Stop other programs from minimizing my Win32 application
I've got a Delphi app that is running in an environment where it gets minimized by another aggressive app that is trying to seize the screen entirely (it's POS stuff). When a second application is started it get hunts down the windows and minimizes them, probably by enumerating the windows and hitting them with a 'ShowWindow(handle,SW_MINIMIZE)'.
It seems to me that the thing to do is to pick up these commands and block resize/minimize messages to the window. I've tried ha开发者_如何学JAVAcking around a few handlers to try and capture this behaviour, but still the SW_MINIMIZE will hide it. And Winsight is not showing me much other than the notification messages that something is resizing etc. I've put in a message handler for WMSysCommand messages, but that only seems to stop actions like the minimize button being clicked. And I've tried overriding the WndProc function to filter messages but that doesn't cut it either.
If anyone could shed some light on what happens when the ShowWindow(handle,SW_MINIMIZE) call is inflicted on an application I'd be very grateful!
Thanks Terry
What happens when ShowWindow
is called with SW_MINIMIZE
as 'nCmdShow' is that the window manager minimizes the window.
The system will send various notification messages, some more important to be able to carry out the minimization and the application can act upon, like WM_WINDOWPOSCHANGING
, WM_GETMINMAXINFO
, WM_NCCALCSIZE
, or some just to notify, like WM_WINDOWPOSCHANGED
, WM_MOVE
, WM_SIZE
, but normally, none of these is for blocking the operation.
The cleanest way, I think, if you can decide that the minimization is unexpected, is to respond to a WM_SIZE
message when 'wParam' is SIZE_MINIMIZED
, and restore your window accordingly. Then your form will bounce back from the taskbar:
type
TForm1 = class(TForm)
...
private
procedure WmSize(var Msg: TWMSize); message WM_SIZE;
end;
procedure TForm1.WmSize(var Msg: TWMSize);
begin
inherited;
if (Msg.SizeType = SIZE_MINIMIZED) and IsUnexpectedMinimize then
PostMessage(Handle, WM_SYSCOMMAND, SC_RESTORE, 0);
end;
I don't have any clear idea about how you might decide either a minimization is unexpected or not but it would seem you do. User initiated actions would cause a WM_SYSCOMMAND
to be send, but I don't know if some of the OS features also do that and you'll be able to differentiate if the OS minimizes the window or the aggressive application.
The window recieves a WM_COMMAND message not WM_SYSCOMMAND
精彩评论