Spy++原理初探
2010-07-20 20:46:04 来源:WEB开发网在该页中,主要用到了下面几个API函数:GetNextWindow、GetWindow和SendMessage。这三个API函数搭配以不同的参数值可以实现不同的功能。这里没有用GetWIndowText函数,是因为它不能取出部分系统窗口和隐藏窗口的标题。我们用SendMessage函数加WM_GETTEXT参数取代之。代码如下:
CPage3* pPage3=(CPage3*)FromHandle(g_hPage3);
HWND tempHandle;
char tempstr[255]="";
tempHandle = g_hWnd; //本窗口句柄
pPage3->SetDlgItemText(IDC_MYHWND, Display((int)tempHandle));
//获取本窗口标题
::SendMessage(tempHandle, WM_GETTEXT, 255, (LPARAM)tempstr);
pPage3->SetDlgItemText(IDC_MYTITLE, tempstr);
//上一窗口
tempHandle = ::GetNextWindow(g_hWnd, GW_HWNDPREV);
pPage3->SetDlgItemText(IDC_PREHWND, Display((int)tempHandle));
//获取上一窗口标题
memset(tempstr,0,255);
::SendMessage(tempHandle, WM_GETTEXT, 255, (LPARAM)tempstr);
pPage3->SetDlgItemText(IDC_PRETITLE, tempstr);
//下一窗口
tempHandle = ::GetNextWindow(g_hWnd, GW_HWNDNEXT);
pPage3->SetDlgItemText(IDC_NEXTHWND,Display((int)tempHandle));
memset(tempstr,0,255); //获取下一窗口标题
::SendMessage(tempHandle, WM_GETTEXT, 255, (LPARAM)tempstr);
pPage3->SetDlgItemText(IDC_NEXTTITLE, tempstr);
tempHandle = ::GetParent(g_hWnd); //父窗口
pPage3->SetDlgItemText(IDC_PARENTHWND, Display((int)tempHandle));
memset(tempstr,0,255);
::SendMessage(tempHandle, WM_GETTEXT, 255, (LPARAM)tempstr);
pPage3->SetDlgItemText(IDC_PARENTTITLE,tempstr);
//第一子窗口
tempHandle = ::GetWindow(g_hWnd, GW_CHILD);
pPage3->SetDlgItemText(IDC_CHILDHWND,Display((int)tempHandle));
memset(tempstr,-0,255);
::SendMessage(tempHandle, WM_GETTEXT, 255, (LPARAM)tempstr);
pPage3->SetDlgItemText(IDC_CHILDTITLE,tempstr);
//所有者窗口
tempHandle = ::GetWindow(g_hWnd, GW_OWNER);
Page3->SetDlgItemText(IDC_OWNERHWND,Display((int)tempHandle));
memset(tempstr,0,255);
::SendMessage(tempHandle, WM_GETTEXT, 255, (LPARAM)tempstr);
pPage3->SetDlgItemText(IDC_OWNERTITLE, tempstr);
更多精彩
赞助商链接