Advertisement

The dreaded WNDCLASSEX

Started by November 06, 2002 09:11 PM
1 comment, last by MattS423 22 years ago
ok, i wrote this basic shell to expand upon, compiled, ran, and it worked. the only preblem was that it wouldn''t leave...the black screen went away, but it was still listed in the task manager...sitll running...and eating my processer alive! i think it has something to do with WNDCLASSEX, but i''m not sure. anyway, here is the source:
  
#include "stdafx.h"


#define WIN32_LEAN_AND_MEAN //No MFC, at all


#define KEYUP(vk_code)		((GetAsyncKeyState(vk_code) & 0x8000) ? 0:1)
#define KEYDOWN(vk_code)	((GetAsyncKeyState(vk_code) & 0x8000) ? 1:0)


#include "windows.h"
#include "windowsx.h"
#include "ddraw.h"  //for futrue expansion


LRESULT CALLBACK WinProc(HWND hWnd, UINT msg,
						 WPARAM wParam, LPARAM lParam);

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	WNDCLASSEX winclass; 
	winclass.cbSize = sizeof(winclass);
	winclass.style = CS_DBLCLKS | CS_OWNDC |
					 CS_HREDRAW | CS_VREDRAW;
	winclass.cbClsExtra = 0;
	winclass.cbWndExtra = 0;
	winclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
	winclass.hCursor = LoadCursor(NULL,IDC_ARROW);
	winclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
	winclass.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
	winclass.lpfnWndProc = WinProc;
	winclass.hInstance = hInstance;
	winclass.lpszMenuName = NULL;
	winclass.lpszClassName = "WindowClass1";

	RegisterClassEx(&winclass);


	HWND hWnd;

	if(!(hWnd = CreateWindowEx(NULL,"WindowClass1","FirstDD",
								WS_POPUP | WS_VISIBLE,0,0,
								GetSystemMetrics(SM_CXSCREEN),
								GetSystemMetrics(SM_CYSCREEN),
								NULL,NULL,hInstance,NULL)))

			return 0; //Return if false


	if(hWnd == NULL)
	{
		return 0;
	}


	//GameInit();


	MSG msg;

	while(TRUE)
	{
		if(PeekMessage(&msg,hWnd,0,0,PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				break; //break if were stopping


			TranslateMessage(&msg);

			DispatchMessage(&msg);

		}//end if


		//ok, with that out of the way, let''s do game stuff...


		//GameMain();


	}


	//GameShutdown()

	

	// TODO: Place code here.


	return 0;
}


LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case WM_KEYDOWN:
		DestroyWindow(hWnd);
		return 0;

	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;

	default:
		break;
	}

	return DefWindowProc(hWnd,msg,wParam,lParam);
}

  
please excuse the notes to myself... thanks alot... MattS423
Programmers of the world, UNTIE!
In your loop change hWnd by NULL like this:

    while(TRUE)	{if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){	if(msg.message == WM_QUIT)				break; //break if were stopping			TranslateMessage(&msg);			DispatchMessage(&msg);		}//end if		//ok, with that out of the way, let's do game stuff...		//GameMain();	}  


[edited by - remi on November 6, 2002 10:27:42 PM]
"...and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces."----------Scott Meyers, "Effective C++"
Advertisement
ok, thanks. It works now.
Programmers of the world, UNTIE!

This topic is closed to new replies.

Advertisement