Click to See Complete Forum and Search --> : Why am I getting repeat messages?


Gyannea
October 15th, 2004, 07:51 AM
Why do I get repeat messages to this radio button? What happens in this case is the user clicks on the radio button and the settings are wrong so a message box comes up and informs him of the error and then I make two calls, one to 'uncheck' the button and another to recheck the other button. These calls use the
SendMessage(hwnd, BM_SETCHECK, BST_UNCHECKED, 0); or
SendMessage(hwnd, BM_SETCHECK, BST_CHECKED, 0);
They don't use the BM_CLICK message which is supposed to send a message to the dialog box.

Yet when I run this I get an infinite number of calls to the MessageBox function in
an infinite loop. Why are these calls sending messages to this button? I thought they only effected the button appearance; they didn't go to you message handler.

Code below:

case RADIO_VHF:
if(cycle.cycle != STANDBY || // If engaged in a procedure OR
s->thisradio == VHF) // if already a VHF radio, do nothing
{
break;
}

i = soundcard->GetSamplesPerSecond();

if(i - 1200 * (i / 1200) != 0)
{
MessageBox(hwindow, "Sample rate is not a multiple of the baudrate",
"Error in parameters for VHF", MB_OK);
SendButtonUnchecked(RADIO_VHF); // send button unchecked
SendButtonChecked(RADIO_HF); // Send button checked
break; // Quit since Sample rate is not a multiple of the baud rate
}
..... More code ..... not important



First time I ever used the CODE feature! Hope I did it right.

Why do I get an infinite number of messages to this radio button (only when the sample rate is not a multiple of the baud rate condition happens)?

Thanks,

Brian

Bond
October 15th, 2004, 08:28 AM
I hope I didn't miss anything cause I just briefly looked through your question, but it is not necessary to use SendMessage(...) to check/uncheck your button. It is done automatically. So, when your handler is called, you are in essence checking the button manually which, in turn, calls your handler again, creating an endless loop.

Gyannea
October 15th, 2004, 08:40 AM
The problem is the button is checked because the user has clicked on it.

So what I need to do is uncheck the button after telling the user that the sampling rate has to be changed.

What seems inconsistent is that during the WM_INTIALIZE section of the dialog callback, I set the check state of radio buttons and check boxes using these messages and they DON'T call my callback. Which is what I want, especially on an "uncheck'.

Here the user has clicked on a radio button to make a VHF radio. But the sampling rate is wrong so he needs to change it before he can run a VHF radio. However, the VHF radio button is now checked, so I have to uncheck it.

I can do it by sending a BM_CLICK message to the HF radio button which restores the button field, re-checking the HF button and unchecking the VHF button. But that sends a message to the callback which I don't need and thought I avoided by using the BM_SETCHECK message (handles only graphics and nothing else).

Though not critical here, that option is nice to have so you can minimize overhead. Sometimes, all I need is to check a button without calling all the junk that the button press would normally do.

Does the BM_SETCHECK message send a message back to your callback? I don't think it is supposed to. That's why I am wondering why I am getting the infinite loop.

Brian