How to prevent maximizing of a dialog box by an externally sent message

  • Thread starter Thread starter Bob Rock
  • Start date Start date
B

Bob Rock

Hello,

I'd like to prevent hacking of my application by messages sent from the
external. The dialog box already has the maximize button disabled however
I've seen that a simple ShowWindow with the correct window handle sent from
an external application can maximize it. I have tracked window messages sent
to the dialog and there isn't much .... there are WM_GETMINMAXINFO messages
sent to "know" what the dialog can do (max size, position when maximized,
etc.) and WM_WINDOWPOSCHANGING messages sent just before changing
position/size/z-order.
By handling WM_GETMINMAXINFO messages and changing returned info (max size
and position when maximized) and then handling WM_WINDOWPOSCHANGING messages
and ignoring messages when the new size in WINDOWPOS is different from the
one that the dialog should have I can in fact prevent maximizing ... the
problem is that (1) the dialog gets redrawn (even if in the same position
and size) and (2) the state of dialog "maximized" is somehow associated to
it because afterwards I see from the system menu that it can only be
restored or minimized. It there a simpler solution or am I missing just a
few more steps?


Bob Rock
 
Maximizing usually is done by WM_SHOWWINDOW with SW_MAXIMIZED or something
like that. Why don't you try to simply intercept these messages and ignore
them?

Just a thought...

-Gernot

In order to reply, revert my forename.
 
Maximizing usually is done by WM_SHOWWINDOW with SW_MAXIMIZED or something
like that. Why don't you try to simply intercept these messages and ignore
them?

Just a thought...

-Gernot

In order to reply, revert my forename.

Hello Gernot, I haven't seen such a message among those sent to my dialog
.... I'll try it and let you know. Thx.

Regards,
Bob Rock
 
Maximizing usually is done by WM_SHOWWINDOW with SW_MAXIMIZED or something
like that. Why don't you try to simply intercept these messages and ignore
them?

Unfortunately WM_SHOWWINDOW is not sent when a window gets maximized ..
while SW_MAXIMIZED is a parameter that can be used with ShowWindow.

However I found the following on the MSDN:

Maximizing: When a child window is maximized, it uses the screen's maximum
size. To have the child window act similar to an MDI child, two messages
need to be processed; WM_SIZE in the main parent's window procedure and
WM_GETMINMAXINFO in the child's window procedure.

WM_SIZE of the child's parent window procedure checks for SIZE_MAXIMIZE and
SIZE_RESTORE. Then, if the child window is maximized, call ShowWindow() with
SW_MAXIMIZED. This method adjusts the child window's size to the new size of
the parent's client area.

On WM_GETMINMAXINFO of the child's window procedure, calculate the size of
the parent's client area. Use the newly calculated size and set the
ptMaxSize variable of the MINMAXINFO structure. This ensures that the child
is always fully contained within its parent client area when maximized.


Bob Rock
 
How does hacking of your application involve maximizing of your dialogue?!


Hello,

I'd like to prevent hacking of my application by messages sent from the
external. The dialog box already has the maximize button disabled however
I've seen that a simple ShowWindow with the correct window handle sent from
an external application can maximize it. I have tracked window messages sent
to the dialog and there isn't much .... there are WM_GETMINMAXINFO messages
sent to "know" what the dialog can do (max size, position when maximized,
etc.) and WM_WINDOWPOSCHANGING messages sent just before changing
position/size/z-order.
By handling WM_GETMINMAXINFO messages and changing returned info (max size
and position when maximized) and then handling WM_WINDOWPOSCHANGING messages
and ignoring messages when the new size in WINDOWPOS is different from the
one that the dialog should have I can in fact prevent maximizing ... the
problem is that (1) the dialog gets redrawn (even if in the same position
and size) and (2) the state of dialog "maximized" is somehow associated to
it because afterwards I see from the system menu that it can only be
restored or minimized. It there a simpler solution or am I missing just a
few more steps?


Bob Rock
 
Back
Top