1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
interface
procedure showTaskBar;
procedure HideTaskBar;
implementation
uses Math, System.Generics.Collections, TlHelp32,Windows;
var
vistaStartMenuWnd: Integer;
const
SW_SHOW = 5;
SW_HIDE = 0;
VistaStartMenuCaption = 'Start';
function MyEnumThreadWindowsProc(Wnd: hwnd; Data: lParam): Boolean;
var
buffer: array [0 .. 255] of char;
begin
if (GetWindowText(Wnd, buffer, Length(buffer)) > 0) then
begin
if (buffer = VistaStartMenuCaption) then
begin
vistaStartMenuWnd := wnd;
result := false;
exit;
end;
end;
result := TRUE;
end;
function ListProcessThreads(dwOwnerPID: DWORD;pList:Tlist<Integer>): Boolean;
var
hThreadSnap: THANDLE;
te32: TThreadEntry32;
NextProc: Boolean;
begin
pList.Clear;
// Take a snapshot of all running threads
hThreadSnap := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (hThreadSnap = INVALID_HANDLE_VALUE) then begin
result := false;
exit;
end;
// Fill in the size of the structure before using it.
te32.dwSize := sizeof(THREADENTRY32);
// Retrieve information about the first thread,
// and exit if unsuccessful
NextProc := Thread32First(hThreadSnap, te32); // get the first Thread
while NextProc do
begin
if te32.th32OwnerProcessID = dwOwnerPID then // Check the owner Pid against the PID requested
begin
pList.Add(te32.th32ThreadID);
end;
NextProc := Thread32Next(hThreadSnap, te32); // get the Next Thread
end;
// Don't forget to clean up the snapshot object.
CloseHandle(hThreadSnap);
result := TRUE;
end;
function GetVistaStartMenuWnd(var taskBarWnd: Integer): IntPtr;
var
procId: Cardinal;
lList: TList<Integer>;
i: Integer;
begin
// get process that owns the taskbar window
GetWindowThreadProcessId(taskBarWnd, procId);
lList := TList<Integer>.Create;
ListProcessThreads(procId, lList);
for i := 0 to lList.Count - 1 do begin
EnumThreadWindows(lList[i], @MyEnumThreadWindowsProc, 0);
end;
result := vistaStartMenuWnd;
end;
procedure SetVisibility(show: Boolean);
var
startWnd, taskBarWnd: Integer;
begin
// get taskbar window
taskBarWnd := FindWindow('Shell_TrayWnd', nil);
// try it the WinXP way first...
startWnd := FindWindowEx(taskBarWnd, 0, 'Button', 'Start');
if (startWnd = 0) then
begin
// try an alternate way, as mentioned on CodeProject by Earl Waylon Flinn
startWnd := FindWindowEx(0, 0, Pointer($C017), 'Start');
end;
if (startWnd = 0) then
begin
// ok, let's try the Vista easy way...
startWnd := FindWindow('Button', nil);
if (startWnd = 0) then
begin
// no chance, we need to to it the hard way...
startWnd := GetVistaStartMenuWnd(taskBarWnd);
end;
end;
ShowWindow(taskBarWnd, IfThen(show, SW_SHOW, SW_HIDE));
ShowWindow(startWnd, IfThen(show, SW_SHOW, SW_HIDE));
end;
procedure HideTaskBar;
begin
SetVisibility(false);
end;
procedure showTaskBar;
begin
SetVisibility(TRUE);
end; |
Partager