Hi, below is source code that simply creates and displays a window. The problem is that right after it displys it destroys its self. Tat is wrong, wrong, wrong. I don't want it destroy it self, but I cannot figure out why it is doing so. Suggestions?
--------------------------------------------
//includes and defines
#define WIN32_LEAN_AND_MEAN
#include
#include
HWND main_window_handle = NULL;
//windproc function
LRESULT CALLBACK WindowProc(HWND hwnd, //the window
UINT msg, //the message itself
WPARAM wParam,
LPARAM lParam)
{
//this function handles all the messages sent to window
HDC hdc; //device context used for graphics
PAINTSTRUCT ps; //also used for graphics
//find out what message was sent
switch(msg)
{
case WM_CREATE:
{
return 0;
}break;
case WM_PAINT:
{
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
return 0;
}break;
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}break;
default:break;
}
return (DefWindowProc(hwnd, msg, wParam, lParam));
}
//winmain entry point
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpCmdLine,
int nShowCmd)
{
//declaration of window class
WNDCLASS wndclass;
HWND hwnd;
MSG msg;
wndclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WindowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hinstance; //from winmain
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "WINCLASS1";
//register wndclass
if (RegisterClass(&wndclass)==0)
{
//error
}
//create windows
hwnd = CreateWindow("WINCLASS1",
"Blind Try",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0,0,
320, 200,
NULL,
NULL,
hinstance,
NULL);
return 0;
//holdsthe message
main_window_handle = hwnd;
//loop unitl there is a WM_QUIT
while(1)
{
//is there a message
if (PeekMessage(&msg, NULL, 0, 0 , PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
//translate message
TranslateMessage(&msg);
//sends message to Window proc
DispatchMessage(&msg);
}
}
return (msg.wParam);
}
-------------------------------