Fully control your Windows desktop

zhaozj2021-02-08  273

Fully control your Windows desktop for Windows desktop interface. I believe everyone is already very familiar, occupying a large number of screens, is the desktop icon in the above. The taskbar is usually located below the desktop or other edges on the desktop. At the left side is the "Start button", next is the "Quick Start button" area, the program button area, then it is the taskbar icon area, which generally has volume adjustment icons and input method adjustment icons and clocks. This article first describes how to hide the part described above in the taskbar. We know that using Windows API functions showWindow can hide or display the window, how is the key to get the handle of the window. Each window under Windows has no one window handle marking window, but also a string tag window called class name. If you know the class name of the window, you can get the handle of the window via the FindWindow function. The Windows desktop itself is a window, desktop icon, taskbar, and start button under the taskbar, etc. are all its sub-windows. We can look for these windows through the FindWindowEx function. Use the ShowWindow function to hide or display the window. The following is to demonstrate how to control the taskbar through a Delphi example. First create a new Delphi project, then add 7 CheckBox controls in Form1, then add the following code to Form1:

Unit unit1;

Interface

Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;

type TForm1 = class (TForm) CheckBox1: TCheckBox; CheckBox2: TCheckBox; CheckBox3: TCheckBox; CheckBox4: TCheckBox; CheckBox5: TCheckBox; CheckBox6: TCheckBox; CheckBox7: TCheckBox; procedure FormCreate (Sender: TObject); private procedure CheckButtonClick (Sender: TObject ); {Private declarations} public {public declarations} end; Constfile: // class name defined in a different window sTrayWindow = 'Shell_TrayWnd'; sTrayNotify = 'TrayNotifyWnd'; sStartButton = 'Button'; sAppSwitchBar = 'ReBarWindow32'; sAppSwitch = ' MStaskswwclass'; sappicon = 'ToolbarWindow32'; streyclock = 'trayclockwclass'; sdesktopicon =' shelldll_defview '; sprogman =' progman ';

Var Form1: TFORM1; WND: Integer;

IMPLEMENTATION

{$ R * .dfm}

procedure TForm1.FormCreate (Sender: TObject); begin CheckBox1.Caption: = 'hide the taskbar'; CheckBox1.OnClick: = CheckButtonClick; CheckBox2.Caption: = 'hide the Start button'; CheckBox2.OnClick: = CheckButtonClick; CheckBox3.Caption : = 'hide the taskbar icon'; CheckBox3.OnClick: = CheckButtonClick; CheckBox4.Caption: = 'hidden program button'; CheckBox4.OnClick: = CheckButtonClick; CheckBox5.Caption: = 'hide the taskbar clock'; CheckBox5.OnClick: = CheckButtonClick; CheckBox6.Caption: = 'hide desktop icons'; CheckBox6.OnClick: = CheckButtonClick; CheckBox7.Caption: = 'hide icon to run fast'; CheckBox7.OnClick: = CheckButtonClick; end; file: // 7 Ge CheckBox control Click Processing Function Procedure TFORM1.CHECKBUTTONCLICK (Sender: TOBJECT); VAR i: integer; begin file: // Find the window handle of the taskbar window WND: = FindWindow (streywindow, nil);

IF (Tcheckbox (Sender) .Name) = 'Checkbox2' Then Wnd: = FindWindowEx (WND, 0, SSTARTBUTTON, NIL);

IF (tcheckbox (sender) .name) = 'Checkbox3' Then Wnd: = FindWindowEx (WND, 0, Straynotify, NIL);

IF (tcheckbox (sender) .name) = 'checkbox4' Then Begin Wnd: = FindWindowEx (WND, 0, SAPPSWITCHBAR, NIL); WND: = FINDWINDOWEX (WND, 0, SAPPSWITCH, NIL);

IF (tcheckbox (sender) .name) = 'checkbox5' Ten begin wnd: = FindWindowEx (WND, 0, Straynotify, NIL); WND: = FINDWINDOWEX (WND, 0, Strayclock, NIL);

IF (tcheckbox (sender) .name) = 'Checkbox6' Then Begin Wnd: = FINDWINDOW (Sprogman, NIL); WND: = FindWindowEx (WND, 0, SDESKTOPICON, NIL);

IF (Tcheckbox (Sender) .name) = 'CheckBox7' Ten Begin Wnd: = FindWindowEx (WND, 0, Sappswitchbar, NIL); WND: = FindWindowEx (WND, 0, SAPPICON, NIL); End; IF Tcheckbox (Sender) .Checked the showwindow (wnd, sw_hide) Else showWindow (WND, SW_SHOW); END; END.

Run the program, click on different selection boxes, you can hide different parts on the task bar or taskbar.

Let's take a look at how to manipulate the desktop icon. Set the background and colors of the icon text and the arrangement of the icon. With the above introduction, we know that Windows desktop is also a window, different it is a listView class window, for the ListView class window, a series of messages starting with LVM_, send these to the listView class window via the Windows API function sendMessage The message can control some properties of the window, and there is a series of functions starting with ListView_ in Delphi, which can replace the LVM_ class message. The specific examples are as follows: First create a new Delphi project, then join two CommandButton controls in Form1, then add the following code in Form1: Unit Unit1;

Interface

Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Comctrls, Stdctrls, CommCtrl

type TForm1 = class (TForm) Button1: TButton; Button2: TButton; procedure Button1Click (Sender: TObject); procedure Button2Click (Sender: TObject); procedure FormCreate (Sender: TObject); private {Private declarations} public {Public declarations} end ;

Var Form1: TFORM1;

IMPLEMENTATION

{$ R * .DFM} procedure SetDesktopIconColor (Forground, Background: TColor; Trans: Boolean); var Window: HWND; begin Window: = FindWindow ( 'Progman', 'Program Manager'); file: // find the desktop window Window : = FindWindowEx (Window, HWnd (nil), 'shelldll_defview', ''); File: // List the listview window for placing desktop icons Window: = FindWindowEx, 'syslistView32', '';

if Trans then file: // set transparent text background color ListView_SetTextBkColor (Window, $ ffffffff) // back color else file: // set the opacity of the text background color ListView_SetTextBkColor (Window, Background); // back colorListView_SetTextColor (Window, Forground ); //, re-draws desktop icon ListView_redrawitems (Window, 0, ListView_GetItemcount (Window) - 1); UpdateWindow (Window); file: // Redraw window END;

procedure SetDeskTopIconArr (iWidth, iHeight: Integer); var Window: HWND; i, i1, i2, iCount: integer; begin Window: = FindWindow ( 'Progman', 'Program Manager'); Window: = FindWindowEx (Window, HWND ( NIL), 'shelldll_defview', ''); Window: = FindWindowEx (Window, HWnd (nil), 'syslistView32', '');

File: // Set the distance between the icon and the boundary. I1: = 20; I2: = 20;

File: // Number ICount: = ListView_GetItemcount (Window) -1; for i: = 0 to iCount Do Begin File: // Set Icon Position ListView_SetItemPosition (Window, I, I1, I2); I1: = I1 iWidth; IF I1> (Screen.width-32) THEN BEGIN I1: = 20; I2: = I2 IHEIGHT; End; End; ListView_redRawitems (Window, 0, ListView_GetItemcount (Window) - 1); UpdateWindow (Window) ;

Procedure setdefault; var kind: integer; color: tcolor; begin kind: = color_desktop; color: = getSyscolor (color_desktop); setsyscolors (1, kind, color);

Procedure TForm1.Button1Click (Sender: TOBJECT); Begin File: // You can change CLWHITE, CLBLACK to see file: // icon text color change setDesktopiconcolor (CLWHITE, CLBLACK, TRUE);

Procedure TForm1.Button2Click (Sender: TOBJECT); becom file: // Set the pitch of the icon to 100 pixels setdesktopiconarr (100, 100);

Procedure TForm1.FormCreate (Sender: TOBJECT); begin button1.caption: = 'Sets the icon text color'; button2.caption: = 'Settings icon arranging'; end; end;

In the above program, the function setDesktopiconcolor sets the foreground color, background color and transparency of the icon text, and the parameter ForegroundbackGround specifies the foreground and background colors of the text, and the parameter TRANS specifies whether the background of the text is transparent (if there is a background pattern). Function SetDesktopiconarr Arranges Desktop Icons, Parameters iWidth, Iheight The horizontal longitudinal distance between icons, respectively. If you want the SetDesktopiconarr function to take effect, you need to remove the automatic arrangement of the desktop icon. In addition, the ListView class also has other control messages to utilize these messages to control more desktop icon options. Interested friends can check the MSDN library. The above programs are written by Delphi5, running in Windows98 Windows 2000.

转载请注明原文地址:https://www.9cbs.com/read-1189.html

New Post(0)