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. Can´t access close button in a modeless cdialog

Can´t access close button in a modeless cdialog

Scheduled Pinned Locked Moved C / C++ / MFC
testingbeta-testinghelpquestion
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.
  • S Offline
    S Offline
    Stefan_L_01
    wrote on last edited by
    #1

    Hello I use a modeless CDialog to display some CProgessCtrl controls. It has a Close button which i want to use to abort a loop. The progress controls of the modeless dialog are updated during this loop. The constructor of the dialog is CDialogVorgang::CDialogVorgang(CWnd* pParent /*=NULL*/) : CDialog() { Create(CDialogVorgang::IDD, pParent); //{{AFX_DATA_INIT(CDialogVorgang) //}}AFX_DATA_INIT } and i initialize it with // Modeless dialog init CDialogVorgang* pDlgVorgang = new CDialogVorgang(); pDlgVorgang->SetWindowText("Datenbank Aktualisierung"); pDlgVorgang->m_cProgressVorgang.SetRange(0, 3); pDlgVorgang->m_cProgressGesamt.SetRange(0, v_oaV->GetSize()); // Show Dialog pDlgVorgang->ShowWindow(SW_SHOW); // is somehow necessary to display static text (??) pDlgVorgang->UpdateWindow(); // loop for (int nv = 0; nv < v_oaV->GetSize(); nv++) { pDlgVorgang->IncGesamt(); pDlgVorgang->ResetVorgang(); pDlgVorgang->IncVorgang(); ..... } The dialog shows up, and the progess controls are adjusted correctly(in the functions IncGesamt, ResetVorgang etc), but i can´t press the cancel button during the loop. Only AFTER the loop has stopped i can close the dialog. It´s also strange that i had to include the UpdateWindow function. Without it static text would not have showed up, even the cancel button was invisible. I added for testing a windowproc message handling function to my modeless cdialog class, but during the loop it is never called. Is it possible that the loop - and thus the adjustment of the progess controls - starts to quickly before the window is registered? Do i have to wait a bit, and if so, how? Thank you for any help niklas

    J 1 Reply Last reply
    0
    • S Stefan_L_01

      Hello I use a modeless CDialog to display some CProgessCtrl controls. It has a Close button which i want to use to abort a loop. The progress controls of the modeless dialog are updated during this loop. The constructor of the dialog is CDialogVorgang::CDialogVorgang(CWnd* pParent /*=NULL*/) : CDialog() { Create(CDialogVorgang::IDD, pParent); //{{AFX_DATA_INIT(CDialogVorgang) //}}AFX_DATA_INIT } and i initialize it with // Modeless dialog init CDialogVorgang* pDlgVorgang = new CDialogVorgang(); pDlgVorgang->SetWindowText("Datenbank Aktualisierung"); pDlgVorgang->m_cProgressVorgang.SetRange(0, 3); pDlgVorgang->m_cProgressGesamt.SetRange(0, v_oaV->GetSize()); // Show Dialog pDlgVorgang->ShowWindow(SW_SHOW); // is somehow necessary to display static text (??) pDlgVorgang->UpdateWindow(); // loop for (int nv = 0; nv < v_oaV->GetSize(); nv++) { pDlgVorgang->IncGesamt(); pDlgVorgang->ResetVorgang(); pDlgVorgang->IncVorgang(); ..... } The dialog shows up, and the progess controls are adjusted correctly(in the functions IncGesamt, ResetVorgang etc), but i can´t press the cancel button during the loop. Only AFTER the loop has stopped i can close the dialog. It´s also strange that i had to include the UpdateWindow function. Without it static text would not have showed up, even the cancel button was invisible. I added for testing a windowproc message handling function to my modeless cdialog class, but during the loop it is never called. Is it possible that the loop - and thus the adjustment of the progess controls - starts to quickly before the window is registered? Do i have to wait a bit, and if so, how? Thank you for any help niklas

      J Offline
      J Offline
      Joan M
      wrote on last edited by
      #2

      The problem with the button is that you are getting all the CPU occupied with your loop (take a look at the task administrator) and then you can press the button but it won't be able to be processed until the exit of your loop. If you want to solve it think about creating a thread in order to be able to update the progress ctrls while you'll be able to cancel the process. Remember that if you want to handle multiple threads you must control the secondary effects. ----------------------------------------------------------- It's strange that the static text is not displayed... I can only think about you have any other control over it and that only when you repaint it it can be shown...

      https://www.robotecnik.com freelance robots, PLC and CNC programmer.

      S 1 Reply Last reply
      0
      • J Joan M

        The problem with the button is that you are getting all the CPU occupied with your loop (take a look at the task administrator) and then you can press the button but it won't be able to be processed until the exit of your loop. If you want to solve it think about creating a thread in order to be able to update the progress ctrls while you'll be able to cancel the process. Remember that if you want to handle multiple threads you must control the secondary effects. ----------------------------------------------------------- It's strange that the static text is not displayed... I can only think about you have any other control over it and that only when you repaint it it can be shown...

        S Offline
        S Offline
        Stefan_L_01
        wrote on last edited by
        #3

        But isn´t a modeless dialog a "standalone" thread? I mean doesn´t modeless mean that it runs independent from any parent as an individual thread? niklas

        J 2 Replies Last reply
        0
        • S Stefan_L_01

          But isn´t a modeless dialog a "standalone" thread? I mean doesn´t modeless mean that it runs independent from any parent as an individual thread? niklas

          J Offline
          J Offline
          Joan M
          wrote on last edited by
          #4

          You are occupying all the cpu in the main thread and nothing reacts as expected. I still believe that you should implement your loop inside another thread... hope this helps...

          https://www.robotecnik.com freelance robots, PLC and CNC programmer.

          1 Reply Last reply
          0
          • S Stefan_L_01

            But isn´t a modeless dialog a "standalone" thread? I mean doesn´t modeless mean that it runs independent from any parent as an individual thread? niklas

            J Offline
            J Offline
            Joan M
            wrote on last edited by
            #5

            Another way to do it (depending on your code) would be to use timer messages to handle that in order to free a little bit more the CPU... Hope this helps...

            https://www.robotecnik.com freelance robots, PLC and CNC programmer.

            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