> 如何取得/改變工作列的狀態?

下面的程式範例可以取得工作列的狀態:

uses ShellApi;

procedure TForm1.Button1Click(Sender: TObject);
var 
  abd: TAppBarData;
  i: integer;
begin
  abd.cbSize := SizeOf(abd);
  i := SHAppBarMessage(ABM_GETSTATE, abd);
  ShowMessage(IntToStr(i));
{ Notes:
  0 表示 "最上層顯示" 未勾選,"自動隱藏" 未勾選
  1 表示 "最上層顯示" 未勾選,"自動隱藏" 有勾選
  2 表示 "最上層顯示" 有勾選,"自動隱藏" 未勾選
  3 表示 "最上層顯示" 有勾選,"自動隱藏" 有勾選
}
end;

雖然 MSDN 的文件中有列出 ABM_SETSTATE 這項常數,但卻無法使用它來改變"最上層顯示"以及"自動隱藏"的屬性(在 Delphi 附的 ShellApi.pas 裡面也找不到此常數),以下說明取自 MSDN:

Taskbar Display Options
The taskbar supports two display options: Auto Hide and Always On Top. To set these options, the user must open the taskbar shortcut menu, click Properties, and select or clear the Auto Hide check box or the Always On Top check box. There is no way to set these options programmatically. To retrieve the state of these display options, use the ABM_GETSTATE message. If you would like to be notified when the state of these display options changes, process the ABN_STATECHANGE notification message in your window procedure. To change the state of these display options, use the ABM_SETSTATE message.


上面提到的兩個工作列的屬性也可以在 Registry 裡面找到,位置是
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects,在 Settings 二進位值的第三個 DWORD,如果 "最上層顯示" 為 True 且 "自動隱藏" 為 True,則其值為 00 00 00 03(在 regedit 中看到的是 03 00 00 00)。但你無法透過修改這個數值來改變工作列的狀態,因為 Explorer 會一直去寫入這個機碼以確保其值和目前的設定是相同的。

工作列的視窗類別名稱是 Shell_TrayWnd(你可以利用 Delphi 所附的 WinSight32 找到工作列的視窗類別),你可以利用此類別名稱取得工作列的視窗 Handle,再利用其 Handle 取得或改變視窗的相關資訊,例如,以下的程式片段可以將工具列隱藏起來:

var
  hTaskBar: HWND;
begin
  hTaskBar := FindWindow('Shell_TrayWnd', nil);
  if (hTaskBar <> 0) then
    ShowWindow(hTaskBar, SW_HIDE);
end;

註:工具列雖然被隱藏起來,但是工具列所佔據的空間仍無法為其他視窗所用。

    Source: geocities.com/huanlin_tsai/faq

               ( geocities.com/huanlin_tsai)