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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
#define WIN32_LEAN_AND_MEAN
// stops windows.h dragging is loads of unwanted stuff
#include <windows.h>
#include "resource.h"
const WCHAR achTitle [] = L"Example #1";
const WCHAR achWindowClass[] = L"ExampleNumberOne";
int r = 0;
int g = 0;
int b = 0;
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
{
MyRegisterClass(hInstance);
if(!InitInstance(hInstance, nCmdShow))
{
return FALSE;
}
MSG msg = {0};
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
{
bool inval = false;
switch(LOWORD(wParam))
{
case ID_Exit:
{
DestroyWindow(hWnd);
}
break;
case ID_Red:
{
r = 250;
g = 0;
b = 0;
inval = true;
} break;
case ID_Green:
{
r = 0;
g = 250;
b = 0;
inval = true;
} break;
case ID_Blue:
{
r = 0;
g = 0;
b = 250;
inval = true;
} break;
}
if(inval)
InvalidateRect(hWnd, NULL, TRUE);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
TextOut(hdc,10,10,L"Hello World",11);
HBRUSH blueBrush=CreateSolidBrush(RGB(r,g,b));
RECT rct;
rct.left=30;
rct.right=60;
rct.top=30;
rct.bottom=60;
FillRect(hdc, &rct, blueBrush);
DeleteObject(blueBrush); // delete brush!
EndPaint(hWnd, &ps);
}
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
ATOM
MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex = {0};
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProcedure;
wcex.hInstance = hInstance;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszClassName = achWindowClass;
wcex.lpszMenuName = MAKEINTRESOURCE(ID_Menu);
return RegisterClassEx(&wcex);
}
BOOL
InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd = CreateWindow(achWindowClass,
achTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL,
NULL,
hInstance,
NULL);
if(NULL == hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
|