2007. szeptember 18., kedd

How to toggle the AlwaysOnTop property of the Windows Taskbar


Problem/Question/Abstract:

Can anyone tell me how to set and reset the Windows TaskBar AlwaysOnTop property from within my application?

Answer:

procedure TForm1.Button1Click(Sender: TObject);
var
  hw: HWND;
begin
  hw := FindWindow('Shell_TrayWnd', nil);
  if hw <> 0 then
  begin
    if (GetWindowLong(hw, GWL_EXSTYLE) and WS_EX_TOPMOST) <> 0 then
    begin
      label1.caption := 'Taskbar is topmost';
      SetWindowPos(hw, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);
    end
    else
    begin
      label1.caption := 'Taskbar is not topmost';
      SetWindowPos(hw, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);
    end;
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése