Archived

This topic is now archived and is closed to further replies.

JIMbond21

Windows buttons???

Recommended Posts

When I use the createwindow function with the button class I get a button with my desired text on it, what I want to know is if I make two or three buttons how do I determine if and what button was pressed? Thx in advance!

Share this post


Link to post
Share on other sites
Read up on buttons right here.

First I assume you have unique IDs for your buttons. When you get your WM_COMMAND message, just have a switch statement like this:


//...
case WM_COMMAND:
switch(LOWORD(wparam))
{
case BUTTON_ID_ONE:
//The message from the button with the ID
//BUTTON_ID_ONE.
//...Do some stuff.
break;
case BUTTON_ID_TWO:
//This is your second button.
break;
}
return 0;


It''s been a little while since I''ve worked much with win32 so forgive any errors.


Share this post


Link to post
Share on other sites
Either the LPARAM or WPARAM (I can''t remember which, look it up in the MSDN) contains the handle to the button. Just compare this with the handle of each of your buttons and if it is the same then that is the button that was pressed.

Share this post


Link to post
Share on other sites
quote:
Original post by Raloth
Either the LPARAM or WPARAM (I can''t remember which, look it up in the MSDN) contains the handle to the button. Just compare this with the handle of each of your buttons and if it is the same then that is the button that was pressed.


That''s another method. And it''s the lparam.

Share this post


Link to post
Share on other sites
quote:
Original post by JIMbond21
I know how to figure out the button checking part when i have IDs for them, I don''t know how to make an ID for them to check against.


Oh, I see.

The third to last varialbe in CreateWindow doubles as the ID when creating child windows.

eg.
Orginally from Platfor SDK (and slightly modified be me)

#define ID_BUTTONONE 1

hwndButton = CreateWindow(
"BUTTON", // predefined class
"OK", // button text
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles

// Size and position values are given explicitly, because
// the CW_USEDEFAULT constant gives zero values for buttons.
10, // starting x position
10, // starting y position
100, // button width
100, // button height
hwnd, // parent window
ID_BUTTONONE, // This is normally your menu, but for
//child windows it is the ID.
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
NULL); // pointer not needed



That should answer your question.

Share this post


Link to post
Share on other sites