In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "VC how to get the process through the tray icon", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how VC gets the process through the tray icon" this article.
This example takes getting the location of the program tray icon as an example.
/ / A lot of information can also be obtained as needed.
Code 1 / / get pallet area data RECT CTray::GetTrayRect () {RECT rect = {0}; HWND hWnd = NULL; hWnd = FindTrayWnd (); if (hWnd! = NULL) {if (! EnumNotifyWindow (rect,hWnd)) / / if not in the normal pallet area {hWnd = FindNotifyIconOverflowWindow () / / get the pallet area location bool CTray::EnumNotifyWindow (RECT & rect,HWND hWnd) {/ / RECT rect = {0} in the overflow area (win7) if (hWnd! = NULL) {EnumNotifyWindow (rect,hWnd);} return rect;} / / enumerated; bool bSuc = false; unsigned long lngPID = 0; long ret = 0jngButtons = 0 Long lngHwndAdr = 0jngHwnd = 0ngTextAdr LngButtonID; HANDLE hProcess = NULL; LPVOID lngAddress = NULL,lngRect = NULL; if (hWnd! = NULL) {ret = GetWindowThreadProcessId (hWnd, & lngPID); if (ret! = 0 & lngPID! = 0) {hProcess = OpenProcess (PROCESS_ALL_ACCESS | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE,0,lngPID) / / if (hProcess! = NULL) {lngAddress = VirtualAllocEx (hProcess,0, 0x4096, MEM_COMMIT, PAGE_READWRITE); lngRect = VirtualAllocEx (hProcess,0,sizeof (RECT), MEM_COMMIT, PAGE_READWRITE); lngButtons = SendMessage (hWnd, TB_BUTTONCOUNT, 0,0) / / send a message to get the number of pallet button if (lngAddress! = NULL & & lngRect! = NULL) {for (int item0; I)
< lngButtons;i++) { RECT rc = {0}; int j = i; ret = SendMessage(hWnd,TB_GETBUTTON,j,long(lngAddress));//发送消息获取托盘项数据起始地址 ret = ReadProcessMemory(hProcess, LPVOID(long(lngAddress) + 12),&lngHwndAdr,4,0); if(ret != 0 && lngHwndAdr != -1) { ret = ReadProcessMemory(hProcess, LPVOID(lngHwndAdr),&lngHwnd, 4,0);//获取句柄 if(ret != 0 && (HWND)lngHwnd == m_NotifyIconData.hWnd)// { ret = ::SendMessage(hWnd,TB_GETITEMRECT,(WPARAM)j,(LPARAM)lngRect); //发送消息获取托盘项区域数据 ret = ReadProcessMemory(hProcess,lngRect,&rc, sizeof(rc),0); //读取托盘区域数据 if(ret != 0) { CWnd::FromHandle(hWnd)->ClientToScreen (& rc); rect = rc;} bSuc = true;// found in the normal pallet area, no longer looking for break in the overflow area }} if (lngAddress! = NULL) {VirtualFreeEx (hProcess, lngAddress, 0x4096, MEM_DECOMMIT); VirtualFreeEx (hProcess, lngAddress, 0, MEM_RELEASE) } if (lngRect! = NULL) {VirtualFreeEx (hProcess, lngRect, sizeof (RECT), MEM_DECOMMIT); VirtualFreeEx (hProcess, lngRect, 0, MEM_RELEASE);} CloseHandle (hProcess);}} return bSuc } / / get window handle HWND CTray::FindTrayWnd () {HWND hWnd = NULL; HWND hWndPaper = NULL; if ((hWnd = FindWindow (_ T ("Shell_TrayWnd"), NULL))! = NULL) {if ((hWnd = FindWindowEx (hWnd, 0, _ T ("TrayNotifyWnd"), NULL)! = NULL) {hWndPaper = FindWindowEx (hWnd, 0, _ T ("SysPager"), NULL) If (! hWndPaper) hWnd = FindWindowEx (hWnd, 0, _ T ("ToolbarWindow32"), NULL); else hWnd = FindWindowEx (hWndPaper, 0, _ T ("ToolbarWindow32"), NULL);}} return hWnd;} / / get overflow tray window handle HWND CTray::FindNotifyIconOverflowWindow () {HWND hWnd = NULL; hWnd = FindWindow (_ T ("NotifyIconOverflowWindow"), NULL) If (hWnd! = NULL) {hWnd = FindWindowEx (hWnd, NULL, _ T ("ToolbarWindow32"), NULL);} return hWnd;}
The following code is collected online, and the success of the variable initialization pointer handle and function has not been determined.
/ / add your own judgment if you need it, and change it when you have time.
Code 2 struct TRAYDATA {HWND hwnd; UINT uID; UINT uCallbackMessage; DWORD Reserved [2]; HICON hIcon;}; void CTray::GetTrayRect () {HWND hWnd,hWndPaper;unsigned long lngPID;long ret,lngButtons;HANDLE hProcess;LPVOID lngAddress;long lngTextAdr,lngHwndAdr,lngHwnd,lngButtonID TCHAR strBuff [1024] = {0}; TRAYDATA trayData = {0}; TBBUTTON btnData= {0}; hWnd = FindWindow (_ T ("Shell_TrayWnd"), NULL); hWnd = FindWindowEx (hWnd, 0, T ("TrayNotifyWnd"), NULL); hWndPaper = FindWindowEx (hWnd, 0, _ T ("SysPager"), NULL); if (! hWndPaper) hWnd = FindWindowEx (hWnd, 0, _ T ("ToolbarWindow32"), NULL); elsehWnd = FindWindowEx (hWndPaper, 0, _ T ("ToolbarWindow32"), NULL) Ret = GetWindowThreadProcessId (hWnd, & lngPID); hProcess = OpenProcess (PROCESS_ALL_ACCESS | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE,0,lngPID); lngAddress = VirtualAllocEx (hProcess,0, 0x4096, MEM_COMMIT, PAGE_READWRITE); lngButtons = SendMessage (hWnd, TB_BUTTONCOUNT, 0,0); RECT rc; POINT point;LPVOID lngRect = VirtualAllocEx (hProcess,0,sizeof (RECT), MEM_COMMIT, PAGE_READWRITE); CRect rect;for (int item0; I
< lngButtons;i++){int j = i;ret = SendMessage(hWnd,TB_GETBUTTON,j,long(lngAddress));ret = ReadProcessMemory(hProcess, LPVOID(long(lngAddress) + 16),&lngTextAdr,4,0);if(lngTextAdr != -1){ret = ReadProcessMemory(hProcess, LPVOID(lngTextAdr),strBuff,1024,0);//ret = ReadProcessMemory(hProcess, LPVOID(long(lngAddress) + 12),&lngHwndAdr,4,0); //获取句柄//ret = ReadProcessMemory(hProcess, LPVOID(lngHwndAdr),&lngHwnd, 4,0);//ret = ReadProcessMemory(hProcess, LPVOID(long(lngAddress) + 4),&lngButtonID,4,0);//获取buttonIDCString str(strBuff);if (str.Compare(m_NotifyIconData.szTip) == 0){::SendMessage(hWnd,TB_GETITEMRECT,(WPARAM)j,(LPARAM)lngRect);ReadProcessMemory(hProcess,lngRect,&rc, sizeof(rc),0); //获取托盘图标区域CWnd::FromHandle(hWnd)->ClientToScreen (& rc);} / / the following is the hidden tray icon / / {/ / if (show) / / {/ / SendMessage (hWnd,TB_HIDEBUTTON,lngButtonID,0); / /} / / else// {/ / SendMessage (hWnd,TB_HIDEBUTTON,lngButtonID,1); / /} /}} VirtualFreeEx (hProcess, lngAddress, 0x4096, MEM_DECOMMIT) VirtualFreeEx (hProcess, lngAddress, 0, MEM_RELEASE); VirtualFreeEx (hProcess, lngRect, sizeof (RECT), MEM_DECOMMIT); VirtualFreeEx (hProcess, lngRect, 0, MEM_RELEASE); CloseHandle (hProcess);} Code 3 VOID StartStorm () {HWND hMain = FindWindow ("animate_layered_window_class", "Storm Media Center"); if (hMain) {ShowWindow (hMain, SW_HIDE) } / / get toolbar handle HWND hTray = FindWindow ("Shell_TrayWnd", NULL); hTray = FindWindowEx (hTray, 0, "TrayNotifyWnd", NULL); hTray = FindWindowEx (hTray, 0, "SysPager", NULL); hTray = FindWindowEx (hTray, 0, "ToolbarWindow32", NULL); / / get explore process ID DWORD TrayPid; GetWindowThreadProcessId (hTray, & TrayPid) / / Open the process and open the process space RECT rect; TBBUTTON tb; TBBUTTON pTb; LPVOID lpAddr; DWORD dwThreadIdOfICO; DWORD dwTempId = FindStorm ("Stormtray.exe"); / / the PID TRAYDATA traydata; HANDLE hOpen of the process you want to click on = OpenProcess (PROCESS_ALL_ACCESS, FALSE, TrayPid) LpAddr = VirtualAllocEx (hOpen, NULL, sizeof (tb) + sizeof (rect), MEM_COMMIT, PAGE_READWRITE); int nCount = SendMessage (hTray, TB_BUTTONCOUNT, 0,0); int i; DWORD dwOutWrite; for (I = 0; I < nCount; I + +) {ZeroMemory (& tb, sizeof (tb); ZeroMemory (& rect, sizeof (rect)) / / write parameters to the target process WriteProcessMemory (hOpen, lpAddr, & tb, sizeof (tb), & dwOutWrite); / / WriteProcessMemory (hOpen, (LPVOID) ((DWORD) lpAddr + sizeof (pTb)), & rect, sizeof (rect), & dwOutWrite); / / get BUTTON SendMessage (hTray, TB_GETBUTTON, I, LPARAM (lpAddr)) / read TBBUTTON structure ReadProcessMemory (hOpen, lpAddr, & pTb, sizeof (TBBUTTON), & dwOutWrite); / / read TRAYDATA structure ReadProcessMemory (hOpen, (LPVOID) pTb.dwData, & traydata, sizeof (TRAYDATA), & dwOutWrite); GetWindowThreadProcessId (traydata.hwnd, & dwThreadIdOfICO) If (dwThreadIdOfICO = = dwTempId) {/ / get RECT LPVOID lp of ICO = (LPVOID) ((DWORD) lpAddr + sizeof (pTb)); SendMessage (hTray, TB_GETITEMRECT, I, (LPARAM) lp) LPVOID lpdata = (LPVOID) ((DWORD) lpAddr + sizeof (TBBUTTON)); ReadProcessMemory (hOpen, lpdata, & rect, sizeof (rect), & dwOutWrite); int iGap = rect.right/2 / / interval to get the intermediate coordinates of the icon / / Click 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)) / / CloseHandle (hOpen); break;;}}
Win7 has an overflow pallet area: the following is the pallet information hidden in the pallet area, which cannot be found using the above method, because in NotifyIconOverflowWindow
Fhwnd = FindWindow ("NotifyIconOverflowWindow", NULL)
Reference article: http://topic.csdn.net/u/20101003/23/859851ee-5aa1-4476-8ce1-1359826df2b0.html
Code IV # include "stdafx.h" # include # include # include using namespace std;typedef BOOL (WINAPI * LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); BOOL IsWow64 () {BOOL bIsWow64 = FALSE; LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (_ T ("kernel32")), "IsWow64Process") If (NULL! = fnIsWow64Process) {if (! fnIsWow64Process (GetCurrentProcess (), & bIsWow64)) {/ / handle error}} return bIsWow64;} HWND FindTrayWnd () {HWND hWnd = NULL; hWnd = FindWindow (_ T ("Shell_TrayWnd"), NULL); hWnd = FindWindowEx (hWnd, NULL, _ T ("TrayNotifyWnd"), NULL) HWnd = FindWindowEx (hWnd, NULL, _ T ("SysPager"), NULL); hWnd = FindWindowEx (hWnd, NULL, _ T ("ToolbarWindow32"), NULL); return hWnd;} HWND FindNotifyIconOverflowWindow () {HWND hWnd = NULL; hWnd = FindWindow (_ T ("NotifyIconOverflowWindow"), NULL); hWnd = FindWindowEx (hWnd, NULL, _ T ("ToolbarWindow32"), NULL); return hWnd;} void EnumNotifyWindow (HWND hWnd) {DWORD dwProcessId = 0; GetWindowThreadProcessId (hWnd,&dwProcessId) HANDLE hProcess= OpenProcess (PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, dwProcessId); if (hProcess==NULL) {return;} LPVOID lAddress= VirtualAllocEx (hProcess, 0, 4096, MEM_COMMIT, PAGE_READWRITE); if (lAddress==NULL) {return;} DWORD lTextAdr = 0; BYTE buff [1024] = {0}; CString strFilePath; CString strTile; HWND hMainWnd = NULL Int nDataOffset = sizeof (TBBUTTON)-sizeof (INT_PTR)-sizeof (DWORD_PTR); int nStrOffset = 18; if (IsWow64 ()) {nDataOffset+=4; nStrOffset+=6;} / / get the number of instances int lButton = SendMessage (hWnd, TB_BUTTONCOUNT, 0,0); for (int I = 0; I < lButton; iTunes +) {SendMessage (hWnd, TB_GETBUTTON, I, (LPARAM) lAddress) / / the text address ReadProcessMemory (hProcess, (LPVOID) ((DWORD) lAddress + nDataOffset), & lTextAdr, 4,0); if (lTextAdrystalline copyright 1) {/ / "text ReadProcessMemory (hProcess, (LPCVOID) lTextAdr, buff, 1024, 0); hMainWnd = (HWND) (* (DWORD*) buff); strFilePath = (WCHAR *) buff + nStrOffset StrTile = (WCHAR *) buff + nStrOffset + MAX_PATH; _ tprintf (_ T ("% s\ n"), strTile,strFilePath);}} VirtualFreeEx (hProcess, lAddress, 4096, MEM_RELEASE); CloseHandle (hProcess);} int _ tmain (int argc, _ TCHAR* argv []) {setlocale (LC_ALL, "chs"); EnumNotifyWindow (FindTrayWnd ()); _ tprintf (_ T ("\ n")) EnumNotifyWindow (FindNotifyIconOverflowWindow ()); system ("pause"); return 0;} Code five void CTrayDlg::OnButton1 () {/ / TODO: Add your control notification handler code here HWND wd=::FindWindow ("Shell_TrayWnd", NULL); if (wd==NULL) {MessageBox ("Error1"); return;} HWND wtd=FindWindowEx (wd,NULL, "TrayNotifyWnd", NULL) If (wtd==NULL) {MessageBox ("Error2"); return;} HWND wd1=FindWindowEx (wtd,NULL, "ToolbarWindow32", NULL); if (wd1==NULL) {MessageBox ("Error3"); return;} DWORD pid; pid=0; GetWindowThreadProcessId (wd1,&pid); if (pid==NULL) {MessageBox ("Error4") Return;} HANDLE hd=OpenProcess (PROCESS_QUERY_INFORMATION examples PROCESS_ALL_ACCESS, true,pid); if (hd==NULL) {MessageBox ("Error6"); return;} int num=::SendMessage (wd1,TB_BUTTONCOUNT, NULL,NULL); int i; unsigned long n; TBBUTTON pmae ppp; CString x; wchar_t name [256] Unsigned long whd,proid; CString temp; TBBUTTON * sp; sp= (TBBUTTON *) 0x20f00; / / it should be changed to use VirtualAllocEx to allocate memory, otherwise it may go wrong, but lazy, let's just say for.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.