🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

windows help

Started by
2 comments, last by lucinpub 22 years, 5 months ago
Sorry to post what is probably an often asked question, but windows code is killing me... and I never got answer to my previous post. I have followed the examples from Game Programming genesis and COTC to try to open a window. The process starts and the window shows up in the task bar, but the window has only opened once (the first time I ran it ). here is my code.... please help


#include "game.h"
#include <windows.h>
#include <windowsx.h>
#include <iostream>

using namespace std;

#define WIN32_LEAN_AND_MEAN

// Function prototypes
 int init( HINSTANCE, HWND );
LRESULT CALLBACK MsgHandler( HWND hwnd, UINT msg, WPARAM wpar, LPARAM lpar );

// data
bool game_over = false;
Board brd;
HWND sysw_hwnd;
HINSTANCE sysw_hInst;

int WINAPI WinMain( HINSTANCE hinst, HINSTANCE xxx, LPSTR cmndln, int nCmnd ){

	sysw_hInst = hinst;
	init(sysw_hInst, sysw_hwnd);
	MSG msg;



	if( !( sysw_hwnd = CreateWindowEx( WS_EX_APPWINDOW, "XL_Chess", "XL_CHESS", 
		WS_VISIBLE | WS_OVERLAPPEDWINDOW | WS_MAXIMIZE,
		0, 0, 640, 480, NULL, NULL, hinst, NULL ))){
	//-------------- end arg list
		return( false );
	}

	ShowWindow( sysw_hwnd, nCmnd );
	UpdateWindow( sysw_hwnd );

	__try{
		while (1){
			if(PeekMessage(&msg,sysw_hwnd, 0, 0, PM_REMOVE)){
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
			// call application main loop function
			if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
			{
				if (msg.message == WM_QUIT) // exit loop on quit
					break;
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
	}
	__except(GetExceptionCode()){ 
		// A Bad Thing happened, try to crash cleanly
		
	}


	return true;
}


int init( HINSTANCE hinst, HWND hwnd ){

	brd = Board();
	WNDCLASSEX app;

	// fill out WNDCLASSEX struct
	app.cbSize        = sizeof( WNDCLASSEX );
	app.style         = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
	app.lpfnWndProc   = MsgHandler;
	app.cbClsExtra    = 0;
	app.cbWndExtra    = 0;
	app.hInstance     = hinst;
	app.hIcon	      = LoadIcon( NULL, IDI_WINLOGO );
	app.hCursor		  = LoadCursor( NULL, IDC_ARROW );
	app.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
	app.lpszMenuName  = NULL;
	app.lpszClassName = "XL_Chess";
	app.hIconSm		  = LoadIcon( NULL, IDI_WINLOGO );

	RegisterClassEx( &app );
	
	return( true );
}

LRESULT CALLBACK MsgHandler( HWND hwnd, UINT msg, WPARAM wpar, LPARAM lpar ){

	switch( msg ){
		case( WM_CREATE ):
			cout << "game up!!" << endl;
			return( true );
		case( WM_CLOSE ):
		case( WM_DESTROY ):
		case( WM_QUIT ):
			exit( true );
			break;
		default:
			cout << msg << endl;
			return( true );
	}
}
 
Lucas Henekswww.ionforge.com
Advertisement
Instead of

exit( true );

use

PostQuitMessage(0);
thanks for the attempt...but still has the same problem. It''s like windows invalidates the area my window will be at, and transfers control to it, but it never opens and as you can see I call show window. I have been struggling with this little hangup for almost a week now...
Lucas Henekswww.ionforge.com
guess what... I finally got it! all I had to do was get rid of the default case in the switch and add a call to the windows default msg handler and BAM! up comes the window. Thank you toanyone who helped on this or the last post and to anyone who was working on it.
I knew it was simple!!!
Lucas Henekswww.ionforge.com

This topic is closed to new replies.

Advertisement