XP任务栏结构解析

在网上看到一篇关于获取windows任务栏信息的文章,闲着没事,把代码段拷贝过来,试运行了一下,发现并没有达到预期的效果,仔细一看,代码所适用的系统为window 2000,为什么Windows XP不可以呢?
这时想到了XP与2000的任务栏可能结构不同,于是拿起了SPY++,仔细看了一下任务栏的构造:

1.整个任务栏的类名为Shell_TrayWnd
2.其下分为了三个区:开始按钮,中间任务栏和右下角任务栏:
1)开始按钮: 类名为BUTTON,标题为"开始",控件ID为0x130
2)中间任务栏:类名为ReBarWindow32,控件ID为0xA005,其下又有三个子窗口:
i.快速启动栏: 类名:ToolbarWindow32,Title:Quick Launch
ii.正在运行程序栏:类名:MSTaskSwWClass,Title:运行应用程序;再其下又有一个类名:ToolbarWindow32,Title:
运行应用程序
iii.文字输入语言栏:类名:CiceroUIWndFrame,Title:TF_FloatingLangBar_WndTitle
3.右下角任务栏:类名:TrayNotifyWnd,其下有也有三个子窗口:
1)时间显示栏:类名:TrayClockWClass,Title:当前时间如19:00
2)主要显示栏:类名:SysPager,其下有个子窗口,就是我们最常见的最小化到右下角任务栏的地方:类名:
ToolbarWindow32,Title:通知区域
3)一个button,类名:Button, 控件ID为0x5DE

好了知道了XP下任务栏每个子窗口的类名和窗口标题,就可以随心所欲地获得句柄进而操作任务栏,下面举个例子,看一下右下角任务栏每个程序图标提示的内容(从一位pscj(战神)网友提供的windows 2000下的代码修改):

这里用了MFC,所以工程设置中要Project->settings->Use MFC in a Shared dll
#include <AFX.H>
#include <COMMCTRL.H>
#include <iostream.h>
int main()
{
        HWND  hStatus=::FindWindow("Shell_TrayWnd",NULL);  //得到任务栏句柄
        if  (hStatus==NULL) 
        { 
                cout<<"Get Shell_TrayWnd error!/n"; 
                return -1; 
        } 
        HWND  hNotify=FindWindowEx(hStatus,NULL,"TrayNotifyWnd",NULL); //右下角区域
        if  (hNotify==NULL) 
        { 
                cout<<"Get TrayNotifyWnd error!/n"; 
                return -1; 
        } 
        HWND  hNotify1=FindWindowEx(hNotify,NULL,"SysPager",NULL);
        if  (hNotify==NULL) 
        { 
                cout<<"Get SysPager error!/n"; 
                return -1; 
        }
        HWND  hNotify1_0=FindWindowEx(hNotify1,NULL,"ToolBarWindow32",NULL);//右下角区域(不包括时间)
        if  (hNotify1_0==NULL)  
        { 
                cout<<"Get ToolBarWindow32 error!/n"; 
                return -1; 
        } 
        //-------------------以上是得到任务栏右下脚一块地方的句柄
        DWORD  pid = 0; 
        GetWindowThreadProcessId(hNotify1_0,&pid); 
        if  (pid==NULL) 
        { 
                cout<<"Get pid error!/n"; 
                return -1; 
        }  
       
        HANDLE  hProcess=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_ALL_ACCESS,true,pid); 
        if  (hProcess==NULL) 
        { 
                cout<<"Get hd error!/n"; 
                return -1; 
        } 
       
        int  iNum=::SendMessage(hNotify1_0,TB_BUTTONCOUNT ,NULL,NULL);  //获取任务栏上图标个数

        unsigned long n = 0; 
        TBBUTTON  *pButton = new TBBUTTON; 
        CString  strInfo = _T(""); 
        wchar_t  name[256] = {0};  
       
        TBBUTTON  BButton;
          
        for(int i=0; i<iNum; i++) 
        { 
                ::SendMessage(hNotify1_0,TB_GETBUTTON,i,(LPARAM)(&BButton)); 
                ReadProcessMemory(hProcess,&BButton,pButton,sizeof(TBBUTTON),&n);  
                if  (pButton->iString != 0xffffffff) 
                { 
                        try 
                        { 
                                ReadProcessMemory(hProcess,(void *)pButton->iString,name,255,&n); 
                        } 
                        catch(...) 
                        { 
                        }     
                        strInfo.Format("%d : %s/n",i+1,CString(name)); 
                        cout<<strInfo<<endl;
                }
        }
        delete pButton;
        return 0;
}

如果有QQ登录,则会显示出当前登录的QQ号,不清楚Q宠保姆是怎么搞的,不过这个也不失为一种方法^-^
 

评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值