1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <windows.h>
#define MSGEVENT Msg.message
#define BUTTON1 4866
/* Declare Windows procedure */
LRESULT CALLBACK CtAppDefProc (HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain
(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgs, int iWindowState)
{
HWND hWnd; /* This is the handle for our window */
MSG Msg; /* Here messages to the application are saved */
WNDCLASSEX wincex; /* Data structure for the windowclass */
/* The Window structure */
wincex.hInstance = hInstance;
wincex.lpszClassName = "WindowClassEx";
wincex.lpfnWndProc = CtAppDefProc; /* This function is called by windows */
wincex.style = CS_HREDRAW | CS_VREDRAW | CS_NOCLOSE; /* Disables the RED X button! */
wincex.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincex.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincex.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincex.hCursor = LoadCursor (NULL, IDC_ARROW);
wincex.lpszMenuName = NULL; /* No menu */
wincex.cbClsExtra = 0; /* No extra bytes after the window class */
wincex.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincex.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincex))
return 0;
/* The class is registered, let's create the program*/
hWnd = CreateWindowEx (
0, /* Extended possibilites for variation */
wincex.lpszClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW -WS_SIZEBOX, /* Prevent re-sizing of the client window! */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
640, /* The programs width */
480, /* 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 */
);
/* Make the window visible on the screen */
ShowWindow (hWnd,iWindowState);
/* Create a button. */
HWND button1 = CreateWindow("button","Close Me!",WS_CHILD,100,100,100,100,hWnd,(HMENU)BUTTON1,GetModuleHandle(NULL),0);
ShowWindow(button1,SW_SHOW); /* Display button in window. */
bool bQuit = false;
/* Run the message loop. It will run while bQuit is false. */
while (!bQuit)
{
while (PeekMessage (&Msg, NULL, 0, 0,PM_REMOVE))
{
if (MSGEVENT == WM_QUIT) bQuit = true;
/* Translate virtual-key messages into character messages */
TranslateMessage(&Msg);
/* Send message to WindowProcedure */
DispatchMessage(&Msg);
}
}
return 0; /* bye bye. */
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK CtAppDefProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_COMMAND:
if(LOWORD(wParam) == BUTTON1)
PostQuitMessage(0);
case WM_SYSCOMMAND:
if((wParam & 0xFFF0) == SC_CLOSE) PostQuitMessage(0);
default: /* for messages that we don't deal with */
return DefWindowProc (hWnd, message, wParam, lParam);
}
return 0;
}
|