CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2002
    Location
    CenTex
    Posts
    32

    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);
    }
    }

  2. #2
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    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

  3. #3
    Join Date
    Nov 2002
    Location
    CenTex
    Posts
    32

    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".

  4. #4
    Join Date
    Feb 2002
    Posts
    4,640

    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

  5. #5
    Join Date
    Jul 2007
    Posts
    52

    Red face 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

  6. #6
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Strange - ON_BN_CLICKED Event gets caught in loop

    [ code ] tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured