Changeset 828 in dev for trunk/ab5.0/abdev/abdev/Attach.cpp
- Timestamp:
- Mar 19, 2012, 1:59:48 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to
/branches/egtra merged eligible
-
Property svn:mergeinfo
set to
-
trunk/ab5.0/abdev
-
Property svn:ignore
set to
*.opensdf
*.sdf
*.suo
*.user
int
ipch
out
-
Property svn:ignore
set to
-
trunk/ab5.0/abdev/abdev/Attach.cpp
r763 r828 4 4 5 5 #include "common.h" 6 #include <abdev/ab_common/include/Path.h> 7 #include <abdev/ab_common/include/ProcessAndModule.h> 6 8 #include <psapi.h> 7 9 #include <tlhelp32.h> … … 37 39 } 38 40 39 void InsertProcess_ToListView(HWND hListView,char *lpszAppPath,int id,char *lpszPlatform,char *lpszTitle){41 void InsertProcess_ToListView(HWND hListView,char const* lpszAppPath,int id,char const* lpszPlatform,char const * lpszTitle){ 40 42 char szAppName[MAX_PATH],temp2[MAX_PATH]; 41 43 _splitpath(lpszAppPath,NULL,NULL,szAppName,temp2); … … 75 77 ListView_SetItem(hListView,&item); 76 78 77 item.pszText= lpszPlatform;79 item.pszText=const_cast<LPSTR>(lpszPlatform); 78 80 item.iSubItem++; 79 81 ListView_SetItem(hListView,&item); 80 82 81 item.pszText= lpszTitle;83 item.pszText=const_cast<LPSTR>(lpszTitle); 82 84 item.iSubItem++; 83 85 ListView_SetItem(hListView,&item); … … 159 161 BOOL CALLBACK FindWindowProc(HWND hwnd, LPARAM lParam) 160 162 { 161 HWND* pphWnd = (HWND*)lParam; 162 *pphWnd = hwnd; 163 return FALSE; /* 列挙を中断 */ 163 auto pProcessIdAndHWnd = reinterpret_cast<std::pair<DWORD, HWND>*>(lParam); 164 DWORD processId = 0; 165 ::GetWindowThreadProcessId(hwnd, &processId); 166 if (processId == pProcessIdAndHWnd->first) 167 { 168 pProcessIdAndHWnd->second = hwnd; 169 return FALSE; 170 } 171 else 172 { 173 return TRUE; 174 } 164 175 } 165 176 void ListupProcesses(HWND hListView){ 166 char temporary[MAX_PATH];167 168 177 ListView_DeleteAllItems(hListView); 169 178 170 DWORD *pdwProcessId;171 pdwProcessId=(DWORD *)HeapAlloc(hHeap,0,8192*sizeof(DWORD));172 173 179 //プロセスを列挙 174 DWORD cbNeeded; 175 EnumProcesses(pdwProcessId,8192*sizeof(DWORD),&cbNeeded); 176 177 char szMyAppPath[MAX_PATH]; 178 GetModuleFileName(GetModuleHandle(0),szMyAppPath,MAX_PATH); 179 180 int i; 181 for(i=0;i<(int)(cbNeeded/sizeof(DWORD));i++){ 182 183 //プロセスIDを元にハンドルを取得 184 HANDLE hProcess; 185 hProcess=OpenProcess(PROCESS_ALL_ACCESS,0,pdwProcessId[i]); 186 if(!hProcess) continue; 187 180 auto processIds = ActiveBasic::Common::GetProcesses(); 181 182 char szMyAppPath[MAX_PATH] = {}; 183 GetModuleFileName(nullptr, szMyAppPath, MAX_PATH); 184 185 BOOST_FOREACH(DWORD processId, processIds) 186 { 188 187 //そのプロセスにおける実行モジュールのインスタンスハンドルを取得 189 HINSTANCE hModule; 190 DWORD cbReturned; 191 if(!EnumProcessModules( hProcess, &hModule, sizeof(HINSTANCE), &cbReturned )) 192 continue; 193 194 //実行ファイル名を取得 195 GetModuleFileNameEx(hProcess,hModule,temporary,MAX_PATH); 196 188 auto executablePath = ActiveBasic::Common::GetExecutableModulePath(processId); 197 189 198 190 ////////////////////////////// … … 200 192 ////////////////////////////// 201 193 202 //スナップショットを取得 203 HANDLE hSnapshot; 204 hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0); 205 206 THREADENTRY32 te; 207 memset(&te,0,sizeof(THREADENTRY32)); 208 te.dwSize=sizeof(THREADENTRY32); 209 if(Thread32First(hSnapshot,&te)){ 210 do{ 211 if(te.th32OwnerProcessID==pdwProcessId[i]){ 212 break; 213 } 214 }while(Thread32Next(hSnapshot,&te)); 215 } 216 217 HWND hwnd; 218 hwnd=0; 219 EnumThreadWindows(te.th32ThreadID,FindWindowProc,(LPARAM)&hwnd); 220 221 while(GetParent(hwnd)) hwnd=GetParent(hwnd); 222 223 char szWndTitle[1024]; 224 szWndTitle[0]=0; 225 if(hwnd) GetWindowText(hwnd,szWndTitle,1024); 226 227 CloseHandle(hSnapshot); 228 229 230 231 CloseHandle(hProcess); 232 233 if(lstrcmpi(szMyAppPath,temporary)==0){ 194 std::pair<DWORD, HWND> processIdAndHWnd(processId, nullptr); 195 EnumWindows(FindWindowProc, reinterpret_cast<LPARAM>(&processIdAndHWnd)); 196 HWND hwnd = processIdAndHWnd.second; 197 198 TCHAR szWndTitle[1024] = {}; 199 if(hwnd) GetWindowText(hwnd, szWndTitle, 1024); 200 201 if (ActiveBasic::Common::IsPathEqual(Jenga::Common::ToWString(szMyAppPath).c_str(), executablePath.wstring().c_str())) 202 { 234 203 //自分自身(ProjectEditor.exe)は無視 235 204 continue; … … 237 206 238 207 //リストビューへ追加 239 InsertProcess_ToListView(hListView,temporary,pdwProcessId[i],"Win32",szWndTitle); 240 } 241 242 HeapDefaultFree(pdwProcessId); 208 InsertProcess_ToListView(hListView,executablePath.string().c_str(),processId,"Win32",szWndTitle); 209 } 243 210 } 244 211
Note:
See TracChangeset
for help on using the changeset viewer.