I'm working on an app that tests for some stuff on startup and depending on those tests one of seven radio buttons gets checked. Then when you press a certain button the tests get run again and the same thing happens.

The problem is that when a different radio button gets checked, the previous radio button doesn't get unchecked. Right now I'm using a SendMessage call with bm_setcheck to check the buttons. Maybe there's another function that does what I want (i.e. only have one button checked at a time)?

I don't want to resort to having another proc that cycles through the radio buttons and unchecks them before each bm_setcheck message gets sent.

Or, I could just have a dummy variable and mov the radio button's handle into it as it gets checked. Then I could just send a bm_uncheck message to it before the bm_setcheck? That'd just be a couple extra lines of code. Is there a cleaner/better way to do this?
Posted on 2002-03-02 16:55:50 by Will
Btw, that works fine. It seems like there would be a better way to do it though.

Now, it looks something like this:

invoke SendMessage,hChecked,BM_SETCHECK,BST_UNCHECKED,0
mov eax,hRadio1
mov hChecked,eax
invoke SendMessage,hRadio1,BM_SETCHECK,BST_CHECKED,0

So the the last radio button to be checked is unchecked and then the one that's about to be checked gets its handle stored in hChecked. Does anyone know of a better way to handle this?
Posted on 2002-03-02 17:24:48 by Will
i think using a group box will solve this. do you not want to use a group box? i dont see how this can be done without programically checking each of the other radio button for being checked too.
Posted on 2002-03-02 17:54:17 by smurf
Oh..... I didn't know what you meant at first.

The radio buttons are in a groupbox. I'm not talking about the buttons being unchecked when I check another button. I'm talking about when I programatically (sp?) check another button.

I don't see the need for checking all the other buttons for being checked. What the program does is on my win2k box I do a lot of php/mysql work and I wanted to do some services related progamming. This program checks the status of the mysql service on startup, and also gives you the option of checking the status by pushing the "refresh" button. There are 7 radio buttons, 1 for each of the 7 different service status'. The appropriate button is programmatically checked if that is the actual status of the mysql service. So in a big if/else statement, the appropriate button gets checked. But before it gets checked, the last button to be checked gets unchecked and the button about to be checked has its handle saved.

I just thought that maybe there was a different way to accomplish the same thing. -shrugs- This works fine though.
Posted on 2002-03-02 23:03:16 by Will
Instead of checking and unchecking inside the decision making portion of your code, you could use a local variable to determine
which button should be checked after all the options have been tested. This approach would certainly run more efficiently since it would involve only one api call. Of course, you'd have to uncheck all the boxes before hand.
In fact, if you use a separate procedure to perform the test then return the button to be check, you might be able to reuse the code that actually calls SendMessage with a different group of radio buttons if you find it neccessary.
Posted on 2002-03-02 23:43:41 by Canite
aaahhh.....

Good idea. Thanks. I knew someone would come up with something better. ;)
Posted on 2002-03-03 09:58:37 by Will
If you want to have exactly one button out of several checked (mutually exclusive buttons), you can also use CheckRadioButton.
invoke CheckRadioButton, hWnd, FirstButtonID, LastButtonID, ChosenButtonID

Number the buttons consecutively from FirstButtonID to LastButtonID.
Posted on 2002-03-03 19:35:15 by tenkey
This forum kicks ass!

That's exactly what I was looking for. Thanks a bunch tenkey.

You'd think that would be listed in the api help file along with the other button messages or at least listed in the "see also" section under BM_SETCHECK. Hell, BM_SETCHECK is listed in the "see also" section under CheckRadioButton. That's odd that those two aren't cross-referenced.
Posted on 2002-03-04 10:40:22 by Will