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
|
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int x = 0, y = 0;
static bool bDrawText = false;
switch (message)
{
case WM_LBUTTONDOWN:
bDrawText = true;
x = LOWORD(lParam);
y = HIWORD(lParam);
InvalidateRect(hwnd, NULL, TRUE);
return 0;
// optional, text will vanish on mouse up
case WM_LBUTTONUP:
bDrawText = false;
InvalidateRect(hwnd, NULL, TRUE);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT PAINT;
hdc = BeginPaint(hwnd, &PAINT);
if (bDrawText) // only draw when you want.
{
const char *text = "I clicked!";
TextOut(hdc, x, y, text, strlen(text));
}
EndPaint(hwnd, &PAINT);
return 0;
}
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
|