Code:
// Project1
//
#include <windows.h>
LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInstance;
HWND hWindow;
static HWND Button1;
#define ID_Button1 100
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wc;
MSG msg;
if (!hPrevInst)
{
wc.lpszClassName="Project1Class";
wc.lpfnWndProc=MainWndProc;
wc.style=CS_OWNDC; // | CS_VREDRAW | CS_HREDRAW;
wc.hInstance=hInst;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1);
wc.cbClsExtra=0;
wc.cbWndExtra=0;
RegisterClass(&wc);
}
hWindow=CreateWindow("Project1Class","Application",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,500,350,NULL,NULL,hInst,NULL);
hInstance=hInst;
ShowWindow(hWindow,nCmdShow);
UpdateWindow(hWindow);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam,LPARAM lParam)
{
static RECT rect;
static POINT point;
switch(msg)
{
case WM_MOUSEMOVE:
point.x = LOWORD(lParam);
point.y = HIWORD(lParam);
ClientToScreen(hWnd, &point);
GetWindowRect(Button1, &rect);
if(PtInRect(&rect, point))
{
SetWindowText(hWnd, "over button1");
return 1;
}
SetWindowText(hWnd, "over dialog");
return 1;
case WM_CREATE:
Button1 = CreateWindowEx(0, "Static", "Button1", WS_VISIBLE | WS_CHILD , 81, 250, 105, 26, hWnd, (HMENU) ID_Button1, hInstance, NULL);
SendMessage(Button1, (UINT) WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), (LPARAM) MAKELPARAM(FALSE, 0));
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hWnd, msg, wParam, lParam));
}
return 0;
}