1

Is it possible to disallow minimizing of a form\application in Delphi ?

I found the following code:

procedure TForm1.WMShowWindow(var Msg: TWMShowWindow);
begin
  if not Msg.Show then
    Msg.Result := 0
  else
    inherited;
end;

But if I press windows key + M or WindowsKey + D, then it still gets minimized. Is there a way to prevent this?

nbanic
  • 1,270
  • 1
  • 8
  • 11
Anna
  • 61
  • 2
  • 5

3 Answers3

11

Setting BorderIcons.bsMinimized to false (removing it from the set) will work for WindowsKey + M but will not stop WindowsKey + D. I think that makes sense. The difference between the two is the first is asking all windows to minimize while the second is an explicit request by the user to see their desktop. Overriding the latter would probably annoy the user (similiar to forcing yourself into focus).

2

or you can place a keyboard hook and catch winkey+d or winkey+m and keep your form maxmized.

avar
  • 1,180
  • 2
  • 13
  • 28
  • 1
    and annoy the bejeezus out of your users... Nevertheless, +1 for it being a correct solution. – Lieven Keersmaekers Jun 03 '09 at 09:33
  • in my case the user wants it to stay maximised – Anna Jun 03 '09 at 11:10
  • Hello Avar , thank you for your comment , can you please give me the code to keep the form maximised – Anna Jun 03 '09 at 12:03
  • Anna, this may be what you are looking for (more like a kiosk). http://stackoverflow.com/questions/14451/what-is-the-best-way-to-make-a-delphi-application-completely-full-screen – Ryan VanIderstine Jun 03 '09 at 12:28
  • i found something interesting : "Show Desktop" sends the command "ToggleDesktop", which, among other things, posts a DTM_RAISE message (WM_USER + 83) to the Desktop (Progman) to set it on foreground." http://www.eggheadcafe.com/forumarchives/win32programmerui/Jun2005/post23443993.asp i'll try to write something with this, need time :) – avar Jun 03 '09 at 12:33
  • hi ann, today i'v tested something, in the form create method put something like var progmanhandle : Thandle; progmanhandle:=findwindow('Progman','Program Manager'); if progmanhandle <> 0 then begin ParentWindow:= progmanhandle; end; that will attach your form as child of desktop, and never hide with winkey+d or winkey+m; but when you start your app i didn't show itself as usual. – avar Jun 06 '09 at 06:10
0

Just put to the form onShow event such code:

  WindowState:=wsMaximized;

And to the OnCanResize this:

  if (newwidth<width) and (newheight<height) then
    Resize:=false;
Taras
  • 391
  • 4
  • 10