Software designers familiar with the WINDOWS operating system know that there is a taskbar (task bar) program in win95/98/nt/2000, the path is: C:\WINDOWS\SYSTEM\SYSTRAY. EXE (assuming that your WINDOWS installation is in the system default path C:\WINDOWS). From a system-functional perspective, the taskbar consists of several distinct subregions, from left to right: Start button, application switching area (application switch bar), taskbar notification section (Notification area), and taskbar clock. From a programming perspective, the Taskbar program (SYSTRAY.EXE), like other Windows applications, consists of several different forms that have information such as their respective window class names, handles, display modes, and so on.
I. Important notes
1, the taskbar, Start button window information:
Window class name for Tray bar: Shell_traywnd
Window class name for Start button: button
2, call the FindWindow function to get the taskbar window handle.
3, call the FindWindowEx function to get the Start button window handle.
4. Call the GETDC function to get the contextual relationship between the Start button device and the Desktop window.
5, Call GetDesktopWindow Desktop window handle.
6, call the GetCursorPos function to get the current mouse position.
7, call the StretchBlt function to draw the mouse background on the Start button
8. Invoke ReleaseDC Release Start button and Desktop window context relationship
Two. Examples
1, in the C + + Builder 5.0 IDE New Project Project1,project1 contains Form1, the form is shown in the following figure:
2. Define Variables
HWND wnd;
HDC hdcButton, hdcDesktop;
TPoint pt;
3, Form1 formcreate Process code is as follows
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Application->MessageBox("利用C++Builder在Windows开始按钮上绘图演示程序", "特别说明", MB_OK + MB_DEFBUTTON1);
wnd = FindWindow("Shell_TrayWnd", NULL);
wnd = FindWindowEx(wnd, 0, "Button", NULL);
hdcButton = GetDC(wnd);
wnd = GetDesktopWindow();
hdcDesktop = GetDC(wnd);
Timer1->Enabled = False;
Timer1->Interval = 1;
BitBtn1->Tag = 0;//开始绘图
}
4, Form1 Bitbtn1click Process code is as follows:
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
if (BitBtn1->Tag == 0)
Timer1->Enabled = True;
BitBtn1->Caption = "结束绘图";
BitBtn1->Tag = 1;
}
else
Close();
}
5, Form1 Timer1timer Process code is as follows:
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
GetCursorPos(&pt);
StretchBlt(hdcButton, 0, 0, 60, 25, hdcDesktop, pt.x - 30, pt.y - 12, 60, 25, SRCCOPY);
}
7, press F9 to run the program. The above procedures in the C + + Builder 5.0, windows95/98/nt/2000 Simplified Chinese version of the debugging environment.
Three. List of procedures
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package (smart_init)
#pragma resource "*.DFM"
TForm1 *form1;
HWND Wnd;
HDC Hdcbutton, Hdcdesktop;
Tpoint pt;
__fastcall Tform1::tform1 (tcomponent* owner): Tform (owner)
{
}
void __fastcall Tform1::timer1timer (tobject *sender)
{
GetCursorPos (&PT);
StretchBlt (Hdcbutton, 0, 0, N, hdcdesktop, pt.x-30, pt.y-12);
}
void __fastcall tform1::formcreate (tobject *sender)
{
Application->messagebox ("Draw demo program using C++builder on the Windows Start button", "Special note", MB_OK + mb_defbutton1);
WND = FindWindow ("Shell_traywnd", NULL);
WND = FindWindowEx (wnd, 0, "button", NULL);
Hdcbutton = GetDC (WND);
WND = GetDesktopWindow ();
Hdcdesktop = GetDC (WND);
timer1->enabled = False;
Timer1->interval = 1;
Bitbtn1->tag = 0;//Start Drawing
}
void __fastcall Tform1::bitbtn1click (tobject *sender)
{
if (Bitbtn1->tag = 0)
timer1->enabled = True;
Bitbtn1->caption = "End Drawing";
Bitbtn1->tag = 1;
Else
Close ();
}