windows_programming_notes.nbk: Home | Index | Next Page: Using DDE | Previous Page: Using a tab control in a window
You can create a button on a window like this:
hwndButton1 = CreateWindow( "button", "hit me", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 400, 10, 100, 50, hwnd, 1, hInst, NULL);
The eighth argument to the CreateWindow function is the button's ID.
When the button is clicked, it sends a WM_COMMAND meesage to the parent window with the wParam argument set to the button's ID. This can be caught like this:
long FAR PASCAL WndProc (
...
switch(msg) {
case WM_COMMAND:
switch (wParam) {
case IDM_EXIT:
// stuff
break;
...
case 1:
// do something about the button being clicked
break;
...
default:
// is there a default response for WM_COMMAND messages?
break;
}
break;
}
Also, the lParam argument is the control's handle.
Note that the button reports to it's parent just like a menu item, so the button ID must not be the same as any menu item's ID.
windows_programming_notes.nbk: Home | Index | Next Page: Using DDE | Previous Page: Using a tab control in a window
Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time