Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Modal MessgeBox Problem

Modal MessgeBox Problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    moobob
    wrote on last edited by
    #1

    I have a problem with my app when displaying a MessageBox to indicate an error. I display the message box in a losingFocus callback, if the value of a dialog field is out of range. Most times the message box behaves correctly. The problem occurs when the user clicks in a window outside the application, the message box gets displayed and keeps reappearing when the OK button is pressed. This will continue for 10-20 times before the dialog will stop appearing. I have tried all three of the modality values (MB_APPLMODAL, MB_SYSTEMMODAL, MB_TASKMODAL) with the same results. Any suggestions as to how I can make the messagebox behave properly when the user clicks outside my application? Thanks in advance, Bob

    M 1 Reply Last reply
    0
    • M moobob

      I have a problem with my app when displaying a MessageBox to indicate an error. I display the message box in a losingFocus callback, if the value of a dialog field is out of range. Most times the message box behaves correctly. The problem occurs when the user clicks in a window outside the application, the message box gets displayed and keeps reappearing when the OK button is pressed. This will continue for 10-20 times before the dialog will stop appearing. I have tried all three of the modality values (MB_APPLMODAL, MB_SYSTEMMODAL, MB_TASKMODAL) with the same results. Any suggestions as to how I can make the messagebox behave properly when the user clicks outside my application? Thanks in advance, Bob

      M Offline
      M Offline
      Mustafa Demirhan
      wrote on last edited by
      #2

      Could you post that part of the code please? Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrix

      They say I'm lazy but it takes all my time

      M 2 Replies Last reply
      0
      • M Mustafa Demirhan

        Could you post that part of the code please? Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrix

        They say I'm lazy but it takes all my time

        M Offline
        M Offline
        moobob
        wrote on last edited by
        #3

        I think I need to determine if the focus is going to a window outside my app. How do I do that? Here is the code.

        void DataImportDlg2::OnKillfocusProtocolNameCb()
        {
        CString protoName;

        // Get the protocol item just typed in.
        m\_protocolNameCB.GetWindowText(protoName);
        
        // If an item was typed in
        // verify this protocol exists.
        if (protoName.GetLength() > 0)
        {
            int index = m\_protocolNameCB.FindStringExact(0, protoName);
        
            if (index == CB\_ERR)
            {
                MessageBox (\_T ("Protocol does not exist, to create it, use the Create Protocol button"),
                            \_T ("Data Import"), 
                            MB\_ICONERROR | MB\_OK | MB\_APPLMODAL | MB\_TOPMOST);
        
                m\_protocolNameCB.SetFocus();
            }
        

        Thanks, Bob

        1 Reply Last reply
        0
        • M Mustafa Demirhan

          Could you post that part of the code please? Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrix

          They say I'm lazy but it takes all my time

          M Offline
          M Offline
          moobob
          wrote on last edited by
          #4

          I am trying to determine if the control that focus is going to next is on my app's window. Here is how I am attempting to do this

          void DataImportDlg2::OnKillfocusProtocolNameCb(CWnd* pNewWnd )
          {
          CString protoName;

          // CWnd *pMainWnd = (CWnd *) AfxGetApp()->m_pMainWnd;
          CWnd *pMainWnd = (CWnd *) AfxGetMainWnd();

          BOOL child = pMainWnd->IsChild(pNewWnd);
          

          When I click on a control on my apps window, the IsChild returns FALSE. I would expect it to return TRUE. What am I doing wrong? Thanks in advance, Bob

          M 1 Reply Last reply
          0
          • M moobob

            I am trying to determine if the control that focus is going to next is on my app's window. Here is how I am attempting to do this

            void DataImportDlg2::OnKillfocusProtocolNameCb(CWnd* pNewWnd )
            {
            CString protoName;

            // CWnd *pMainWnd = (CWnd *) AfxGetApp()->m_pMainWnd;
            CWnd *pMainWnd = (CWnd *) AfxGetMainWnd();

            BOOL child = pMainWnd->IsChild(pNewWnd);
            

            When I click on a control on my apps window, the IsChild returns FALSE. I would expect it to return TRUE. What am I doing wrong? Thanks in advance, Bob

            M Offline
            M Offline
            Mustafa Demirhan
            wrote on last edited by
            #5

            Well, this won't work because the control is the child of your View class; not the CMainFrame class. I have two suggestions: The first one is the easier way: Don't try to validate the data everytime you loose focus. Instead, validate it when the user clicks on OK button. If you want to do it whenever the window looses focus do it this way: Create a bool variable as a member of your view. Lets say m_bChildHasFocus Now, whenever the control gets the focus set the variable to true and whenever it looses set it false. Here is the code:void DataImportDlg2::OnKillfocusProtocolNameCb() { if (!m_bChildHasFocus) return CView::OnKillFocus(); // or whatever! I am not sure. Just exit the function properly!! m_bChildHasFocus = false; CString protoName; // Get the protocol item just typed in. m_protocolNameCB.GetWindowText(protoName); // If an item was typed in // verify this protocol exists. if (protoName.GetLength() > 0) { int index = m_protocolNameCB.FindStringExact(0, protoName); if (index == CB_ERR) { MessageBox (_T ("Protocol does not exist, to create it, use the Create Protocol button"), _T ("Data Import"), MB_ICONERROR | MB_OK | MB_APPLMODAL | MB_TOPMOST); m_protocolNameCB.SetFocus(); m_bChildHasFocus = true; }
            Also, don't forget to add the OnGetFocus function. In OnGetFocus functions, just set m_bChildHasFocus = true. Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrix

            They say I'm lazy but it takes all my time

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups