This topic is now archived and is closed to further replies.

windows help

This topic is 5817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;


// 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", 
		0, 0, 640, 480, NULL, NULL, hinst, NULL ))){
	//-------------- end arg list
		return( false );

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

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

	return true;

int init( HINSTANCE hinst, HWND hwnd ){

	brd = Board();

	// fill out WNDCLASSEX struct
	app.cbSize        = sizeof( WNDCLASSEX );         = 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 );
			cout << msg << endl;
			return( true );

Share this post

Link to post
Share on other sites
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...

Share this post

Link to post
Share on other sites
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!!!

Share this post

Link to post
Share on other sites