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. DoModal not returning.

DoModal not returning.

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
7 Posts 5 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
    Mr Simple
    wrote on last edited by
    #1

    Hi, I have created a 'please wait' dialog which is loaded when a user clicks on a button. A new thread is launched to load the button so the main thread can continue what it is doing. The button code; CPleaseWait *dlgWait = new CPleaseWait(this); AfxBeginThread(PleaseWaitThread, dlgWait); Then in the new thread; CPleaseWait dlg = (CPleaseWait*)lpParam; dlg.DoModal(); return 0; It is very simple code, which I have had working before. The problem is that when called, DoModal never returns, so the dialog doesnt get displayed (it doesnt get as far as InitDialog). The main thread continues running however. If I place a 'return;' directly after the AfxBeginThread() then the dialog DOES display. If I place 'while(1) Sleep(100);' (or any other code) after the AfxBeginThread() then it does not return. I have narrowed the problem down to a particular line (510) within 'dlgcore.cpp' // disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent && hWndParent != ::GetDesktopWindow() && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); /////// <--- THIS HANGS FOREVER bEnableParent = TRUE; } Creating a modeless dialog does not fix the problem - Create() does not reurn instead. Does anyone have any ideas as to what the problem could be? Please advise. Thank you!

    R N K D M 5 Replies Last reply
    0
    • M Mr Simple

      Hi, I have created a 'please wait' dialog which is loaded when a user clicks on a button. A new thread is launched to load the button so the main thread can continue what it is doing. The button code; CPleaseWait *dlgWait = new CPleaseWait(this); AfxBeginThread(PleaseWaitThread, dlgWait); Then in the new thread; CPleaseWait dlg = (CPleaseWait*)lpParam; dlg.DoModal(); return 0; It is very simple code, which I have had working before. The problem is that when called, DoModal never returns, so the dialog doesnt get displayed (it doesnt get as far as InitDialog). The main thread continues running however. If I place a 'return;' directly after the AfxBeginThread() then the dialog DOES display. If I place 'while(1) Sleep(100);' (or any other code) after the AfxBeginThread() then it does not return. I have narrowed the problem down to a particular line (510) within 'dlgcore.cpp' // disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent && hWndParent != ::GetDesktopWindow() && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); /////// <--- THIS HANGS FOREVER bEnableParent = TRUE; } Creating a modeless dialog does not fix the problem - Create() does not reurn instead. Does anyone have any ideas as to what the problem could be? Please advise. Thank you!

      R Offline
      R Offline
      Roger Broomfield
      wrote on last edited by
      #2

      You're using a worker thread to create a user interface object? Personally I dont see the need for a thread at all. On Button Click: Disable the main window. Create and show a modeless please wait dialog. Do work. Destroy the modeless please wait dialog. Enable the main window.

      1 Reply Last reply
      0
      • M Mr Simple

        Hi, I have created a 'please wait' dialog which is loaded when a user clicks on a button. A new thread is launched to load the button so the main thread can continue what it is doing. The button code; CPleaseWait *dlgWait = new CPleaseWait(this); AfxBeginThread(PleaseWaitThread, dlgWait); Then in the new thread; CPleaseWait dlg = (CPleaseWait*)lpParam; dlg.DoModal(); return 0; It is very simple code, which I have had working before. The problem is that when called, DoModal never returns, so the dialog doesnt get displayed (it doesnt get as far as InitDialog). The main thread continues running however. If I place a 'return;' directly after the AfxBeginThread() then the dialog DOES display. If I place 'while(1) Sleep(100);' (or any other code) after the AfxBeginThread() then it does not return. I have narrowed the problem down to a particular line (510) within 'dlgcore.cpp' // disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent && hWndParent != ::GetDesktopWindow() && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); /////// <--- THIS HANGS FOREVER bEnableParent = TRUE; } Creating a modeless dialog does not fix the problem - Create() does not reurn instead. Does anyone have any ideas as to what the problem could be? Please advise. Thank you!

        N Offline
        N Offline
        Nelek
        wrote on last edited by
        #3

        I think you are mixing the parent between threads, what about having the new CPleaseWait with (NULL) ??

        Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson ;)

        1 Reply Last reply
        0
        • M Mr Simple

          Hi, I have created a 'please wait' dialog which is loaded when a user clicks on a button. A new thread is launched to load the button so the main thread can continue what it is doing. The button code; CPleaseWait *dlgWait = new CPleaseWait(this); AfxBeginThread(PleaseWaitThread, dlgWait); Then in the new thread; CPleaseWait dlg = (CPleaseWait*)lpParam; dlg.DoModal(); return 0; It is very simple code, which I have had working before. The problem is that when called, DoModal never returns, so the dialog doesnt get displayed (it doesnt get as far as InitDialog). The main thread continues running however. If I place a 'return;' directly after the AfxBeginThread() then the dialog DOES display. If I place 'while(1) Sleep(100);' (or any other code) after the AfxBeginThread() then it does not return. I have narrowed the problem down to a particular line (510) within 'dlgcore.cpp' // disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent && hWndParent != ::GetDesktopWindow() && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); /////// <--- THIS HANGS FOREVER bEnableParent = TRUE; } Creating a modeless dialog does not fix the problem - Create() does not reurn instead. Does anyone have any ideas as to what the problem could be? Please advise. Thank you!

          K Offline
          K Offline
          KarstenK
          wrote on last edited by
          #4

          Your Thread Dialog wants to disable the main dialog. :~ There can be only one modal dialog per Thread. -> Parent = NULL or modeless Dialog (tip: with new and self destruction)

          Greetings from Germany

          1 Reply Last reply
          0
          • M Mr Simple

            Hi, I have created a 'please wait' dialog which is loaded when a user clicks on a button. A new thread is launched to load the button so the main thread can continue what it is doing. The button code; CPleaseWait *dlgWait = new CPleaseWait(this); AfxBeginThread(PleaseWaitThread, dlgWait); Then in the new thread; CPleaseWait dlg = (CPleaseWait*)lpParam; dlg.DoModal(); return 0; It is very simple code, which I have had working before. The problem is that when called, DoModal never returns, so the dialog doesnt get displayed (it doesnt get as far as InitDialog). The main thread continues running however. If I place a 'return;' directly after the AfxBeginThread() then the dialog DOES display. If I place 'while(1) Sleep(100);' (or any other code) after the AfxBeginThread() then it does not return. I have narrowed the problem down to a particular line (510) within 'dlgcore.cpp' // disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent && hWndParent != ::GetDesktopWindow() && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); /////// <--- THIS HANGS FOREVER bEnableParent = TRUE; } Creating a modeless dialog does not fix the problem - Create() does not reurn instead. Does anyone have any ideas as to what the problem could be? Please advise. Thank you!

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Mr Simple wrote:

            CPleaseWait dlg = (CPleaseWait*)lpParam; dlg.DoModal();

            This looks odd. Try:

            CPleaseWait *dlg = (CPleaseWait *) lpParam;
            dlg->DoModal();


            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            1 Reply Last reply
            0
            • M Mr Simple

              Hi, I have created a 'please wait' dialog which is loaded when a user clicks on a button. A new thread is launched to load the button so the main thread can continue what it is doing. The button code; CPleaseWait *dlgWait = new CPleaseWait(this); AfxBeginThread(PleaseWaitThread, dlgWait); Then in the new thread; CPleaseWait dlg = (CPleaseWait*)lpParam; dlg.DoModal(); return 0; It is very simple code, which I have had working before. The problem is that when called, DoModal never returns, so the dialog doesnt get displayed (it doesnt get as far as InitDialog). The main thread continues running however. If I place a 'return;' directly after the AfxBeginThread() then the dialog DOES display. If I place 'while(1) Sleep(100);' (or any other code) after the AfxBeginThread() then it does not return. I have narrowed the problem down to a particular line (510) within 'dlgcore.cpp' // disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent && hWndParent != ::GetDesktopWindow() && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); /////// <--- THIS HANGS FOREVER bEnableParent = TRUE; } Creating a modeless dialog does not fix the problem - Create() does not reurn instead. Does anyone have any ideas as to what the problem could be? Please advise. Thank you!

              M Offline
              M Offline
              Mr Simple
              wrote on last edited by
              #6

              Thanks folks. Using "new CPleaseWait(NULL);" didn't fix the problem, oh, and I was using dlg->DoModal (as opposed to .DoModdal) it was a typo as the machine I am coding on isnt networked :-) I ended up using the modeless after disabling the main form, as suggested. I have another question, not too important anymore, but would be handy to know. Inside the InitDialog() I had a new thread which alters the contents of a label to show the search hasnt crashed. It has worked before in the old application (I have just realised that the old problem didnt exist then as it was being used as a splash screen when the app was started, hence no parent). Now, the 'SetWindowText()' to update the label runs once, then doesnt return the second time. I cant look any further into it as no code is available for debugging (other than assembly) meaning it is quicker for me to delete that bit :-) Like i say, its not important now, but any ideas? Thanks for the help everyone, I had been staring at those lines of code for hours!

              N 1 Reply Last reply
              0
              • M Mr Simple

                Thanks folks. Using "new CPleaseWait(NULL);" didn't fix the problem, oh, and I was using dlg->DoModal (as opposed to .DoModdal) it was a typo as the machine I am coding on isnt networked :-) I ended up using the modeless after disabling the main form, as suggested. I have another question, not too important anymore, but would be handy to know. Inside the InitDialog() I had a new thread which alters the contents of a label to show the search hasnt crashed. It has worked before in the old application (I have just realised that the old problem didnt exist then as it was being used as a splash screen when the app was started, hence no parent). Now, the 'SetWindowText()' to update the label runs once, then doesnt return the second time. I cant look any further into it as no code is available for debugging (other than assembly) meaning it is quicker for me to delete that bit :-) Like i say, its not important now, but any ideas? Thanks for the help everyone, I had been staring at those lines of code for hours!

                N Offline
                N Offline
                Nelek
                wrote on last edited by
                #7

                Hi, I had problems with something similar in one project. I was using static labels to show variable datas. It worked good sometimes, but not as I wanted. So I changed them with Edits, set the protection to write and erase the border (all in resource editor), then just calling SetWindowText was enough and never failed. BTW, are you erasing the background before sending the message to update screen?

                Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson ;)

                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