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. How To Restrict Dialog Box in an SDI to be With in Application Boundaries [modified]

How To Restrict Dialog Box in an SDI to be With in Application Boundaries [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
12 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.
  • K Offline
    K Offline
    K ARUN KUMAR
    wrote on last edited by
    #1

    Hi Friends, I have an interesting question for all. How can i restrict a dialog box(Modal or modeless) to stay within the application boundaries? Just like CView derived objects will not move out of application. I know we can do it with OnMove(..) event handling. But, i wanted to know whether there are any other direct means like by setting some properties to CDialog class. Please help me with this. Regards, K ARUN KUMAR

    modified on Tuesday, May 4, 2010 5:30 AM

    L S D 3 Replies Last reply
    0
    • K K ARUN KUMAR

      Hi Friends, I have an interesting question for all. How can i restrict a dialog box(Modal or modeless) to stay within the application boundaries? Just like CView derived objects will not move out of application. I know we can do it with OnMove(..) event handling. But, i wanted to know whether there are any other direct means like by setting some properties to CDialog class. Please help me with this. Regards, K ARUN KUMAR

      modified on Tuesday, May 4, 2010 5:30 AM

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Add some code in your OnInitDialog() method (where you handle the WM_INITDIALOG message) to set your diaolg's window within the confines of its parent Window, assuming it is large enough.

      It's time for a new signature.

      K 1 Reply Last reply
      0
      • L Lost User

        Add some code in your OnInitDialog() method (where you handle the WM_INITDIALOG message) to set your diaolg's window within the confines of its parent Window, assuming it is large enough.

        It's time for a new signature.

        K Offline
        K Offline
        K ARUN KUMAR
        wrote on last edited by
        #3

        Hi Richard, As advised I have limited the size to be with in the application. But, the problem comes when user is trying to move the dialog. It goes out of application boundaries. I want a functionality similar to CView child objects which stay with in the MainFrame.

        enhzflepE 1 Reply Last reply
        0
        • K K ARUN KUMAR

          Hi Richard, As advised I have limited the size to be with in the application. But, the problem comes when user is trying to move the dialog. It goes out of application boundaries. I want a functionality similar to CView child objects which stay with in the MainFrame.

          enhzflepE Offline
          enhzflepE Offline
          enhzflep
          wrote on last edited by
          #4

          Hi Arun, To the best of my knowledge, it doesn't get any better than handling the move messages. If you also handle the move/size messages of the parent, you'll know what your boundary dimensions without requesting them specifically every time your child dialog is moved. (unless of course mfc does this for you behind the scenes)

          K 1 Reply Last reply
          0
          • enhzflepE enhzflep

            Hi Arun, To the best of my knowledge, it doesn't get any better than handling the move messages. If you also handle the move/size messages of the parent, you'll know what your boundary dimensions without requesting them specifically every time your child dialog is moved. (unless of course mfc does this for you behind the scenes)

            K Offline
            K Offline
            K ARUN KUMAR
            wrote on last edited by
            #5

            Hi enhzflep, Yep.I have implemented the OnMove(..) solution for this. But seriously searching for some direct method like inheriting some poperties of CView which will make the dialog to be constrained to be with in application. Hope any one knows the better solution. Thanks Mate.

            L 1 Reply Last reply
            0
            • K K ARUN KUMAR

              Hi Friends, I have an interesting question for all. How can i restrict a dialog box(Modal or modeless) to stay within the application boundaries? Just like CView derived objects will not move out of application. I know we can do it with OnMove(..) event handling. But, i wanted to know whether there are any other direct means like by setting some properties to CDialog class. Please help me with this. Regards, K ARUN KUMAR

              modified on Tuesday, May 4, 2010 5:30 AM

              S Offline
              S Offline
              Software_Developer
              wrote on last edited by
              #6

              A CFrameWind is the top window in an application. Embed a CDialog into a CFrameWnd so that when the CFrameWnd is moved or minimized, the CDialog will also be moved and minimized. CFrameWnd manages all of its child windows so that they fill its client area. If you have a toolbar, a status bar and a CFormView they will all be positioned and sized automatically by the CFrameWnd. CFrameWnd http://msdn.microsoft.com/en-us/library/4y17z36a(VS.80).aspx

              K 1 Reply Last reply
              0
              • S Software_Developer

                A CFrameWind is the top window in an application. Embed a CDialog into a CFrameWnd so that when the CFrameWnd is moved or minimized, the CDialog will also be moved and minimized. CFrameWnd manages all of its child windows so that they fill its client area. If you have a toolbar, a status bar and a CFormView they will all be positioned and sized automatically by the CFrameWnd. CFrameWnd http://msdn.microsoft.com/en-us/library/4y17z36a(VS.80).aspx

                K Offline
                K Offline
                K ARUN KUMAR
                wrote on last edited by
                #7

                Hi Micheal, Thanks for your reply. How to embed the CDialog into the CFrameWnd in SDI application so that my requirement is accomplished. I mean a bit of code. Please help me. :)

                S 1 Reply Last reply
                0
                • K K ARUN KUMAR

                  Hi Micheal, Thanks for your reply. How to embed the CDialog into the CFrameWnd in SDI application so that my requirement is accomplished. I mean a bit of code. Please help me. :)

                  S Offline
                  S Offline
                  Software_Developer
                  wrote on last edited by
                  #8

                  http://www.codeproject.com/Messages/381389/CFormView-and-Child-Dialogs.aspx[^] Modeless Dialogs with MFC http://www.voidnish.com/Articles/ShowArticle.aspx?code=gettingmodeless[^] http://aclacl.brinkster.net/MFC/ch08c.htm[^]

                  modified on Tuesday, May 4, 2010 6:59 AM

                  K 1 Reply Last reply
                  0
                  • S Software_Developer

                    http://www.codeproject.com/Messages/381389/CFormView-and-Child-Dialogs.aspx[^] Modeless Dialogs with MFC http://www.voidnish.com/Articles/ShowArticle.aspx?code=gettingmodeless[^] http://aclacl.brinkster.net/MFC/ch08c.htm[^]

                    modified on Tuesday, May 4, 2010 6:59 AM

                    K Offline
                    K Offline
                    K ARUN KUMAR
                    wrote on last edited by
                    #9

                    Nop. This does not work for me. Any ways thanks for the help. :)

                    1 Reply Last reply
                    0
                    • K K ARUN KUMAR

                      Hi enhzflep, Yep.I have implemented the OnMove(..) solution for this. But seriously searching for some direct method like inheriting some poperties of CView which will make the dialog to be constrained to be with in application. Hope any one knows the better solution. Thanks Mate.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      K ARUN KUMAR wrote:

                      Hope any one knows the better solution.

                      There isn't one, other than the suggestions you have already been given by other posters. You need to remember that a dialog should be a short lived window that allows interaction between your app and the user. If you want it to be longer lived and/or to restrict its positioning then you should make it a child window of your frame as described below.

                      It's time for a new signature.

                      1 Reply Last reply
                      0
                      • K K ARUN KUMAR

                        Hi Friends, I have an interesting question for all. How can i restrict a dialog box(Modal or modeless) to stay within the application boundaries? Just like CView derived objects will not move out of application. I know we can do it with OnMove(..) event handling. But, i wanted to know whether there are any other direct means like by setting some properties to CDialog class. Please help me with this. Regards, K ARUN KUMAR

                        modified on Tuesday, May 4, 2010 5:30 AM

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

                        See if this helps.

                        "One man's wage rise is another man's price increase." - Harold Wilson

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        "Man who follows car will be exhausted." - Confucius

                        K 1 Reply Last reply
                        0
                        • D David Crow

                          See if this helps.

                          "One man's wage rise is another man's price increase." - Harold Wilson

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          "Man who follows car will be exhausted." - Confucius

                          K Offline
                          K Offline
                          K ARUN KUMAR
                          wrote on last edited by
                          #12

                          Thanks David.. That worked. One more thing. If the dialog is a modeless dialog and if the user goes back to the main frame window and moves the window, the modeless dialog will go out of application. So for this i have added the WM_MOVING event in MainFrame class. void CMainFrame::OnMoving(UINT fwSide, LPRECT pRect) { //CFrameWnd::OnMoving(fwSide, pRect); HWND hWnd = pDlg->GetSafeHwnd(); RECT rc; RECT* pRc=&rc; rc.left=rc.top=rc.right=rc.bottom=0; LRESULT result = ::SendMessage(hWnd, WM_MOVING, (WPARAM)fwSide, (LPARAM)&rc); } and modified the WM_MOVING handler of Modeless Dialog as below. void CModelessDlg::OnMoving(UINT fwSide, LPRECT pRect) { CDialog::OnMoving(fwSide, pRect); CRect rcParent; if(pRect->right==0) //Calin from MainFrame GetWindowRect(pRect); GetOwner()->GetWindowRect(rcParent); // keep the child's left edge inside the parent's right edge pRect->left = min(pRect->left, rcParent.right - m_nWidth); // keep the child's left edge inside the parent's left edge pRect->left = max(pRect->left, rcParent.left); // keep the child's top edge inside the parent's bottom edge pRect->top = min(pRect->top, rcParent.bottom - m_nHeight); // keep the child's top edge inside the parent's top edge pRect->top = max(pRect->top, rcParent.top); // keep the child's right edge inside the parent's right edge pRect->right = min(pRect->right, rcParent.right); // keep the child's right edge inside the parent's left edge pRect->right = max(pRect->right, rcParent.left + m_nWidth); // keep the child's bottom edge inside the parent's bottom edge pRect->bottom = min(pRect->bottom, rcParent.bottom); // keep the child's bottom edge inside the parent's top edge pRect->bottom = max(pRect->bottom, rcParent.top + m_nHeight); if((rcParent.Width() < pRect->right - pRect->left) || (rcParent.Height() < pRect->bottom - pRect->top)) { this->ShowWindow(SW_HIDE); } else this->ShowWindow(SW_SHOW); this->MoveWindow(pRect); //Added by Arun } Once again Thanks a lot David..... :)

                          modified on Wednesday, May 5, 2010 5:31 AM

                          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