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
|
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
static bool display_text = true;
switch(message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
if (display_text)
{
RECT rect;
GetClientRect(hwnd, &rect);
DrawTextW(hdc, L"Click Me, Baby!", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
EndPaint(hwnd, &ps);
return S_OK;
case WM_LBUTTONDOWN:
MessageBoxW(hwnd, L"Stop Poking Me!", L"Ouch!", MB_OK);
display_text = false;
InvalidateRect(hwnd, NULL, TRUE); // invalidate the entire client area to erase the text
return S_OK;
case WM_DESTROY:
PostQuitMessage(0);
return S_OK;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
| |