Link to home
Start Free TrialLog in
Avatar of Thirstyplusplus
Thirstyplusplus

asked on

A CDialog question.

Hi,
Is there any way to prevent the user from moving  a Dialog Box by holding mouse down on the title bar and dragging?

I assume the question is less than easy.

Avatar of cramer091498
cramer091498

Create a dialog box in the resource editor, with no static or client edge, and no title bar.
When you call this resource, the dialog box will be unmovable.

Cramer

If you want to have the dialog box look normal and do the same thing, you might try intercepting the WM_MOVING message and changing the passed in rectangle address to the windows baseline.  In other words, when you get the WM_MOVING message, put the rectangle back in the same place.  Warning, I've never done this, but the documentation says this should work.
CMyDialog::OnNcHitTest(CPoint pt)
{
  return HTNOWHERE;
}
Avatar of Thirstyplusplus

ASKER

Cyrilbdt, that does not work. Thanks.

jstolan, I do not know how to capture WM_MOVING message directly, in a dialog. Tried overriding the "OnMoving" message map using class wizard. It seems the message is processed at
the base class function itself.

Can u please show a sample code, how to capture the WM_MOVING
message?

I am increasing the points. Help!
Regards.

   
I don't know what you mean with "not work". I create simple dialog based project and the prgram works! the main window wich is dialog can't be moved. send me your e-mail if you want to see example.
Hi! Try this:
UINT CYourtDlg::OnNcHitTest(CPoint point)
{
      //UINT uRes = CDialog::OnNcHitTest(point);
      SetWindowLong(m_hWnd, DWL_MSGRESULT, HTCLIENT);
      return HTCLIENT;
}

UINT CEx1Dlg::OnNcHitTest(CPoint point)
{
      UINT u = CDialog::OnNcHitTest(point);
      if(u == HTCAPTION)
            u = HTNOWHERE;
      return u;
}
from WORKING example
cyrilbdt,
I have tried the following code exactly as u said.
The Frame work never called the function 'CBaseDialog::OnNcHitTest(CPoint point)'.
 
Incidently I am using an SDI application based on CFormView, not Dialog based. The additional dialogs have this problem.

Does that make any difference?

Please see the code from my application...

UINT CBaseDialog::OnNcHitTest(CPoint point)
{
AfxMessageBox("OnNcHitTest fired"); //I never got this
UINT u = CDialog::OnNcHitTest(point);
if(u == HTCAPTION)
u = HTNOWHERE;
return u;
}
/***********************/
migel,

For the same reason as sited above, I have to reject your answer too.




Are you add ON_WM_NCHITTEST() to the dialog message Map?

by default when you invoke ClassWizard on CDialog derived class in message map there is no WM_NCHITTEST. You should goto ClassInfo tab an there to change Message Filter to Window. then back to Message Map and use Add function button to add WM_NCHITTEST member.

Hope this helps
/**This question being reloaded only to transfer points to
   Cyrilbdt's account.**/

Cyrilbdt,

That was pure ignorance on my part. I did not go by the Class wizard. It works fine.

I have reloaded the question so that I can give the points
to u. Thanks.
 
My sincere thanks to  migel also but the points goes to cyrilbdt,
because originally he had answered the question.

I sincerely  apologize to all for I rejected a correct answer.

bye
 



ASKER CERTIFIED SOLUTION
Avatar of cyrilbdt
cyrilbdt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial