Win32 Button Control
Creating a button control in a Win32 window (hWnd).
Define a unique ID for the button control:
#define BTN_MYBUTTON_ID 503
Create the control after the main Win32 window has been created:
// Create button control. CreateWindowEx(NULL, L"BUTTON", L"Click Me", WS_VISIBLE | WS_CHILD, 35, 35, 120, 20, hWnd, (HMENU)BTN_KEYGUARD_ID, NULL, NULL);
Listen for activity in your message handler (WndProc):
switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); switch (wmId) { case BTN_MYBUTTON_ID: // Your code here. MessageBox(hWnd, L"I was clicked!", L"Info", MB_OK); break;
Setting and getting text from your button control:
SetDlgItemText(hWnd, BTN_MYBUTTON_ID, "Foo!"); GetDlgItemText(hWnd, BTN_MYBUTTON_ID, szBuf, sizeof(szBuf));