Full control of your Windows Desktop

Source: Internet
Author: User

Full control of your Windows Desktop
I believe you are familiar with the Windows desktop interface. Most of the screen is the desktop, and the desktop icons are arranged on it.
The taskbar is generally located under the desktop or on other desktop edges. On the far left is the "Start button", followed by the "Quick Start button" area,
The button area of the program is the taskbar icon area, on which the volume adjustment icon and Input Method adjustment icon and clock are usually displayed.
This article first describes how to hide the content described above in the taskbar. We know that the Windows API function showwindow can be used to hide or
The key is how to obtain the window handle. In Windows, each window not only has a window handle identifier window, but also has a name
The window for marking the string of the class name. If you know the class name of the window, you can use the findwindow function to obtain the window handle. Windows Desktop
Itself is a window. The desktop icon area, the taskbar, And the start button under the taskbar are all its subwindows. We can use findjavaswex
Function to find these windows. Use the showwindow function to hide or display the window. The following uses a Delphi example to demonstrate how to control the taskbar.
First, create a New Delphi project, add seven checkbox controls to form1, and 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;
Const
File: // defines the class names of different windows
Straywindow = 'Shell _ traywnd ';
Straypolicy = 'traypolicywnd ';
Sstartbutton = 'button ';
Sappswitchbar = 'rebarwindow32 ';
Sappswitch = 'mstaskswwclass ';
Sappicon = 'toolbarwindow32 ';
Strayclock = 'trayclockwclass ';
Ssf-topicon = 'shelldll _ defview ';
Sprogman = 'progman ';

VaR
Form1: tform1;
WND: integer;

Implementation

{$ R *. DFM}

Procedure tform1.formcreate (Sender: tobject );
Begin
Checkbox1.caption: = 'hide tasks ';
Checkbox1.onclick: = checkbuttonclick;
Checkbox2.caption: = 'hide start click ';
Checkbox2.onclick: = checkbuttonclick;
Checkbox3.caption: = 'hide taskbar icons ';
Checkbox3.onclick: = checkbuttonclick;
Checkbox4.caption: = 'hide program click ';
Checkbox4.onclick: = checkbuttonclick;
Checkbox5.caption: = 'hide the taskbar clock ';
Checkbox5.onclick: = checkbuttonclick;
Checkbox6.caption: = 'hide desktop icons ';
Checkbox6.onclick: = checkbuttonclick;
Checkbox7.caption: = 'hide quick running ';
Checkbox7.onclick: = checkbuttonclick;
End;

File: // click handler for seven checkbox controls
Procedure tform1.checkbuttonclick (Sender: tobject );
VaR
I: integer;
Begin
File: // find the window handle of the taskbar window
WND: = findwindow (straywindow, nil );

If (tcheckbox (sender). Name) = 'checkbox2 'then
WND: = find1_wex (WND, 0, sstartbutton, nil );

If (tcheckbox (sender). Name) = 'checkbox3 'then
WND: = find1_wex (WND, 0, stray1_y, nil );

If (tcheckbox (sender). Name) = 'checkbox4 'Then begin
WND: = find1_wex (WND, 0, sappswitchbar, nil );
WND: = find1_wex (WND, 0, sappswitch, nil );
End;

If (tcheckbox (sender). Name) = 'checkbox5' then begin
WND: = find1_wex (WND, 0, stray1_y, nil );
WND: = find1_wex (WND, 0, strayclock, nil );
End;

If (tcheckbox (sender). Name) = 'checkbox6' then begin
WND: = findwindow (sprogman, nil );
WND: = find1_wex (WND, 0, s1_topicon, nil );
End;

If (tcheckbox (sender). Name) = 'checkbox7' then begin
WND: = find1_wex (WND, 0, sappswitchbar, nil );
WND: = find1_wex (WND, 0, sappicon, nil );
End;

If tcheckbox (sender). Checked then
Showwindow (WND, sw_hide)
Else
Showwindow (WND, sw_show );
End;
End.

Run the program and click different selection boxes to hide different parts of the task bar or task bar.

Next we will introduce how to manipulate the desktop icon. Set the background and color of the icon text and set the arrangement of icons. Through the above introduction
As we know above, Windows desktop is also a window, but it is a listview window.
For a series of messages starting with LVM _, you can use the Windows API function sendmessage to send these messages to the listview window.
In Delphi, there are also a series of functions starting with listview _. These functions can replace LVM _ class messages.
An example is as follows: first create a New Delphi project, add two commandbutton controls to form1, and then
Add the following code to 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: = find1_wex (window, hwnd (NiL), 'shelldll _ defview ','');
File: // find the listview window where the desktop icon is placed
Window: = find1_wex (window, hwnd (NiL), 'syslistview32 ','');

If trans then file: // set the transparent text background color
Listview_settextbkcolor (window, $ ffffffff) // back color
Else file: // set the opaque text background color
Listview_settextbkcolor (window, background); // back color

Listview_settextcolor (window, forground); // foreground color
File: // redraw the desktop icon
Listview_redrawitems (window, 0, listview_getitemcount (window)-1 );
Updatewindow (window); file: // redraw the window
End;

Procedure setdesktopiconarr (iwidth, iheight: integer );
VaR
Window: hwnd;
I, i1, I2, icount: integer;
Begin
Window: = findwindow ('progman ', 'program manager ');
Window: = find1_wex (window, hwnd (NiL), 'shelldll _ defview ','');
Window: = find1_wex (window, hwnd (NiL), 'syslistview32 ','');

File: // set the distance between the icon and the border.
I1: = 20; I2: = 20;

File: // obtain the number of desktop icons
Icount: = listview_getitemcount (window)-1;
For I: = 0 to icount do begin
File: // set the 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 );
End;

Procedure setdefaulticoncolors;
VaR
Kind: integer;
Color: tcolor;
Begin
Kind: = color_desktop;
Color: = getsyscolor (color_desktop );
Setsyscolors (1, kind, color );
End;

Procedure tform1.button1click (Sender: tobject );
Begin
File: // you can change clwhite and clblack to another color value.
File: // Changes in the color of the icon text
Setdesktopiconcolor (clwhite, clblack, true );
End;

Procedure tform1.button2click (Sender: tobject );
Begin
File: // set the spacing of the icon to 100 pixels.
Setmediatopiconarr (100,100 );
End;

Procedure tform1.formcreate (Sender: tobject );
Begin
Button1.caption: = 'set the icon text color ';
Button2.caption: = 'set icon arrangement ';
End;

End.

In the preceding procedure, the setmediatopiconcolor function sets the foreground color, background color, and transparency of the icon text. The foreground Parameter
Background specifies the foreground color and background color of the text, and the parameter trans specifies whether the text background is transparent (if there is a background pattern ).
The setmediatopiconarr function is used to arrange the desktop icons. The iwidth and iheight parameters respectively specify the horizontal vertical distance between icons. If you want
If the setmediatopiconarr function takes effect, you need to remove the automatic arrangement option of the desktop icons. In addition, the listview class has other control messages.
You can use these messages to control more desktop icon options. If you are interested, you can check the msdn library.
The above program is compiled by delphi5 and runs under Windows98 Windows2000.

 

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.