Disable the 'X' button on the titlebar of a dialog box

    In a VC++ application, the 'X' button of the Dialog's titlebar is required to be disabled. This cannot be set directly in the dialog's property. Is there any othere programmatical way of disabling it??
Please reply me as soon as possible as it is very urgent.
Who is Participating?
Laminamia063099Connect With a Mentor Commented:
Yes, you need to hook the dialog box's WM_NCHITEST messages, send them through the DefWindowProc, which will return where the mouse hit.  The return value of the DefWindowProc (call it from your switch statement on WM_NCHITTEST) will be the position of the mouse action.  You need to check to see if it's HT_SYSMENU, and if so, take no action and return, disabling this message.  

If this is unsatisfactory, say so and there are other ways of doing it, but this is easy to code and quick. :)

There is a better way

This is done through a round-about means.  You must disable the close menu option of the window's system menu, then the button will be disabled. Use

HMENU SysMen = GetSystemMenu(WndHnd,false); // >> window's system menu.

I stand corrected.  There is a better way :)

Thanks nietod.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.