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
|
#include <windows.h>
#include <tchar.h>
enum { WM_INIT = WM_USER+1, ID_BTN };
INT_PTR CALLBACK DialogProc(HWND hDialog, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INIT:
CreateWindow(_T("button"), _T("test"), WS_CHILD | WS_VISIBLE,
20, 20, 80, 40, hDialog, (HMENU)ID_BTN, (HINSTANCE)lParam, NULL);
return TRUE;
case WM_SETCURSOR:
if (LOWORD(lParam) == HTCLIENT && GetDlgCtrlID((HWND)wParam) == ID_BTN)
{
SetCursor(LoadCursor(NULL, IDC_HAND));
SetWindowLongPtr(hDialog, DWLP_MSGRESULT, TRUE);
return TRUE;
}
return FALSE;
case WM_CLOSE:
DestroyWindow(hDialog);
return TRUE;
case WM_DESTROY:
PostQuitMessage(0);
return TRUE;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd)
{
HWND hDialog = CreateWindow(WC_DIALOG, _T("Win32 testing"), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
200, 200, 500, 400, NULL, NULL, hInst, NULL);
SetWindowLongPtr(hDialog, DWLP_DLGPROC, (LONG_PTR)DialogProc);
SendMessage(hDialog, WM_INIT, 0, (LPARAM)hInst);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
if (!IsDialogMessage(hDialog, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
|