A
ahui
Unregistered / Unconfirmed
GUEST, unregistred user!
哪位朋友帮我把C++程序改成Delphi程序,该程序的作用是“通过托盘图标得到该所属进程”<br>C++程序如下:<br>void CTrayDlg::OnButton1() <br>{<br> // TODO: Add your control notification handler code here<br> HWND wd = ::FindWindow("Shell_TrayWnd", NULL);<br> if (wd == NULL)<br> {<br> MessageBox("Error1"<br> return;<br> }<br> HWND wtd = FindWindowEx(wd, NULL, "TrayNotifyWnd", NULL);<br> if (wtd == NULL)<br> {<br> MessageBox("Error2"<br> return;<br> }<br> HWND wd1 = FindWindowEx(wtd, NULL, "SysPager", NULL);<br> HWND wd2;<br> if (wd1 == NULL)<br> {<br> wd2 = FindWindowEx(wtd, NULL, "ToolbarWindow32", NULL);<br> }<br> else<br> {<br> wd2 = FindWindowEx(wd1, NULL, "ToolbarWindow32", NULL);<br> }<br> if (wd2 == NULL)<br> {<br> MessageBox("Error3"<br> return;<br> }<br> DWORD pid;<br> pid = 0;<br> GetWindowThreadProcessId(wd2, &pid);<br> if (pid == NULL)<br> {<br> MessageBox("Error4"<br> return;<br> }<br> HANDLE hd = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_ALL_ACCESS,<br> true, pid);<br> if (hd == NULL)<br> {<br> MessageBox("Error5"<br> return;<br> }<br> int num = ::SendMessage(wd2, TB_BUTTONCOUNT, NULL, NULL);<br> int i;<br> unsigned long n;<br> TBBUTTON p, * pp;<br> CString x;<br> wchar_t name[256];<br> unsigned long whd,proid;<br> CString temp;<br> TBBUTTON* sp;<br> sp = (TBBUTTON *) 0x20f00;<br> for (i = 0; i < num; i++)<br> {<br> ::SendMessage(wd2, TB_GETBUTTON, i, (LPARAM) sp);<br> pp = &p;<br> ReadProcessMemory(hd, sp, pp, sizeof(p), &n);<br> // x.Format("%x %x %x %x %x %x",p.iBitmap,p.idCommand,p.fsState,p.fsStyle, p.dwData, p.iString);<br> name[0] = 0;<br> if (p.iString != 0xffffffff)<br> {<br> try<br> {<br> ReadProcessMemory(hd, (void *) p.iString, name, 255, &n);<br> name[n] = 0;<br> }<br> catch (...)<br> {<br> }<br> // x+=" ";<br> // x+=name;<br> temp = name;<br> try<br> {<br> whd = 0;<br> ReadProcessMemory(hd, (void *) p.dwData, &whd, 4, &n);<br> }<br> catch (...)<br> {<br> }<br> proid = 0;<br> GetWindowThreadProcessId((HWND) whd, &proid);<br> x.Format("位置=%d 名称=%s 窗口句柄=%08x 进程ID=%08x", i,<br> (LPCTSTR) temp, whd, proid);<br> MessageBox(x);<br> }<br> }<br>}