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
|
HDC hdc; // Handle to a device context, for drawing
PAINTSTRUCT ps; // Extra information useful when painting
RECT Window;
RECT ClickMeBox;
RECT ExitBox;
COLORREF BoxBorder = RGB(255,255,255);
HBRUSH BoxBorderBrush = CreateSolidBrush(BoxBorder);
COLORREF BoxInternal = RGB(0,0,0);
HBRUSH BoxInternalBrush = CreateSolidBrush(BoxInternal);
int PaintInitialiser=1;
switch (message) /* handle the messages */
{
//-------------------------------------------
case WM_CREATE:
// Once only initialisation
return 0;
//-------------------------------------------
case WM_PAINT:
GetClientRect(hwnd, &Window);
hdc = BeginPaint( hwnd, &ps );
if (PaintInitialiser == 1)
{
ClickMeBox.left = (Window.right/2) - 75;
ClickMeBox.right = (Window.right/2) + 75;
ClickMeBox.top = (Window.bottom/2) - 75;
ClickMeBox.bottom = (Window.bottom/2) + 75;
PaintInitialiser = 0;
}
ExitBox.right = Window.right;
ExitBox.top = Window.top;
ExitBox.left = ExitBox.right - 50;
ExitBox.bottom = ExitBox.top + 50;
Rectangle(hdc, ExitBox.left, ExitBox.top, ExitBox.right, ExitBox.bottom);
Rectangle(hdc, ClickMeBox.left, ClickMeBox.top, ClickMeBox.right, ClickMeBox.bottom);
char ClickMe[] = "Click Me!";
DrawText(hdc, ClickMe, strlen(ClickMe), &ClickMeBox, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
char Exit[] = "Exit";
DrawText(hdc, Exit, strlen(Exit), &ExitBox, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint( hwnd, &ps );
return 0;
case WM_KEYDOWN:
switch(wParam)
{
case VK_UP:
{
ClickMeBox.top -= 10;
ClickMeBox.bottom -= 10;
break;
}
case VK_DOWN:
{
ClickMeBox.top += 10;
ClickMeBox.bottom += 10;
break;
}
case VK_LEFT:
{
ClickMeBox.left -= 10;
ClickMeBox.right -= 10;
break;
}
case VK_RIGHT:
{
ClickMeBox.left += 10;
ClickMeBox.right += 10;
break;
}
}
InvalidateRect(hwnd, NULL, TRUE);
return 0;
|