How To Restrict Dialog Box in an SDI to be With in Application Boundaries [modified]
-
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
-
Add some code in your
OnInitDialog()
method (where you handle theWM_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.
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.
-
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.
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)
-
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)
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.
-
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
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
-
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
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. :)
-
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. :)
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
-
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
Nop. This does not work for me. Any ways thanks for the help. :)
-
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.
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.
-
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
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
-
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
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