-
April 4th, 2008, 09:53 AM
#1
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);
}
}
-
April 4th, 2008, 11:06 AM
#2
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.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
April 4th, 2008, 12:45 PM
#3
Re: Strange - ON_BN_CLICKED Event gets caught in loop
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".
-
April 4th, 2008, 03:16 PM
#4
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
-
April 4th, 2008, 04:47 PM
#5
Re: Strange - ON_BN_CLICKED Event gets caught in loop
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
-
April 4th, 2008, 08:00 PM
#6
Re: Strange - ON_BN_CLICKED Event gets caught in loop
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|