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. Modaless Dialog Box

Modaless Dialog Box

Scheduled Pinned Locked Moved C / C++ / MFC
8 Posts 4 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.
  • J Offline
    J Offline
    John Uhlenbrock
    wrote on last edited by
    #1

    I have created a modaless dialog box, that needs to retain the focus, ie I don't want people to be able to click on the main frame, while this dialog box is up. I can't seem to find the style marker or whatever needs to be set to do this.

    C D 2 Replies Last reply
    0
    • J John Uhlenbrock

      I have created a modaless dialog box, that needs to retain the focus, ie I don't want people to be able to click on the main frame, while this dialog box is up. I can't seem to find the style marker or whatever needs to be set to do this.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I would do this by checking the variable that holds the modeless dialog when my main app recieved focus, and if it was non-NULL ( the dialog existed ), set the focus back to the dialog. Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.

      J 1 Reply Last reply
      0
      • C Christian Graus

        I would do this by checking the variable that holds the modeless dialog when my main app recieved focus, and if it was non-NULL ( the dialog existed ), set the focus back to the dialog. Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.

        J Offline
        J Offline
        John Uhlenbrock
        wrote on last edited by
        #3

        I just attempted to over-ride the WM_SETFOCUS message for my CMainFrame class. When I received it, I checked a boolean variable I created to determine whether the dialog was still "alive" and if it was, I called the ::SetFocus() function to give the focus back to that dialog. This created a bad flickering. Each time I tried to revert the focus back, the program then tried to give the focus back to the main frame (i'm not sure why), and thus I had an endless loop. I also tried to over-ride the WM_LBUTTONUP message, but for some reason I could never get into that function. Any more help would be great. - John

        C 1 Reply Last reply
        0
        • J John Uhlenbrock

          I just attempted to over-ride the WM_SETFOCUS message for my CMainFrame class. When I received it, I checked a boolean variable I created to determine whether the dialog was still "alive" and if it was, I called the ::SetFocus() function to give the focus back to that dialog. This created a bad flickering. Each time I tried to revert the focus back, the program then tried to give the focus back to the main frame (i'm not sure why), and thus I had an endless loop. I also tried to over-ride the WM_LBUTTONUP message, but for some reason I could never get into that function. Any more help would be great. - John

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Hmmm... Here's a thought. When you create the dialog, call SetCapture() so that your dialog recieves all mouse messages first, and then you can catch and kill anything that occurs outside your dialog. That's better - the solution is contained in the dialog where it should be. Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.

          J 1 Reply Last reply
          0
          • C Christian Graus

            Hmmm... Here's a thought. When you create the dialog, call SetCapture() so that your dialog recieves all mouse messages first, and then you can catch and kill anything that occurs outside your dialog. That's better - the solution is contained in the dialog where it should be. Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.

            J Offline
            J Offline
            John Uhlenbrock
            wrote on last edited by
            #5

            Ok. Here's the trouble with that. It does capture all the mouse input, but the dialog does not respond to it. No matter where I click or what I try to drag, nothing happens. If I click outside the main frame, then whatever app that was in the back ground get the focus, which is fine. However, when I bring my app back up, I can click on the main frame and such all over again, and SetCapture has been invalidated or something.

            C A 2 Replies Last reply
            0
            • J John Uhlenbrock

              Ok. Here's the trouble with that. It does capture all the mouse input, but the dialog does not respond to it. No matter where I click or what I try to drag, nothing happens. If I click outside the main frame, then whatever app that was in the back ground get the focus, which is fine. However, when I bring my app back up, I can click on the main frame and such all over again, and SetCapture has been invalidated or something.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              I remember having trouble like that. I did a colour picker dialog and made it so you could click anywhere on the screen to select colours. I'm loading the code right now to see what I did. I set a timer in OnInit to go off twice a second and then do this:

              if(nIDEvent == 42)
              {
              	CPoint pt;
              	GetCursorPos(&pt);
              	
              	CRect rc;
              	GetWindowRect(&rc);
              
              	if (!rc.PtInRect(pt))
              		SetCapture();
              }
              CDialog::OnTimer(nIDEvent);
              

              In MouseMove I do this:

              CPoint pt;
              GetCursorPos(&pt);
              	
              CRect rc;
              GetWindowRect(&rc);
              
              if (rc.PtInRect(pt))
              	ReleaseCapture();
              

              Essentially I found I had to release capture every time the mouse was in the dialog, and set it before it left, releasing it when people click. Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.

              1 Reply Last reply
              0
              • J John Uhlenbrock

                Ok. Here's the trouble with that. It does capture all the mouse input, but the dialog does not respond to it. No matter where I click or what I try to drag, nothing happens. If I click outside the main frame, then whatever app that was in the back ground get the focus, which is fine. However, when I bring my app back up, I can click on the main frame and such all over again, and SetCapture has been invalidated or something.

                A Offline
                A Offline
                Anders Molin
                wrote on last edited by
                #7

                Just an idea... Create a second thread that shows a modal dialog... - Anders Money talks, but all mine ever says is "Goodbye!"

                1 Reply Last reply
                0
                • J John Uhlenbrock

                  I have created a modaless dialog box, that needs to retain the focus, ie I don't want people to be able to click on the main frame, while this dialog box is up. I can't seem to find the style marker or whatever needs to be set to do this.

                  D Offline
                  D Offline
                  Dave Glick
                  wrote on last edited by
                  #8

                  I have a need for this quite often, and while I haven't gotten around to writing my own class to do it, I know of one that works very well. It's called PassiveDialog and comes with the ITCLib package(http://devcentral.iftech.com). If I look at the code (just to get ideas) I find they've overridden the DoModal function: ... TRY { // create modeless dialog AfxHookWindowCreate(this); if (CreateDlgIndirect(lpDialogTemplate, CWnd::FromHandle(m_hWndParent), hInst)) { if (m_nFlags & WF_CONTINUEMODAL) { m_nFlags |= WF_MODALLOOP; ShowWindow(SW_SHOWNORMAL); UpdateWindow(); Pulse(); } } } ... And created a new Pulse function to pass messages back to the calling code: ... // Check to see if we can do idle work while (bIdle && !::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE)) { if (!(dwFlags & MLF_NOIDLEMSG) && m_hWndParent && lIdleCount == 0) { ::SendMessage(m_hWndParent, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)m_hWnd); } if ((dwFlags & MLF_NOKICKIDLE) || !SendMessage(WM_KICKIDLE, MSGF_DIALOGBOX, lIdleCount++)) { bIdle = FALSE; } } ... For more info, just go download the library. Keep in mind, though, that the code is ©. Hope this helps! -Dave

                  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