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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
// A complete windows program.
/***INCLUDES***/
#define WIN32_MEAN_AND_LEAN
#include <Windows.h>
#include <windowsX.h>
#include <stdio.h>
#include <math.h>
#include <tchar.h>
/***DEFINES***/
#define WINDOW_CLASS_NAME "WINCLASS1"
/***GLOBALS***/
/***FUNCTIONS***/
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam)
{
// This is the main message handler of the system
PAINTSTRUCT ps; // used in WM_PAINT
HDC hdc; // handle to a device context
switch( msg )
{
case WM_CREATE:
// do initialization stuff here
// return success
return(0);
break;
case WM_PAINT:
// simply validate the window
hdc = BeginPaint(hWnd, &ps);
// You would do all your painting here
EndPaint(hWnd, &ps);
//return success
return(0);
break;
case WM_DESTROY:
// Kill the application, this sends a WM_QUIT message
PostQuitMessage(0);
//return success
return(0);
break;
default:
break;
} // end switch
// Process any messages that we didn't take care of
return (DefWindowProc(hWnd,msg,wParam,lParam));
} // end WndProc
/***WINMAIN***/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX winClass; // This will hold the class we create
HWND hWnd; // Generic window handle
MSG msg; // generic message
// 1. Fill out Window Class Structure
winClass.cbSize = sizeof(WNDCLASSEX);
winClass.style = CS_HREDRAW | CS_VREDRAW;
winClass.lpfnWndProc = WndProc;
winClass.cbWndExtra = 0;
winClass.cbClsExtra = 0;
winClass.hInstance = hInstance;
winClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winClass.lpszClassName = _T(WINDOW_CLASS_NAME);
winClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
// 2. Register the window class
if(!RegisterClassEx(&winClass))
return(0);
// 3. Create the window
if(!(hWnd = CreateWindowExA(NULL, WINDOW_CLASS_NAME,
"WINDOW 2",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0, 0, 400, 400, NULL, NULL,
hInstance, NULL)))
return(0);
if(!(hWnd = CreateWindowExA(NULL, WINDOW_CLASS_NAME,
"WINDOW 1",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
400, 400, 400, 400, NULL, NULL,
hInstance, NULL)))
return(0);
// Enter main event loop
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} // end while
return(msg.wParam);
}// end WinMain
|