• 用C++Builder在Windows开始按钮上绘图制作方法


    熟悉Windows操作系统的软件设计人员知道,在Win95/98/NT/2000中有一任务栏(Task Bar)程序,路径为:C:WINDOWSSYSTEMSYSTRAY.EXE(假设你的Windows安装在系统默认路径C:WINDOWS)。从系统功能角度分析,任务栏由几个不同的子区域组成,从左至右依次是:开始(Start)按钮、应用程序切换区(Application Switch Bar)、任务栏通知区(Notification Area)以及任务栏时钟。从程序编制角度分析,任务栏程序(SYSTRAY.EXE)与其它Windows应用程序相同,由几个不同的窗体组成,这些窗体具有各自窗口类名、句柄、显示方式等信息。  

      一.要点说明

      1、任务栏、开始按钮的窗口信息:

      ◆Tray Bar的窗口类名:Shell_TrayWnd

      开始按钮的窗口类名:Button

      2、调用FindWindow函数获得任务栏窗口句柄。

      3、调用FindWindowEx函数获得开始按钮窗口句柄。

      4、调用GetDC函数获得开始按钮设备和桌面窗口上下文关系。

      5、调用GetDeskTopWindow桌面窗口句柄。

      6、调用GetCursorPos函数获得当前鼠标位置。

      7、调用StretchBlt函数将鼠标背景绘制在开始按钮上

      8、调用ReleaseDC释放开始按钮和桌面窗口上下文关系

      二.实例

      1、在C++ Builder 5.0 IDE 中新建工程Project1Project1中包含Form1,窗体如下图所示:

      2、定义变量

      HWND wnd;

    HDC hdcButton, hdcDesktop;

    TPoint pt;

      3Form1FormCreate 过程代码如下

      void __fastcall TForm1::FormCreate(TObject *Sender)

    {

    Application->MessageBox("利用C++BuilderWindows开始按钮上绘图演示程序", "特别说明", 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;//开始绘图---www.bianceng.cn

    }

      4Form1BitBtn1Click过程代码如下:

      void __fastcall TForm1::BitBtn1Click(TObject *Sender)

    {

    if (BitBtn1->Tag == 0)

    Timer1->Enabled = True;

    BitBtn1->Caption = "结束绘图";

    BitBtn1->Tag = 1;

    }

    else

    Close();

    }

      5Form1Timer1Timer过程代码如下:

      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、按F9运行程序。以上程序在C++ Builder 5.0Windows95/98/NT/2000简体中文版环境下调试通过。

      三.程序清单

      #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, 60, 25, hdcDesktop, pt.x - 30, pt.y - 12, 60, 25, SRCCOPY);

    }

    void __fastcall TForm1::FormCreate(TObject *Sender)

    {

    Application->MessageBox("利用C++BuilderWindows开始按钮上绘图演示程序", "特别说明", 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;//开始绘图---www.bianceng.cn

    }

    void __fastcall TForm1::BitBtn1Click(TObject *Sender)

    {

    if (BitBtn1->Tag == 0)

    Timer1->Enabled = True;

    BitBtn1->Caption = "结束绘图";

    BitBtn1->Tag = 1;

    else

    Close();

    }

  • 相关阅读:
    redis之不重启,切换RDB备份到AOF备份
    redis之持久化RDB与AOF
    redis之哨兵集群
    redis之订阅功能
    redis之基础命令
    Liunx之MySQL安装与主从复制
    Python邮件发送脚本(Linux,Windows)通用
    redhat6.4 gcc g++ rpm方式安装步骤
    LVS+Keepalived+Mysql+主主数据库架构[2台]
    监控mysql状态脚本
  • 原文地址:https://www.cnblogs.com/blogpro/p/11445986.html
Copyright © 2020-2023  润新知