Strange - ON_BN_CLICKED Event gets caught in loop
I added some WinPcap initialization code to a radio-button's OnClick event. Part of my WinPcap initialization process is to display a dialog box with a list of availble network adapters for the user to select from. The ListBox, adapter selection, and OK button all work as intended. However if the user clicks CANCEL and then trys to exit the application the radio-button's OnClick event goes into a loop.....and this happens before the apps destructor even gets called. Anyone care to take a look at my code and see what maybe causing this loop?
Thanks!
Code:
void CAutoSendDlg::OnPcapRadio()
{
if(SelectAdapter()){ // Adapter selection & initalization
// Close SocketManager before opening pcap
if (g_SocketMgrLoaded){
CAutoSendDlg::CloseSocketManager();
g_SocketMgrLoaded = FALSE;
}
g_PcapLoaded = TRUE;
m_ProtoTypeCombo.EnableWindow(TRUE);
m_MsgTypeCombo.EnableWindow(FALSE);
m_PacketSummary = m_TxMsg.InfoSummary();
}
else{
// Set radio button back to original selection
CheckRadioButton(IDC_WINSOCK_RADIO,IDC_PCAP_RADIO,IDC_WINSOCK_RADIO);
}
}
Re: Strange - ON_BN_CLICKED Event gets caught in loop
This code
Code:
CheckRadioButton(IDC_WINSOCK_RADIO,IDC_PCAP_RADIO,IDC_WINSOCK_RADIO);
looks suspicious.
According to MSDN, the arguments to CheckRadioButton are
Code:
FirstButtonInGroup, LastButtonInGroup, ButtonToBeChecked
Since your first and last buttons are the same, I don's see how IDC_PCAP_RADIO can be in the group.
Hope that helps.
Re: Strange - ON_BN_CLICKED Event gets caught in loop
Quote:
Originally Posted by krmed
According to MSDN, the arguments to CheckRadioButton are
Code:
FirstButtonInGroup, LastButtonInGroup, ButtonToBeChecked
Since your first and last buttons are the same, I don's see how IDC_PCAP_RADIO can be in the group.
Huhhh? The radio button group consists of two radio buttons: "IDC_WINSOCK_RADIO", "IDC_PCAP_RADIO". Therefore the 1st button in the group is "IDC_WINSOCK_RADIO" and the last button in the group is "IDC_PCAP_RADIO". The button i want checked is "IDC_WINSOCK_RADIO".
Re: Strange - ON_BN_CLICKED Event gets caught in loop
Are the numeric ID's (in the resource file) of your buttons consecutive? I thought that grouped buttons needed to have consecutive ID's. I could be wrong, though.
Viggy
Re: Strange - ON_BN_CLICKED Event gets caught in loop
Quote:
Originally Posted by 97C5ENVY
if the user clicks CANCEL and then trys to exit the application the radio-button's OnClick event goes into a loop
You dismiss the modal dialog and the execution continues.. right..
but CheckRadioButton sends a BM_SETCHECK for the item you want to be checked, right?
So every time you call it you are implicitly calling your "OnRadioButtonClick" again, that causes the loop.
You may resolve the issue with one check for a boolean var :
void CAutoSendDlg::OnPcapRadio()
{
if(m_refresh)
{
refresh = FALSE;
return;
}
if(SelectAdapter()){ // Adapter selection & initalization
// Close SocketManager before opening pcap
if (g_SocketMgrLoaded){
CAutoSendDlg::CloseSocketManager();
g_SocketMgrLoaded = FALSE;
}
g_PcapLoaded = TRUE;
m_ProtoTypeCombo.EnableWindow(TRUE);
m_MsgTypeCombo.EnableWindow(FALSE);
m_PacketSummary = m_TxMsg.InfoSummary();
}
else{
// Set radio button back to original selection
m_refresh = TRUE;
CheckRadioButton(IDC_WINSOCK_RADIO,IDC_PCAP_RADIO,IDC_WINSOCK_RADIO);
}
}
Not much professional but.. u.u
Re: Strange - ON_BN_CLICKED Event gets caught in loop