这篇文章主要介绍了你呢通过托盘图标得到该所属进程的实现代码,为了方便大家使用特将多个代码分享给大家,需要的朋友可以参考下
目录
代码一代码二代码三代码四代码五代码六本例以获取程序托盘图标位置为例
//根据需要还可以获取不少信息
代码一
//获取托盘区域数据
RECT CTray:GetTrayRect()
{
rect={ 0 };
hWnd=零;
hwnd=find traynd();
如果(hWnd!=空)
{
如果(!enumnotfywindow(rect,hWnd))//如果没在普通托盘区
{
hwnd=find notify conoverflow window();//在溢出区(win7)
如果(hWnd!=空)
{
enumnotifywindow(矩形、hwnd);
}
}
}
返回直线;
}
//枚举获取托盘区域位置
bool ctray:enumnotfywindow(rect,HWND)
{
//rect={ 0 };
bool bSuc=false:
无符号长ln PID=0;
长ret=0.lng buttons=0
长LNG dr=0.lng=0/、lngtextadr、lngbuttonid
hpprocesshandle=null
LPVOID lngAddress=NULL,lngrect=null
如果(hWnd!=空)
{
ret=getwindowthreads processid(hwnd,lnpid);
如果(后悔!=0 lngPID!=0)
{
HP process=open process(process _ all _ access | process _ VM _ operation | process _ VM _ read | process _ VM _ write,0 . lnpid);//
如果(hpprocess!=空)
{
ln address=virtualallcex(HP process,0.0x 4096,MEM _提交,页面_读写);
lnrect=virtualallcex(hpprocess,0,sizeof(RECT),MEM _提交,页面_读写);
lngButtons=SendMessage(hWnd,TB_BUTTONCOUNT,0.0);//发送消息获取托盘按钮(按钮)数量
如果(lngAddress!=零英格丽特。=空)
{
for(int I=0);我是英格巴顿:(一)
{
直线RC={ 0 };
int j=I;
ret=SendMessage(hWnd、TB_GETBUTTON、j、long(LNG地址));//发送消息获取托盘项数据起始地址
ret=read process memory(HP process,LP void(long(lngadress)12),LNG dr,4.0);
如果(后悔!0英格达博士!=(1)
{
ret=read process memory(HP process,lpvoid(lnhwinddr),lnghwnd,4.0);//获取句柄
如果(后悔!=0 (HWND)英格朗===m _ notionconduita。hwnd/)
{
ret=:SendMessage(hWnd,TB_GETITEMRECT,(WPARAM)j,(LPAR)lnrect);//发送消息获取托盘项区域数据
ret=read process memory(HP process,lngrect,rc,sizeof(rc),0);//读取托盘区域数据
如果(后悔!=0)
{
cwnd:from handle(hwnd)-customer to screen(RC);
rect=rc
}
bSuc=true://在普通托盘区找到,在溢出区不再查找
打断;打断;
}
}
}
}
如果(lngAddress!=空)
{
virtualfreeex(hpprocess、lngaddress、0x4096、mem _ de commit);
virtualfreeex(hpprocess、lngaddress、0、mem _ release);
}
如果(lngRect!=空)
{
virtualfreeex(hpprocess、lngrect、sizeof(RECT)、mem _ de commit);
virtualfreeex(hpprocess、lngrect、0、mem _ release);
}
封闭式处理(HP process);
}
}
}
返回bsuc
}
//获取普通托盘区窗口句柄
hwnd ctray:findtraynd()
{
hWnd=零;
hwndpaper=null
if((hwnd=findwindow(_ t( shell _ tray ynd ,NULL))!=空)
{
if ((hWnd=FindWindowEx,0,_T(TrayNotifyWnd ,NULL))!=空)
{
hwndpur=findwindowex(hwnd,0,_ t( syspmanager ,null);
如果(!hwndpaper)
hWnd=FindWindowEx(hWnd,0,_T(ToolbarWindow32 ),空值;
其他语句
hwnd=findwindowex(hwndopener,0,_T(ToolbarWindow32 ),空值;
}
}
返回hwnd
}
//获取溢出托盘区窗口句柄
hwnd ctray:findnotfyconoverflow窗口()
{
hWnd=零;
hwnd=findwindow(_ t( notify conoverflow window ),空值;
如果(hWnd!=空)
{
hWnd=FindWindowEx(hWnd,NULL,_T(ToolbarWindow32 ),NULL);
}
返回hwnd
}
以下代码网上收集的,变量初始化指针句柄及函数是否成功都没判定
//需要的自己加下判定,有时间再改了
代码二
结构跟踪数据
{
温温温;
UINT uID:
UINT uCallbackMessage:
DWORD保留[2];
我们做到了:
}:
请参阅CTray:GetTrayRect()
{
温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温温。
未签署长lngpid
长长的遗憾,英格巴顿;
处理h过程
lpvoid lngaddress
长英文字博士、英文字博士、英文字博士、英文字博士、英文字博士;
S7-1200可编程控制器:
tray data={ 0 };
TB button BTN data={ 0 };
hwnd=查找窗口(_ t( shell _ tray ynd ),空值;
hWnd=FindWindowEx(hWnd,0,_T(TrayNotifyWnd ),空值;
hwndpur=findwindowex(hwnd,0,_ t( syspmanager ,null);
如果(!hwndpaper)
hWnd=FindWindowEx(hWnd,0,_T(ToolbarWindow32 ),空值;
其他语句
hwnd=findwindowex(hwndopener,0,_T(ToolbarWindow32 ),空值;
ret=getwindowthreads processid(hwnd,lnpid);
HP process=open process(process _ all _ access | process _ VM _ operation | process _ VM _ read | process _ VM _ write,0 . lnpid);
ln address=virtualallcex(HP process,0.0x 4096,MEM _提交,页面_读写);
lngButtons=SendMessage(hWnd,TB_BUTTONCOUNT,0.0);
罗马天主教矩形;点点;
lpvoid lnrect=virtualallcex(HP process,0,sizeof(RECT),MEM _提交,页面_读写);
直线裂纹;
for(int I=0);我是英格巴顿:(一)
{
int j=I;
ret=SendMessage(hWnd、TB_GETBUTTON、j、long(LNG地址));
ret=read process memory(HP process,LP void(long(lngadress)16),lngtextadr,4.0);
if(lntextdr!=(1)
{
ret=read process memory(HP process,lpvoid(lntextdr),strBuff,1024.0);
//ret=read process memory(HP process,LP void(long(lngadress)12),lnghwndadr,4.0);//获取句柄
//ret=read process memory(HP process,lpvoid(lnhwdr),lnghwnd,4.0);
//ret=read process memory(HP process,lpvoid(long(lnaddress)4),lngbuttonid,4.0);//获取按钮ID(按钮ID)
c环str(str buf);
如果(字符串.比较(m _通知县。SZ tip)==0)
{
* SendMessage(hWnd,TB_GETITEMRECT,(WPARAM)j,(LPAR)lnrect);
readprocessmemory(hpprocess,lngrect,rc,sizeof(rc),0);//获取托盘图标区域
cwnd:from handle(hwnd)-customer to screen(RC);
}
//以下是隐藏托盘图标
//
//如果(显示)
//
//SendMessage(hWnd,TB_HIDEBUTTON,lngbuttonid,0);
//}
//否则
//
//SendMessage(hWnd,TB_HIDEBUTTON,lngbuttonid,1);
//}
//}
}
}
virtualfreeex(hpprocess、lngaddress、0x4096、mem _ de commit);
virtualfreeex(hpprocess、lngaddress、0、mem _ release);
virtualfreeex(hpprocess、lngrect、sizeof(RECT)、mem _ de commit);
virtualfreeex(hpprocess、lngrect、0、mem _ release);
封闭式处理(HP process);
}
代码三
请参阅startstorm()
{
hwnd hmain=find window( animated _ layered _ window _ class ,暴风媒体中心);
if ( hMain)
{
ShowWindow(hMain,SW_HIDE):
}
//得到工具栏句柄
hwnd htray=find window( shell _ tray ynd ,null);
hTray=FindWindowEx(hTray,0, TrayNotifyWnd ,null);
hTray=FindWindowEx(hTray,0, syspager ,null);
hTray=FindWindowEx(hTray,0, ToolbarWindow32 ,null);
//获取探索一下进程身份证明号
S7-1200可编程控制器:
getwindow threads processid(htray,traypid);
//打开进程并且开辟进程空间
矩形矩形;
TBBUTTON tb
TBBUTTON pTb
LPVOID lpAddr
DWORD dwThreadIdOfICO
寻找风暴(风暴托盘。exe’);//你要点击的进程的PID
TRAYDATA traydata
HANDLE hOpen=open PROCESS(PROCESS _ ALL _ ACCESS,FALSE,TrayPid);
lpAddr=VirtualAllocEx(hOpen,NULL,sizeof(tb) sizeof(rect),MEM _提交,页面_读写);
int nCount=SendMessage(hTray,TB_BUTTONCOUNT,0,0);
int I;
DWORD dwOutWrite
for(I=0;我不算;我)
{
ZeroMemory(tb,sizeof(TB));
ZeroMemory(rect,sizeof(rect));
//把参数写进目标进程
WriteProcessMemory(hOpen,lpAddr,tb,sizeof(tb),dwOutWrite);
//WriteProcessMemory(hOpen,(LP void)((DWORD)LP addr sizeof(pTb))、rect、sizeof(rect)、dwOutWrite);
//获取按钮
SendMessage(hTray,TB_GETBUTTON,I,LPARAM(LP addr));
//读取TBBUTTON结构
ReadProcessMemory(hOpen,lpAddr,pTb,sizeof(TBBUTTON),dwOutWrite);
//读取TRAYDATA结构
ReadProcessMemory(hOpen,(LPVOID)pTb.dwData,traydata,sizeof(TRAYDATA),dw out write);
GetWindowThreadProcessId(托盘数据。hwnd,dwThreadIdOfICO);
if ( dwThreadIdOfICO==dwTempId)
{
//获取图标的矩形
LP void LP=(LP void)((DWORD)LP addr sizeof(pTb));
SendMessage(hTray,TB_GETITEMRECT,I,(LPARAM)LP);
LP void LP data=(LP void)((DWORD)LP addr sizeof(TB button));
ReadProcessMemory(hOpen,lpdata,rect,sizeof(rect),dwOutWrite);
int iGap=rect.right/2;//得到图标的中间坐标的间隔
//点击
SendMessage(hTray,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(rect.right - iGap,rect。bottom-iGap));
SendMessage(hTray,WM_LBUTTONUP,0,MAKELPARAM(rect.right - iGap,rect。bottom-iGap));
//
关闭手柄(hOpen);
打破;
}
}
}
win7有一个溢出托盘区:以下是隐藏在托盘区中的托盘信息,用以上的方法找不到,因为在NotifyIconOverflowWindow里
FH wnd=FindWindow( notifyicon overflow window ,NULL)
参考文章:http://话题。csdn。net/u/2010 10 03/23/859851 ee-5aa 1-4476-8ce 1-1359826 df2b 0。超文本标记语言
代码四
#include stdafx.h
#包含afx.h
#包含区域设置。h
#包含字符串
使用命名空间标准
typedef BOOL(WINAPI * LPFN _ is wow 64进程)(HANDLE,PBOOL);
BOOL IsWow64()
{
BOOL bIsWow64=FALSE
LPFN _ is wow 64进程
fnis wow 64 process=(LPFN _ is wow 64 process)GetProcAddress(
GetModuleHandle(_T(kernel32 ),是wow 64进程);
if (NULL!=fnIsWow64Process)
{
如果(!fnis wow 64进程(GetCurrentProcess()、bIsWow64))
{
//处理错误
}
}
返回bIsWow64
}
HWND FindTrayWnd()
{
HWND hWnd=空
hWnd=FindWindow(_ T( Shell _ tray wnd ),NULL);
hWnd=FindWindowEx(hWnd,NULL,_T(TrayNotifyWnd ),NULL);
hWnd=FindWindowEx(hWnd,NULL,_T(SysPager ),NULL);
hWnd=FindWindowEx(hWnd,NULL,_T(ToolbarWindow32 ),NULL);
返回hWnd
}
HWND findnotifyiconoverflow窗口()
{
HWND hWnd=空
hWnd=FindWindow(_ T( notifyicon overflow window ),NULL);
hWnd=FindWindowEx(hWnd,NULL,_T(ToolbarWindow32 ),NULL);
返回hWnd
}
void EnumNotifyWindow
{
DWORD dwProcessId=0;
GetWindowThreadProcessId(hWnd,dwProcessId);
HANDLE h PROCESS=open PROCESS(PROCESS _ VM _ OPERATION | PROCESS _ VM _ READ | PROCESS _ VM _ WRITE,FALSE,dwProcessId);
if ( hProcess==NULL ){
返回;
}
LPVOID lAddress=virtualallocx(h process,0,4096,MEM _提交,页面_读写);
if ( lAddress==NULL ){
返回;
}
DWORD lTextAdr=0;
字节缓冲区[1024]={ 0 };
CString strFilePath
CString结构
HWND hMainWnd=NULL
INT nDataOffset=sizeof(TB button)-sizeof(INT _ PTR)-sizeof(DWORD _ PTR);
int nStrOffset=18
if ( IsWow64() ){
nDataOffset=4;
nstr offset=6;
}
//得到圖標個數
int lButton=SendMessage(hWnd,TB_BUTTONCOUNT,0,0);
for(int I=0;i lButtoni ) {
SendMessage(hWnd,TB_GETBUTTON,I,(LPARAM)lAddress);
//讀文本地址
ReadProcessMemory(hProcess,(LP void)((DWORD)lAddress nDataOffset),lTextAdr,4,0);
if ( lTextAdr!=-1 ) {
//讀文本
ReadProcessMemory(hProcess,(LPCVOID)lTextAdr,buff,1024,0);
hMainWnd=(HWND)(*((DWORD *)buff));
strfile path=(WCHAR *)buff nstr offset;
strTile=(WCHAR *)buff nstr offset MAX _ PATH;
_tprintf(_T(%s %sn ),strfile,str file path);
}
}
VirtualFreeEx(hProcess,lAddress,4096,MEM _ RELEASE);
关闭手柄(h过程);
}
int _tmain(int argc,_TCHAR* argv[])
{
setlocale(LC_ALL, CHS );
EnumNotifyWindow(FindTrayWnd());
_ tprintf(_ T( n ));
EnumNotifyWindow(findnotifyicon overflow window());
系统("暂停");
返回0;
}
代码五
void CTrayDlg:OnButton1()
{
//TODO:在此添加控件通知处理程序代码
HWND wd=:FindWindow( Shell _ tray wnd ,NULL);
if (wd==NULL)
{
MessageBox("错误1 ");
返回;
}
HWND wtd=FindWindowEx(wd,NULL, TrayNotifyWnd ,NULL);
if (wtd==NULL)
{
MessageBox("错误2 ");
返回;
}
HWND wd1=FindWindowEx(wtd,NULL, ToolbarWindow32 ,NULL);
if (wd1==NULL)
{
MessageBox("错误3 ");
返回;
}
双字pid
PID=0;
GetWindowThreadProcessId(wd1,PID);
if (pid==NULL)
{
MessageBox("错误4 ");
返回;
}
HANDLE HD=open PROCESS(PROCESS _ QUERY _ INFORMATION PROCESS _ ALL _ ACCESS,true,PID);
if (hd==NULL)
{
MessageBox("错误6 ");
返回;
}
int num=:SendMessage(wd1,TB_BUTTONCOUNT,NULL,NULL);
int I;
无符号长n;
TBBUTTON p,* pp
CString x;
wchar _ t name[256];
无符号长whd,proid
CString温度;
TBBUTTON * sp
sp=(TB button *)0x 20f 00;//这里应该改成用虚拟分配分配内存否则有可能出错,不过人懒,就先这么着吧
for(I=0;inum我)
{
* SendMessage(wd1,TB_GETBUTTON,I,(LPARAM)sp);
PP=p;
ReadProcessMemory(hd,sp,pp,sizeof(p),n);
//x.Format(%x %x %x %x %x %x ,p.iBitmap,p.idCommand,p.fsState,p.fsStyle,p.dwData,p . I string);
name[0]=0;
如果(p正在运行!=0xffffffff)
{
尝试
{
ReadProcessMemory(hd,(void *)p.iString,name,255,n);
name[n]=0;
}
catch()
{
}
//x=" ";
//x=name;
temp=name
尝试
{
whd=0;
ReadProcessMemory(hd,(void *)p.dwData,whd,4,n);
}
catch()
{
}
proid=0;
GetWindowThreadProcessId((HWND)whd,proid);
x.格式(位置=%d名称=%s窗口句柄=x进程ID=x,
I,(LPCTSTR )temp,whd,proid);
m_list .AddString(x);
}
}
}
代码六
void CTrayDlg:OnButton1()
{
//TODO:在此添加控件通知处理程序代码
HWND wd=:FindWindow( Shell _ tray wnd ,NULL);
if (wd==NULL)
{
MessageBox("错误1 ");
返回;
}
HWND wtd=FindWindowEx(wd,NULL, TrayNotifyWnd ,NULL);
if (wtd==NULL)
{
MessageBox("错误2 ");
返回;
}
HWND wd1=FindWindowEx(wtd,NULL, ToolbarWindow32 ,NULL);
if (wd1==NULL)
{
MessageBox("错误3 ");
返回;
}
双字pid
PID=0;
GetWindowThreadProcessId(wd1,PID);
if (pid==NULL)
{
MessageBox("错误4 ");
返回;
}
HANDLE HD=open PROCESS(PROCESS _ QUERY _ INFORMATION | PROCESS _ ALL _ ACCESS,true,PID);
if (hd==NULL)
{
MessageBox("错误6 ");
返回;
}
int num=:SendMessage(wd1,TB_BUTTONCOUNT,NULL,NULL);
int I;
无符号长n;
TBBUTTON p,* pp
CString x;
wchar _ t name[256];
无符号长whd,proid
CString温度;
TBBUTTON * sp
sp=(TB button *)0x 20f 00;
for(I=0;inum我)
{
* SendMessage(wd1,TB_GETBUTTON,I,(LPARAM)sp);
PP=p;
ReadProcessMemory(hd,sp,pp,sizeof(p),n);
//x.Format(%x %x %x %x %x %x ,p.iBitmap,p.idCommand,p.fsState,p.fsStyle,p.dwData,p . I string);
name[0]=0;
如果(p正在运行!=0xffffffff)
{
尝试
{
ReadProcessMemory(hd,(void *)p.iString,name,255,n);
name[n]=0;
}
接住(.)
{
}
//x=" ";
//x=name;
temp=name
尝试
{
whd=0;
ReadProcessMemory(hd,(void *)p.dwData,whd,4,n);
}
接住(.)
{
}
proid=0;
GetWindowThreadProcessId((HWND)whd,proid);
x.格式(位置=%d名称=%s窗口句柄=x进程ID=x,
I,(LPCTSTR )temp,whd,proid);
m_list .AddString(x);
}
}
}
到此这篇关于副主席通过托盘图标得到该所属进程的实现代码的文章就介绍到这了,更多相关副主席托盘图标得到该所属进程内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!