Spy++原理初探
2010-07-20 20:46:04 来源:WEB开发网四、常规标签页
常规标签页负责显示窗口句柄、窗口类名、标题文本、窗口矩形、窗口ID、进程ID和程序路径。控制其显示或改变应在CMyPic的WM_LBUTTONUP响应函函数中进行。代码如下:
((CPage0*)FromHandle(g_hPage0))->m_editHWND.SetWindowText(Display((int)g_hWnd));
char strClass[200]="";
::GetClassName(g_hWnd,strClass,200);
((CPage0*)FromHandle(g_hPage0))->m_editCLASS.SetWindowText(strClass);
((CPage2*)FromHandle(g_hPage2))->SetDlgItemText(IDC_EDITCLASSNAME,strClass);<
char strTitle[200]="";
::GetWindowText(g_hWnd,strTitle,200);
((CPage0*)FromHandle(g_hPage0))->m_editTITLE.SetWindowText (strTitle);
long iWNDID=GetWindowLong(g_hWnd,GWL_ID);
((CPage0*)FromHandle(g_hPage0))->m_editWNDID.SetWindowText(Display((int)iWNDID));
unsigned long iPID=0;
GetWindowThreadProcessId(g_hWnd,&iPID);
((CPage0*)FromHandle(g_hPage0))->m_editPID.SetWindowText(Display((int)iPID));
CString strPath;
strPath=getProcPath(iPID);
((CPage0*)FromHandle(g_hPage0))->m_editPATH.SetWindowText(strPath);
RECT rc;
::GetWindowRect(g_hWnd, &rc); //获得窗口矩形
CString strRect;
strRect.Format("(%d,%d),(%d,%d) %dx%d",rc.left,rc.top,rc.right,rc.bottom,
rc.right-rc.left,rc.bottom-rc.top);
((CPage0*)FromHandle(g_hPage0))->m_editRECT.SetWindowText(strRect);
其中,getProcPath是获取进程文件路径的函数。获取进程路径的方法有两种。在NT系统中,我们可以用OpenProcess()函数将进程打开后,再利用EnumProcessModules()函数枚举该进程的模块,最后利用GetModuleFileNameEx()函数就能取得该进程的路径;第二种方法是利用ToolHelp API中的相关函数。而后者兼容容Windows9x和NT4.0以后系统,所以采取此法。它的实现代码如下:
CString getProcPath(int PID)
{
HANDLE hModule;
MODULEENTRY32* minfo=new MODULEENTRY32;
minfo->dwSize=sizeof(MODULEENTRY32);
hModule=CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,PID); Module32First(hModule,minfo);
CString str;
str.Format("%s",minfo->szExePath);
CloseHandle(hModule);
if(minfo) delete minfo;
return str;
}
样式标签页设计如下图:
更多精彩
赞助商链接