-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainDlg.cpp
229 lines (200 loc) · 6.71 KB
/
MainDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// MainDlg.cpp : implementation of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MainDlg.h"
CMainDlg::CMainDlg() : SHostWnd(_T("LAYOUT:XML_MAINWND"))
{
m_bLayoutInited=FALSE;
}
CMainDlg::~CMainDlg()
{
}
void CMainDlg::OnShowWindow( BOOL bShow, UINT nStatus )
{
if(bShow)
{
AnimateHostWindow(200,AW_CENTER);
}
}
BOOL CMainDlg::OnInitDialog( HWND hWnd, LPARAM lParam )
{
m_bLayoutInited=TRUE;
m_pTreeCtrl = FindChildByName2<STreeCtrl>(L"tree_swnd");
SASSERT(m_pTreeCtrl);
m_wndFrame.Create(m_hWnd);
return 0;
}
BOOL CMainDlg::OnEventCaptureHost( EventArgs *pEvt )
{
EventCapture *pEvt2=(EventCapture*)pEvt;
CPoint pt = pEvt2->pt_;
ClientToScreen(&pt);
HWND hWnd=::WindowFromPoint(pt);
if(hWnd == m_hWnd) return TRUE;
SStringT str;
str.Format(_T("0x%08x"),hWnd);
FindChildByName(L"txt_hosthwnd")->SetWindowText(str);
TCHAR szClassName[100];
::GetClassName(hWnd,szClassName,100);
FindChildByName(L"txt_hostclass")->SetWindowText(szClassName);
return FALSE;
}
BOOL CMainDlg::OnEventCaptureHostFinish( EventArgs *pEvt )
{
EventCaptureFinish *pEvt2=(EventCaptureFinish*)pEvt;
CPoint pt = pEvt2->pt_;
ClientToScreen(&pt);
HWND hWnd=::WindowFromPoint(pt);
if(hWnd == m_hWnd) return TRUE;
SStringT str;
str.Format(_T("0x%08x"),hWnd);
FindChildByName(L"txt_hosthwnd")->SetWindowText(str);
TCHAR szClassName[100];
::GetClassName(hWnd,szClassName,100);
FindChildByName(L"txt_hostclass")->SetWindowText(szClassName);
m_pTreeCtrl->RemoveAllItems();
LRESULT lRet=::SendMessage(hWnd,SPYMSG_SETSPY,0,(LPARAM)m_hWnd);
if(lRet == 1)
{
SStringT strRoot;
strRoot.Format(_T("0x%08x"),hWnd);
m_pTreeCtrl->SetUserData((LPARAM)hWnd);
HSTREEITEM hRoot = m_pTreeCtrl->InsertItem(strRoot,2,2,(LPARAM)0);
EnumSwnd(hWnd,0,hRoot);
}
return TRUE;
}
SWNDINFO swndInfo;
void CMainDlg::EnumSwnd( HWND hHost ,DWORD dwSwnd, HSTREEITEM hItem)
{
DWORD dwChild = ::SendMessage(hHost,SPYMSG_SWNDENUM,dwSwnd,GSW_FIRSTCHILD);
while(dwChild != 0)
{
if(0!=::SendMessage(hHost,SPYMSG_SWNDINFO,dwChild,0))
{
SStringW str;
str.Format(L"class:%s,swnd:%d,name:%s",swndInfo.szClassName,swndInfo.swnd,swndInfo.szName[0]==0?L"[undef]":swndInfo.szName);
int iIcon = swndInfo.bVisible?0:1;
HSTREEITEM hChild=m_pTreeCtrl->InsertItem((LPCTSTR)S_CW2T(str),iIcon,iIcon,(LPARAM)swndInfo.swnd,hItem,STVI_LAST,FALSE);
EnumSwnd(hHost,dwChild,hChild);
}
dwChild = ::SendMessage(hHost,SPYMSG_SWNDENUM,dwChild,GSW_NEXTSIBLING);
}
}
BOOL CMainDlg::OnCopyData( HWND hSend, PCOPYDATASTRUCT pCopyDataStruct )
{
if(pCopyDataStruct->dwData != SPYMSG_SWNDINFO) return FALSE;
SWNDINFO *pSwndInfo = (SWNDINFO*)pCopyDataStruct->lpData;
memcpy(&swndInfo,pCopyDataStruct->lpData,sizeof(swndInfo));
return TRUE;
}
void CMainDlg::OnBtnSearch()
{
SStringT strTarget = FindChildByName(L"edit_search")->GetWindowText();
strTarget.MakeLower();
HSTREEITEM hItemStart= m_pTreeCtrl->GetSelectedItem();
if(!hItemStart) hItemStart = m_pTreeCtrl->GetRootItem();
if(!hItemStart) return;
HSTREEITEM hItem = m_pTreeCtrl->GetNextItem(hItemStart);
while(hItem)
{
SStringT strText;
m_pTreeCtrl->GetItemText(hItem,strText);
strText.MakeLower();
if(-1 != strText.Find(strTarget))
{
m_pTreeCtrl->SelectItem(hItem);
return;
}
hItem = m_pTreeCtrl->GetNextItem(hItem);
}
if(SMessageBox(m_hWnd,_T("从当前位置开始没有找到匹配窗口,是否从头开始?"),_T("提示"),MB_ICONQUESTION|MB_OKCANCEL) == IDCANCEL)
return;
hItem = m_pTreeCtrl->GetRootItem();
while(hItem && hItem != hItemStart)
{
SStringT strText;
m_pTreeCtrl->GetItemText(hItem,strText);
strText.MakeLower();
if(-1 != strText.Find(strTarget))
{
m_pTreeCtrl->SelectItem(hItem);
return;
}
hItem = m_pTreeCtrl->GetNextItem(hItem);
}
}
BOOL CMainDlg::OnEventTreeSelChanged( EventArgs *pEvt )
{
EventTCSelChanged *pEvt2 = (EventTCSelChanged*)pEvt;
HSTREEITEM hSelItem = pEvt2->hNewSel;
if(hSelItem)
{
int swnd = m_pTreeCtrl->GetItemData(hSelItem);
if(swnd)
{
HWND hHost = (HWND)m_pTreeCtrl->GetUserData();
if(0!=::SendMessage(hHost,SPYMSG_SWNDINFO,swnd,0))
{
if(swndInfo.bVisible)
{
CRect rcWnd=swndInfo.rcWnd;
::ClientToScreen(hHost,(LPPOINT)&rcWnd);
::ClientToScreen(hHost,((LPPOINT)&rcWnd)+1);
::BringWindowToTop(hHost);
m_wndFrame.Show(rcWnd);
}
FindChildByName(L"edit_xml")->SetWindowText(S_CW2T(swndInfo.szXmlStr));
}
}
}
return TRUE;
}
BOOL CMainDlg::OnEventCaptureSwnd( EventArgs *pEvt )
{
EventCapture *pEvt2=(EventCapture*)pEvt;
HWND hWnd = (HWND) m_pTreeCtrl->GetUserData();
CPoint pt = pEvt2->pt_;
ClientToScreen(&pt);
HWND hWnd2=::WindowFromPoint(pt);
if(hWnd2 != hWnd) return TRUE;
int swnd = ::SendMessage(hWnd,SPYMSG_HITTEST,0,MAKELPARAM(pt.x,pt.y));
if(swnd != 0)
{
HWND hHost = (HWND)m_pTreeCtrl->GetUserData();
if(0!=::SendMessage(hHost,SPYMSG_SWNDINFO,swnd,0))
{
CRect rcWnd=swndInfo.rcWnd;
::ClientToScreen(hHost,(LPPOINT)&rcWnd);
::ClientToScreen(hHost,((LPPOINT)&rcWnd)+1);
m_wndFrame.Show(rcWnd);
}
}
return TRUE;
}
BOOL CMainDlg::OnEventCaptureSwndFinish( EventArgs *pEvt )
{
EventCapture *pEvt2=(EventCapture*)pEvt;
HWND hWnd = (HWND) m_pTreeCtrl->GetUserData();
CPoint pt = pEvt2->pt_;
ClientToScreen(&pt);
HWND hWnd2=::WindowFromPoint(pt);
if(hWnd2 != hWnd) return TRUE;
int swnd = ::SendMessage(hWnd,SPYMSG_HITTEST,0,MAKELPARAM(pt.x,pt.y));
if(swnd)
{//locate swnd in treectrl
HSTREEITEM hItem=m_pTreeCtrl->GetRootItem();
while(hItem)
{
int swnd2 = m_pTreeCtrl->GetItemData(hItem);
if(swnd == swnd2)
{
m_pTreeCtrl->SelectItem(hItem,TRUE);
break;
}
hItem = m_pTreeCtrl->GetNextItem(hItem);
}
}
return TRUE;
}