modeless Dlg
-
Hi, Is there a way to create a modeless dlg that we cannot move so that it always remains at the same place that I have created it? Thanks Everything's beautiful if you look at it long enough...
You can easily do this via your dialog's OnWindowPosChanging() method. When the modeless dialog is created, save it's window rect to a member variable. Then in OnWindowPosChanging(), change the 'x', 'y', 'cx', and 'cy' values of the WINDOWPOS structure. BEGIN_MESSAGE_MAP(CModelessDlg, CDialog) //{{AFX_MSG_MAP(CModelessDlg) //}}AFX_MSG_MAP ON_WM_WINDOWPOSCHANGING() END_MESSAGE_MAP() BOOL CModelessDlg::OnInitDialog() { CDialog::OnInitDialog(); GetWindowRect(m_rect); return TRUE; } void CModelessDlg::OnWindowPosChanging( WINDOWPOS* lpwndpos ) { lpwndpos->x = m_rect.left; lpwndpos->y = m_rect.top; lpwndpos->cx = m_rect.Width(); lpwndpos->cy = m_rect.Height(); }
-
Hi, Is there a way to create a modeless dlg that we cannot move so that it always remains at the same place that I have created it? Thanks Everything's beautiful if you look at it long enough...
This is another way to do it. To move the dialog the user should drag the dialog caption. you can override the WM_NCHITTEST message and disable the HTCAPTION result from reaching hte system. the could should be like this
UINT CMyDlg::OnNcHitTest(CPoint point) { //Store the result returned by the dialog's WinProc UINT hitResult = CDialog::OnNcHitTest(point); //if the mouse is in the caption bar change the result to HTNOWHERE //so the system wouldn't recognize it if(hitResult == HTCAPTION) return HTNOWHERE; //any other result should be returned as it is return hitResult; }
-
Hi, Is there a way to create a modeless dlg that we cannot move so that it always remains at the same place that I have created it? Thanks Everything's beautiful if you look at it long enough...
There is another simple way to do it. To move the dialog the user must drag the caption bar, thus you can override the WM_NCHITTEST message and disable the system from recognizing that the mouse is in the caption bar. This code shows ho that is done:
UINT CMyDlg::OnNcHitTest(CPoint point) { //store the value returnd by the WndProc UINT hitResult = CDialog::OnNcHitTest(point); //if the mouse is in the caption bar, change the result to HTNOWHERE //so the system does not recognize that the mouse is in hte caption if(hitResult == HTCAPTION) return HTNOWHERE; //any other result mus t be returned as it is return hitResult; }
-
There is another simple way to do it. To move the dialog the user must drag the caption bar, thus you can override the WM_NCHITTEST message and disable the system from recognizing that the mouse is in the caption bar. This code shows ho that is done:
UINT CMyDlg::OnNcHitTest(CPoint point) { //store the value returnd by the WndProc UINT hitResult = CDialog::OnNcHitTest(point); //if the mouse is in the caption bar, change the result to HTNOWHERE //so the system does not recognize that the mouse is in hte caption if(hitResult == HTCAPTION) return HTNOWHERE; //any other result mus t be returned as it is return hitResult; }
If the dialog has a system menu the keyboard can be used to move it, so this isn't good enough. OnGetMinMaxInfo() may do the trick. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com