I have a window with 2 child buttons on it and I was originally trying to make their text change color when I hover over and out but when I put the MessageBox () in the WM_MOUSEMOVE message I found out that I stop getting message boxes when my cursor is on either of the buttons. MSDN says that WM_MOUSEMOVE is sent to the window that contains the cursor, so.. I must be doing something wrong.
HWND hparent;
HWND hplaybtt;
HWND hexitbtt;
HINSTANCE hinstance;
LRESULT CALLBACK MainProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void MakeWindow () {
WNDCLASSEX wc;
wc.cbSize = sizeof (WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = MainProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hCursor = LoadCursor( NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = L"Window";
wc.hInstance = hinstance;
wc.hIcon = NULL;
wc.hIconSm = NULL;
RegisterClassEx (&wc);
hparent = CreateWindowEx (0, L"Window", L"Slot Machine", WS_OVERLAPPEDWINDOW, 0, 0, 300, 300,
NULL, NULL, hinstance, NULL);
hplaybtt = CreateWindowEx (0, L"Button", L"Play", WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, 110, 125, 80, 50,
hparent, (HMENU) 101, hinstance, NULL);
hexitbtt = CreateWindowEx (0, L"Button", L"Exit", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 110, 175, 80, 50,
hparent, (HMENU) 102, hinstance, NULL);
ShowWindow (hparent, SW_SHOW);
}
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
hinstance = hInstance;
MSG Msg;
MakeWindow ();
while (GetMessage (&Msg, NULL, 0, 0)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK MainProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
COLORREF cr = RGB (255, 0, 0);
COLORREF white = RGB (255, 255, 255);
HDC hdc;
LPDRAWITEMSTRUCT dis;
switch(Msg) {
case WM_DRAWITEM:
dis = (LPDRAWITEMSTRUCT) lParam;
FillRect (dis->hDC, &dis->rcItem, (HBRUSH) GetStockObject (BLACK_BRUSH));
SetBkMode (dis->hDC, TRANSPARENT);
SetTextColor (dis->hDC, white);
TextOut (dis->hDC, 25, 15, L"Play", 4);
MessageBox (hWnd, L"hi", NULL, MB_OK);
break;
case WM_PAINT:
hdc = BeginPaint (hparent, &ps);
SetTextColor (hdc, cr);
TextOut (hdc, 105, 50, L"Slot Machine", 12);
EndPaint (hparent, &ps);
break;
case WM_MOUSEMOVE:
POINT p;
p.x = LOWORD (lParam);
p.y = HIWORD (lParam);
MessageBox (hWnd, L"This is the slot machine game.", L"About", MB_OK);
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}