Show main form's real taskbar button

Update 19.11.2006 Now that Windows Vista is out showing main form's real taskbar button is a must have. Otherwise you don't have thumbnails and Flip3D. An article available here:

http://www.installationexcellence.com/articles/VistaWithDelphi/Index.html

explains the full technique. I expect that the code presented there works better than what I have compiled from articles read on the Internet as it comes from Peter Below. Guess this all makes my article here obsolete :)

 

 

!!! While playing with the code presented here I saw multiple bugs coming out of the techniques I use. First of all when you have a modal form open on top of the main form, switching between yours and another window hides the modal form and demands the user to click on the main form so that the modal form would appear. Another side effect is that both the application's window and that of the main form appear in the Applications tab in Windows Task Manager. I tried to make modifications but it seems to hard to make it work. Due to the instability of the code I don't recommend using it!

  Maybe two months ago I posted a question on Borland Newsgroups. I wondered how come the taskbar button of a Delphi Application behaves different than the one of a MS MFC application for example. I mean I was surprised to see that on a Windows 2000/XP there are missing items from the system menu displayed at the taskbar. Someone from Borland told me that this is because the button belongs to the Application's window handle and not to the one of the main form. Using two well know techniques: Hide a button from taskbar (applied for the Application button) and Show a button for a given form (applied to obtain a button for the Main form) I managed to achieve the behaviour I wanted. Then I saw a bug, a problem occured when Minimizing the Application. I won't go too deep into explaining it but will only tell you the workaround. It's pretty simple, you just have to suppress the Application window getting the SC_MINIMIZE command. Enough with the intro scroll down and check out the code. Any comments and especially bug report are welcome =)

And here's the code:

  //Show main form's real task button
  procedure CreateParams(var Params: TCreateParams); override;
  procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;
end;

var
  frmMain: TfrmMain;

implementation

procedure TfrmMain.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);

  //Hide the button created by Delphi for the Application
  SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);

  //Show a button for the main form
  with Params do
  begin
    ExStyle := ExStyle or WS_EX_APPWINDOW;
    WndParent := GetDesktopwindow;
  end;
end;

procedure TfrmMain.WMSysCommand(var Message: TWMSysCommand);
begin
  //Pass minimize straight to the window's handle
  if (Message.CmdType and $FFF0 = SC_MINIMIZE) then
    DefWindowProc(Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0)
  else
    inherited;
end;

 

Copyright © 2006 Wise Guy
wise_guybg@yahoo.com
Created: 14.09.2003

Last revised: 19.11.2006