My question : How does the program know if the button is pushed, and how can I use that in code? (I know the button must have a value like null/int depending on its state, but how do I check this variable, and use it in code?
I'm assuming it's something like - Example :
1 2 3 4
if (somefunctiontogetbuttonvalue(1001)==1){
//Then run this code
}
Buttons have a position. A cursor has a position. When mouse button 1 is pressed, check position of mouse to see if it is on this button. If so, your button is pressed.
The WM_LBUTTONDOWN message is sent to the button window. It then sends its parent a WM_COMMAND message.
So your main window's WndProc needs to handle WM_COMMAND looking for an ID value of BUTTON_ID (the ID is the low word of wParam, the high word the notifcation code, which will be BN_CLICK.) As follows:
(Here the IDs are for menu items. All basic controls (like Button, ComboBox, and ListBox), menu items, and accelerators are handled via the WM_COMMAND message. The only difference being that neither menu items nor accelerators use notification codes. But the newer controls in COMCTL32.DLL (like the List View, Rebar, and Tab) use a different message: WM_NOTIFY.)
Where
int wmId, wmEvent;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
The WM_LBUTTONDOWN message is sent to the button windows. It will then send its parent a WM_COMMAND message.
This I understand.
So you main window's WndProc needs to handle WM_COMMAND
You mean make a case WM_COMMAND: {}?
looking for an ID value of BUTTON_ID
Kinda lost here. By looking for ID value of BUTTON_ID, wouldn't that be 1001 as stated in #define BUTTON_ID 1001 on line 6?
the high word the notifcation code, which will be BN_CLICK
And totally lost here.
I'm confused, when I look up BN_CLICK, it seems to me that the l/w params alone are enough to tell if I clicked inside the "button window" that I created. So is WM_LBUTTONDOWN really necessary?
While searching for in formation on a different matter. I bumped into this article from Raymond Chen's log "The Old New Thing" (a very worthwhile read if you're a Windows programmer!)