/* 2010-03-06 john pfeiffer windows (from win ce version) quit button
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/* define a special numeric ID for our buttons */
#define IDC_ExitButton 40099
#define IDC_clearScreen 40098
/* HDC = handle to device context - a logical buffer of the screen.
You "write" things to it and then it can write to the display in a chunk.
A paint structure contains the info about the area being painted.
Direct from MSDN...
typedef struct tagPAINTSTRUCT {
HDC hdc;
BOOL fErase;
RECT rcPaint;
BOOL fRestore;
BOOL fIncUpdate;
BYTE rgbReserved[32];
} PAINTSTRUCT, *PPAINTSTRUCT;
*/
VOID APIENTRY initializeBackground( HWND hwnd )
{ HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd, &ps); /* prepares the window for painting */
EndPaint(hwnd, &ps); /* done painting */
}
/* This is the prototype to the "do everything" window message
processing switch function */
LRESULT CALLBACK MenuWndProc(
HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
int APIENTRY WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int ncmdshow )
{
HWND hwnd = NULL;
HWND ExitButton = NULL; /* each button gets a window handle */
HWND clearScreenButton = NULL;
MSG msg;
WNDCLASS wc;
RECT rc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)MenuWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = 0;
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = (LPTSTR) "AppClass";
if(! RegisterClass (&wc))
{ MessageBox(NULL, TEXT("errors "),
"IMPORTANT", MB_OK);
return 0;
}
/* create our main window letting windows decide the placement & size
NOTE! THE CLASS NAME MUST BE A LONG! - could use TCHAR?*/
hwnd = CreateWindow ( "AppClass",
"quit button app", WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
(HWND)NULL, NULL, hInstance, (LPSTR)NULL);
/* ----------- ----------- ----------- ----------- */
/* here we get the coordinate dimensions of the main window */
GetWindowRect(hwnd, &rc);
/* this makes a quit button at the bottom of the screen */
ExitButton = CreateWindow(
"BUTTON", "Quit", WS_CHILD |
WS_VISIBLE | BS_PUSHBUTTON,
0, 0, /* button top left corner x,y */
50 , 50 , /* width & height */
hwnd, (HMENU)IDC_ExitButton,
hInstance, NULL);
clearScreenButton = CreateWindow(
"BUTTON", "Clear", WS_CHILD |
WS_VISIBLE | BS_PUSHBUTTON,
0, 50, /* button top left corner x,y */
50, 50 , /* width & height */
hwnd, (HMENU) IDC_clearScreen,
hInstance, NULL);
ShowWindow(hwnd, ncmdshow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
} /* end WinMain */
/* ----------- ----------- ----------- ----------- */
LRESULT CALLBACK MenuWndProc(
HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
/* here we test for what events happened/the user might have done */
switch (message)
{
case WM_CREATE:
initializeBackground( hwnd ); /* draw the main window */
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN: /* left button pressed / tap on screen */
break;
case WM_MOUSEMOVE: /* mouse pointer is moving */
/* if(wParam & MK_LBUTTON)*/
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_ExitButton: /* quit button pressed */
PostQuitMessage(0);
break;
case IDC_clearScreen: /* clear button pressed */
InvalidateRect( hwnd, NULL, TRUE);
break; /* wipe the main window */
default:
break;
}/* end case command */
break;
case WM_PAINT:
initializeBackground( hwnd );
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
break;
}/* end case message */
return 0;
}