[Delphi Technology] Hide/show taskbar-Program not on task display-Full Control of Windows taskbar

Source: Internet
Author: User

1. Hide the task bar

var H:thandle; Variable
H:=findwindow (' Shell_traywnd ', nil);
ShowWindow (H,sw_hide);


2. Display the task bar
H:=findwindow (' Shell_traywnd ', nil);
ShowWindow (h,sw_show);

3. How to invoke the API function in Delphi so that the task is not displayed in the taskbar

SetWindowLong (Application.handle,gwl_exstyle,ws_ex_toolwindow);

ShowWindow (Application.handle, sw_hide);

PS. How do I find a handle to the taskbar in Delphi?
Htray:=findwindow (' Shell_traywnd ', nil);

ShowWindow (Htray,sw_hide);

As for the class name Shell_trawnd, to use the tool to find faster, Delphi installed will have a win32sight, you can find the desktop, taskbar, any application form the class name.


4. Automatically hide taskbar and uncheck Auto hide taskbar (hide and Auto hide different auto hide is hidden when the mouse is left, display when entering)
Need to take advantage of an API function: SHAppBarMessage
Winshellapi UINT apientry shappbarmessage (DWORD dwmessage,pappbardata pData);
Appbardata Structural Body

example:
1, set the taskbar to auto-hide or suppress auto-hide
Procedure Tform1.autohidetaskbar (Bhide:bool);
Const ABM_SETSTATE =; //0x0000000a  required because it does not exist in Delphi;
var
    Apbar: Appbardata;
Begin
    apbar.cbsize: = sizeof (Apbar);
    Apbar.hwnd: = FindWindow (' Shell_traywnd ', nil);
    if  apbar.hwnd >0  then
    begin
         if (bhide = TRUE) then
            Apbar.lparam: = abs_autohide//auto-hide
       else
             Apbar.lparam: = Abs_alwaysontop; Suppress auto-hide
       shappbarmessage (abm_setstate, Apbar);//set taskbar auto-Hide
     end;
End;

Call: Autohidetaskbar (True);  Set to Auto-hide or Autohidetaskbar (False); Suppress Auto-hide
Note: Delphi's dwmessage parameter does not exist in the abm_setstate, while the Windows API exists, its value is 0x0000000a;
So set the abm_setstate here and pass in. Direct use of Abm_setautohidebar instead of abm_setstate is not working.

2. Determine if the taskbar is automatically hidden
function TForm1.IsTaskbarAutoHideOn:boolean;
Var
Abdata:tappbardata;
Begin
Abdata.cbsize: = sizeof (ABData);
Result: = (SHAppBarMessage (abm_getstate, ABData) and abs_autohide) > 0;
End

Third, the API function SHAppBarMessage Description:
Winshellapi UINT apientry SHAppBarMessage (
DWORD dwmessage,//message name
Pappbardata PDATA//appbardata Structure pointer
); parameter description:
Dwmessage can be the following parameters
Abm_activate notification System A APPBAR has been activated;
Abm_getautohidebar retrieving the AppBar of the screen edge
Abm_getstate retrieving the status of the top-level Microsoft Windows taskbar
Abm_gettaskbarpos retrieving the bounding rectangle of the Windows taskbar
Abm_new register a new AppBar, the system sends a message to AppBar
Abm_querypos appbar size and screen position
Abm_remove unregister a appbar and move out of the system internal list
Abm_setautohidebar Register or unregister the auto-hide AppBar at the edge of the screen
Abm_setpos Setting the size and screen position of the AppBar
Abm_setstate set AppBar to the top level, set the status in Delphi No
Abm_windowposchanged sends a message to the system when the AppBar state sends a change
PData a appbardata structural body
Appbardata structure, structure and parameter description:
typedef struct _APPBARDATA {//ABD
DWORD cbsize; sizeof (Appbardata)
HWND hwnd; Handle of AppBar task bar handles,
UINT Ucallbackmessage; See below callback pointers
UINT Uedge; See below edge position s
RECT RC; See below rectangular area
LPARAM LPARAM; See below status
Abs_autohide; Auto-hide abs_alwaysontop;//suppress auto-hide
} appbardata, *pappbardata;


2.================================================================


1. Programming Ideas
(1) The window information for the taskbar form is:
① the window class name for the taskbar is: Shelltraywnd. The window class name for the
② Start button is: button. The window class name for the
③ application switch area is: ReBarWindow32. The window class name for the
④ taskbar notification area is: Traynotifywnd. The window class name for the
⑤ task bar clock is: Trayclockwclass.
(2) calls the FindWindow function to get the window handle to the taskbar. 
(3) calls the FindWindowEx function to get the window handle of each child area of the taskbar.
(4) Depending on the window handle, call the ShowWindow function to control the area of the taskbar to show or hide (show/hide), call the En ablewindow function to control the taskbar is valid or invalid (enabled/disabled).
2. Programming Methods
(1) Create a new project Project1 in the Delphi3.0 IDE, Project1 contains Form1, as shown in the form:
(2) Defines the window handle array: Wnd: Array[0. 4] of Thandle; The
(3) Gethandles procedure Code is as follows:

procedure Tform1.gethandles;
Begin
//Get the window handle of tray bar;
Wnd[0]:=findwindow (′shelltraywnd′,nil);
//Get the window handle of the Start button;
wnd[1]:= FindWindow (′shelltraywnd′,nil);
Wnd[1]:=findwindowex (Wnd[1],hwnd (0), ′button′,nil);//Get the window handle of the application switch area;
Wnd[2]:=findwindow (′shelltraywnd′, NIL);
Wnd[2]]:=findwindowex (Wnd[2],hwnd (0), ′rebarwindow32′,nil); 
//Get the window handle of the notification area of the taskbar;
Wnd[3]:=findwindow (′shelltraywnd′,nil);
Wnd[3]:=findwindowex (Wnd[3],hwnd (0), ′traynotifywnd′,nil); 
//Get the window handle of the taskbar clock;
Wnd[4]:=findwindow (′shelltraywnd′,nil);
Wnd[4]:=findwindowex (Wnd[4],hwnd (0), ′traynotifywnd′,nil);
Wnd[4]:=findwindowex (Wnd[4],hwnd (0), ′trayclockwclass′,nil);
End;


(4) The enableordisable process code is as follows:

Procedure tform1.enableordisable (Sender:tobject);
Begin
Gethandles;
If Tcheckbox (Sender). Checked Then
Case Tcheckbox (Sender). Tag of
0:enablewindow (Wnd[0], False);
1:enablewindow (wnd[1], False);
2:enablewindow (wnd[2], False);
3:enablewindow (Wnd[3], False);
4:enablewindow (Wnd[4], False);
End
Else
Case Tcheckbox (Sender). Tag of
0:enablewindow (Wnd[0], True);
1:enablewindow (wnd[1], True);
2:enablewindow (wnd[2], True);
3:enablewindow (Wnd[3], True);
4:enablewindow (Wnd[4], True);
End
End


(5) The Hideorshow process code is as follows:

Procedure Tform1.hideorshow (Sender:tobject);
Begin
Gethandles;
If Tcheckbox (Sender). Checked Then
Case Tcheckbox (Sender). Tag of
0:showwindow (Wnd[0],swhide);
1:showwindow (Wnd[1],swhide);
2:showwindow (Wnd[2],swhide);
3:showwindow (Wnd[3],swhide);
4:showwindow (Wnd[4],swhide);
End
Else
Case Tcheckbox (Sender). Tag of
0:showwindow (wnd[0],swshow);
1:showwindow (wnd[1],swshow);
2:showwindow (wnd[2],swshow);
3:showwindow (wnd[3],swshow);
4:showwindow (wnd[4],swshow);
End
End


(6) The Formclose event code is as follows://Restore the Windows taskbar to its normal state;

Procedure Tform1.formclose (Sender:tobject; var action:tcloseaction);
var I:integer;
Begin
For i:=0 to 4 do
Begin
EnableWindow (wnd[i],true);
ShowWindow (wnd[i],swshow);
End
End


(7) Press F9 to run the program. The above procedures in delphi3.0/4.0, windows95/98 Simplified Chinese version of the environment to debug.
(8) Description: The method described in this article is also applicable to VB, VC, BC, C++builder and other programming tools, but should pay attention to the syntax, variable types and other requirements.

[Delphi Technology] Hide/show taskbar-Program not on task display-Full Control of Windows taskbar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.