Entwickler-Ecke

Windows API - Desktop, Taskbar, Start-Menu verstecken / Workarea verändern


Xion - Fr 02.02.07 15:17
Titel: Desktop, Taskbar, Start-Menu verstecken / Workarea verändern
Taskbar und Desktop verstecken / Workarea verändern

Wollte hier mal diesen Code als Zusammenfassung hinschreiben, nachdem ich relativ lange danach suchen und ihn erst zusammensuchen musste. Dieser Code ist für alle, die gerne an Windows rumspielen ;) Der Code ist u.a. von Torry und ist nicht meine eigene "Entdeckung".


Taskbar, Desktop verstecken
1:
2:
3:
  TaskbarVisibleMode(False);
  DesktopVisibleMode(False);
  ShowWindowsStartButton(False);


Taskbar, Desktop wieder anzeigen
1:
2:
3:
  TaskbarVisibleMode(True);
  DesktopVisibleMode(True);
  ShowWindowsStartButton(True);




Die einzelnen Funktionen:


ShowWindowsStartButton(bvisible: Boolean)
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:
procedure ShowWindowsStartButton(bvisible: Boolean);
var
  h: hwnd;
  TaskWindow: hwnd;
begin
  if bvisible then
  begin
    h := FindWindowEx(GetDesktopWindow, 0'Button'nil);
    if h<>0 then
    begin
      TaskWindow := FindWindow('Shell_TrayWnd'nil);
      ShowWindow(h, 1 );
      Windows.SetParent(h, TaskWindow);
    end;
  end
  else
  begin
    h := FindWindowEx(FindWindow('Shell_TrayWnd'nil), 0'Button'nil);
    if h<>0 then
    begin
      ShowWindow(h, 0);
      Windows.SetParent(h, 0);
    end;
  end;
end;



TaskbarVisibleMode(bVisible: boolean)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TaskbarVisibleMode(bVisible: boolean);
var
  HTaskbar: HWND;
begin
  HTaskBar := FindWindow('Shell_TrayWnd'nil);
  if HTaskBar<>0 then
  begin
    EnableWindow(HTaskBar, bVisible);
    if bVisible=False then
      ShowWindow(HTaskbar, SW_HIDE)
    else
      ShowWindow(HTaskbar, SW_SHOW);
  end;
end;



DesktopVisibleMode(bVisible: boolean)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure DesktopVisibleMode(bVisible: boolean);
var
  HDesktop: HWND;
begin
  HDesktop := FindWindow('progman'nil);

  if HDesktop<>0 then
  begin
    if bVisible=False then
      ShowWindow(HDesktop, SW_HIDE)
    else
      ShowWindow(HDesktop, SW_SHOW);
  end;
end;


ggf. ist dieser Link noch zu beachten, um die Workarea auf Vollbild zu maximieren
http://www.delphi-library.de/viewtopic.php?t=18442&highlight=taskbar



Funtkionen zum setzen der Workarea:


Setzen der Workarea
1:
  ModifyWorkArea(0,6,0,0); //ein oberer Rand von 6 pixeln entsteht, ähnlich dem, der Taskbar                    



Standard-Workarea
1:
  SetWorkareaToStandard;                    



SetWorkareaToStandard
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:
//http://www.delphi-library.de/viewtopic.php?t=18442&highlight=taskbar
procedure SetWorkareaToStandard;
{ set workarea to standard screen (= excluding taskbar) }
var
  hApp: HWND;
  rcApp, rcWork: TRect;
begin
  { prepare a default fullscreen workarea }
  rcWork.Top:=0;
  rcWork.Left:=0;
  rcWork.Bottom:= GetSystemMetrics(SM_CYSCREEN);
  rcWork.Right:= GetSystemMetrics(SM_CXSCREEN);

  { get the taskbar handle }
  hApp := FindWindow('Shell_TrayWnd''');
  if hApp <> 0 then begin
    { get the size of the taskbar }
    GetWindowRect(hApp, rcApp);
    { cut the workarea to place the taskbar }
    if rcApp.Right<rcWork.Right then
      rcWork.Left:=rcApp.Right; { bar on left edge }
    if rcApp.Bottom<rcWork.Bottom then
      rcWork.Top:=rcApp.Bottom; { bar on top edge }
    if rcApp.Left>0 then
      rcWork.Right:=rcApp.Left; { bar on right edge }
    if rcApp.Top>0 then
      rcWork.Bottom:=rcApp.Top; { bar on bottom edge }
  end;

  { set workarea } 
  SystemParametersInfo (SPI_SETWORKAREA, 0, @rcWork, SPIF_SENDCHANGE );
end{ StandardArea }



ModifyWorkArea(VLeft,VTop,VRight,VBottom:integer)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure ModifyWorkArea(VLeft,VTop,VRight,VBottom:integer);
var
  rcWork: TRect;
begin
  rcWork.Top:=VTop;
  rcWork.Left:=VLeft;
  rcWork.Bottom:=GetSystemMetrics(SM_CYSCREEN)-VBottom;
  rcWork.Right:=GetSystemMetrics(SM_CXSCREEN)-VRight;
  SystemParametersInfo (SPI_SETWORKAREA, 0, @rcWork, SPIF_SENDCHANGE);
end;


ggf noch folgende Units einbinden (weiß nicht genau, ob die alle sein müssen, einfach ausprobieren)

uses
1:
2:
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,ExtCtrls,PsAPI,TLHelp32,ShellAPI,ShlObj,ActiveX;




und hier noch Tinos Beispielprogramm. Danke Tino :)