How can i prevent a dialog closing by Alt+F4 ?
I am using PreTranslateMessage(),,,,what is the Virtual key #define for Alt+F4 or is there any other way?,,,,thank you

It's a combination of the F4 key code combined with the alt modifiers, you need to check both.

But i'd avoid trying to prevent it if I was you....

Member Avatar for jencas

If I remember correctly, Alt+F4 never reaches PreTranslateMessage()

Here's the list of virtual key codes. jencas makes a good point that I was wondering about myself. Still, give it a try and let us know what happens.

How can i prevent a dialog closing by Alt+F4 ?
I am using PreTranslateMessage()

Instead of PreTranslateMessage(), add a handler for WM_SYSCOMMAND and detect SC_CLOSE.

You sure it's not WM_CLOSE?

You sure it's not WM_CLOSE?

Yes, SC_CLOSE comes with WM_SYSCOMMAND.

Seems pretty simple to me, add this to the dialog message procedure, and windows shouldn't handle the ALT-F4.

case WM_SYSKEYDOWN: break;

Seems pretty simple to me, add this to the dialog message procedure, and windows shouldn't handle the ALT-F4.

case WM_SYSKEYDOWN: break;

Hmm .. that renders the system menu completely ineffective, which is probably not what the OP wants.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.