Skip to main content
gamedev.net
🔒 Locked

Windows Programming Problem

Started by Regano Feb 1, 2006 at 9:35 AM 0 replies 300+ views
Original Post
Regano
Regano
Every time I run the following code the window pops up but then instantly dissapears and I can't seem to find out why. Any ideas?


#include <windows.h>


/* Declare windows message handler proc */
LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE pInstance, LPSTR lpCmdLine, int cmdShow){
	
	LPCSTR g_szWindowClassName = "My Game";

	//our window class structure
	WNDCLASSEX winclass;

	// first fill in the window class structure
	winclass.cbSize = sizeof( WNDCLASSEX);
	winclass.style = CS_HREDRAW | CS_VREDRAW;
	winclass.lpfnWndProc = WinProc;
	winclass.cbClsExtra = 0;
	winclass.cbWndExtra = 0;
	winclass.hInstance = hInstance;
	winclass.hIcon = LoadIcon( NULL, IDI_APPLICATION);
	winclass.hCursor = LoadCursor( NULL, IDC_ARROW);
	winclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
	winclass.lpszMenuName = NULL;
	winclass.lpszClassName = g_szWindowClassName;
	winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

	// Register the class
	if( !RegisterClassEx(&winclass))
	{
		MessageBox(NULL, "Class reistration failed!", "Error", 0);
		return 0; // exit the app
	}

	HWND hwnd;               /* This is the handle for our window */

	/* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           g_szWindowClassName, /* Classname */
           "Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           800,                 /* The programs width */
           600,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hInstance,			/* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

	ShowWindow(hwnd, cmdShow);

	// Message pump
	MSG msg;

	// Entry point
	while( GetMessage(&msg, NULL, 0, 0) )
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}


	UnregisterClass(g_szWindowClassName, hInstance);
	
	return 0;
}

// Message Handler
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg) {
		case WM_CREATE:

			//PlaySound("window_open.wav", NULL, SND_FILENAME | SND_ASYNC);
			return 0;

		case WM_PAINT:

			PAINTSTRUCT ps;
			BeginPaint(hwnd, &ps);

			// Draw to the screen here //

			EndPaint(hwnd, &ps);

		case WM_DESTROY:
			PostQuitMessage(0);
			return 0;
	}

	return DefWindowProc(hwnd, msg, wParam, lParam);

}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.