Original Post
I''m trying to create a program that simpily creates a window with a black background.
However when the porgram''s window closes the program doesn''t quit. And, yes, I do know that simpily closing the window does NOT end the program.
Sorry to have to do such a massive code dump, but i really can''t understand what''s going on here. All i know is that the window closes and the WM_DESTROY message is sent to WndProc, however something seems to be screwy with the PostQuitMessage(). I''m dumping the entire code inncase something in there is screwing it up.
and by the way, yes I AM using Borland C++Builder 5, and NO I WILL NOT get MSVC++
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To all of those who think I''m just being contradictory:
No I''m not!
//---------------------------------------------------------------------------
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#pragma hdrstop
//---------------------------------------------------------------------------
////////// declarations
//---------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
// create variables, static so that it doesn''t have to keep getting created
static PAINTSTRUCT ps;
static HDC hDC;
// find out what message is
switch(Message)
{
case WM_CREATE: // window created
{
// one time initalization
return 0;
break;
}
case WM_PAINT: // window needs redrawn.
{
hDC = BeginPaint( hWnd, &ps);
// do any drawing with gdi
EndPaint(hWnd, &ps);
return 0;
break;
}
case WM_DESTROY:// window closed
{
// main quindow is closing,
// app needs to exit
// tell winodws to put a quit
// message in the message que
PostQuitMessage(0);
return 0;
break;
}
}
// let window handle message
return DefWindowProc(hWnd, Message, wParam, lParam);
}
//---------------------------------------------------------------------------
#pragma argsused
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hWnd; // window handle
MSG msg; // message
WNDCLASSEX wc; // holds the window properties
// create a name for the window and window caption
const char* AppName= "Temp Anchor";
// fill in the window class structure
// size of class in bytes
wc.cbSize = sizeof(wc);
// style of window
wc.style = (CS_HREDRAW | CS_VREDRAW | CS_OWNDC);
// stupid stuff we don''t need
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
// name of our event handler
wc.lpfnWndProc = WndProc;
// handle to app''s instance
wc.hInstance = hInstance;
// handle to brush to use for the window background
wc.hbrBackground= (HBRUSH)GetStockObject(BLACK_BRUSH);
// a handle to the icon to use for the window
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
// a handle to a smaller version of the app''s icon
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
// handle to the cursor to use for the mouse pointer
wc.hCursor = LoadIcon(NULL, IDC_CROSS);
// menu resource
wc.lpszMenuName = NULL;
// last but not least the name of the class
wc.lpszClassName= AppName;
// register the window
RegisterClassEx(&wc);
// create window.
hWnd = CreateWindowEx( NULL, // Extended window style
AppName, // class name
AppName, // winodw name
WS_OVERLAPPEDWINDOW, // window stlye
0, 0, // x,y
300, 300, // width, height
NULL, // parent handle
NULL, // handle to child
hInstance, // app instance
NULL); // window creation data
// show for first time
ShowWindow(hWnd, nCmdShow);
// update it to make sure everything is in order.
UpdateWindow(hWnd);
while(1) // do forever
{
if( PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE) ) // get message
{
if(msg.message == WM_QUIT) //if it''s time to quit...
break; // quit
// In case of weird messages
TranslateMessage(&msg);
// send to WndProc
DispatchMessage(&msg);
}
else // if no message, continue game
{
// game code here.
}
}
return msg.wParam;
}
//---------------------------------------------------------------------------
|