#include "stdafx.h" #ifndef THETEXT #include "common.h" #include #include #pragma comment(lib, "psapi.lib") using namespace ActiveBasic::IDE; int GetSelectingProcessId(HWND hListView,DWORD *lpdwPlatform){ int nCount; nCount=ListView_GetItemCount(hListView); char temporary[255]; DWORD dwProcessId; int i; for(i=0;i(enumProcess64ExePath.c_str()),NULL,NULL,0,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi); WaitForSingleObject(pi.hProcess,INFINITE); ////////////////////////////////// // 生成されたファイルの読み込み ////////////////////////////////// std::string listPath = ActiveBasic::Common::Environment::GetAbdevSystemDirPath() + "\\enum_process64\\list.dat"; char *buffer; buffer=ReadBuffer_NonErrMsg( listPath ); if(!buffer) return; int i=0; char temporary[MAX_PATH]; while(1){ //ファイルパス char szAppPath[MAX_PATH]; i=GetOneParameter(buffer,i,szAppPath); if(szAppPath[0]=='\0') break; RemoveStringQuotes(szAppPath); //プロセスID DWORD dwProcessId; i=GetOneParameter(buffer,i,temporary); if(temporary[0]=='\0') break; dwProcessId=(DWORD)atoi(temporary); //プラットフォーム char szPlatform[255]; i=GetOneParameter(buffer,i,szPlatform); if(temporary[0]=='\0') break; //タイトル char szTitle[255]; int i2; for(i2=0;;i++,i2++){ if(IS_RETURN(buffer,i)||buffer[i]=='\0'){ szTitle[i2]=0; break; } szTitle[i2]=buffer[i]; } //リストビューへ追加 InsertProcess_ToListView(hListView,szAppPath,dwProcessId,szPlatform,szTitle); if(buffer[i]=='\r'&&buffer[i+1]=='\n') i+=2; if(buffer[i]=='\0') break; } HeapDefaultFree(buffer); } // EnumWindowsProcコールバック関数 BOOL CALLBACK FindWindowProc(HWND hwnd, LPARAM lParam) { HWND* pphWnd = (HWND*)lParam; *pphWnd = hwnd; return FALSE; /* 列挙を中断 */ } void ListupProcesses(HWND hListView){ char temporary[MAX_PATH]; ListView_DeleteAllItems(hListView); DWORD *pdwProcessId; pdwProcessId=(DWORD *)HeapAlloc(hHeap,0,8192*sizeof(DWORD)); //プロセスを列挙 DWORD cbNeeded; EnumProcesses(pdwProcessId,8192*sizeof(DWORD),&cbNeeded); char szMyAppPath[MAX_PATH]; GetModuleFileName(GetModuleHandle(0),szMyAppPath,MAX_PATH); int i; for(i=0;i<(int)(cbNeeded/sizeof(DWORD));i++){ //プロセスIDを元にハンドルを取得 HANDLE hProcess; hProcess=OpenProcess(PROCESS_ALL_ACCESS,0,pdwProcessId[i]); if(!hProcess) continue; //そのプロセスにおける実行モジュールのインスタンスハンドルを取得 HINSTANCE hModule; DWORD cbReturned; if(!EnumProcessModules( hProcess, &hModule, sizeof(HINSTANCE), &cbReturned )) continue; //実行ファイル名を取得 GetModuleFileNameEx(hProcess,hModule,temporary,MAX_PATH); ////////////////////////////// // ウィンドウタイトルを取得 ////////////////////////////// //スナップショットを取得 HANDLE hSnapshot; hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0); THREADENTRY32 te; memset(&te,0,sizeof(THREADENTRY32)); te.dwSize=sizeof(THREADENTRY32); if(Thread32First(hSnapshot,&te)){ do{ if(te.th32OwnerProcessID==pdwProcessId[i]){ break; } }while(Thread32Next(hSnapshot,&te)); } HWND hwnd; hwnd=0; EnumThreadWindows(te.th32ThreadID,FindWindowProc,(LPARAM)&hwnd); while(GetParent(hwnd)) hwnd=GetParent(hwnd); char szWndTitle[1024]; szWndTitle[0]=0; if(hwnd) GetWindowText(hwnd,szWndTitle,1024); CloseHandle(hSnapshot); CloseHandle(hProcess); if(lstrcmpi(szMyAppPath,temporary)==0){ //自分自身(ProjectEditor.exe)は無視 continue; } //リストビューへ追加 InsertProcess_ToListView(hListView,temporary,pdwProcessId[i],"Win32",szWndTitle); } HeapDefaultFree(pdwProcessId); } BOOL CALLBACK DlgAttach(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){ static HWND hListView; static HIMAGELIST hImageList; static DWORD *lpdwPlatform; switch(message){ case WM_INITDIALOG: SetPosCenter(hwnd); lpdwPlatform=(DWORD *)lParam; hListView=GetDlgItem(hwnd,IDC_PROCESSLIST); //拡張スタイル DWORD dwStyle; dwStyle=ListView_GetExtendedListViewStyle(hListView); dwStyle|=LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES; ListView_SetExtendedListViewStyle(hListView,dwStyle); //イメージリストの生成と設定 hImageList=ImageList_Create(16,16,ILC_COLOR24|ILC_MASK,0,0); ListView_SetImageList(hListView,hImageList,LVSIL_SMALL ); /////////////////////////// // カラムをセット /////////////////////////// LV_COLUMN ListView_Column; ListView_Column.mask=LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; ListView_Column.fmt=LVCFMT_LEFT; ListView_Column.cx=150; ListView_Column.pszText="プロセス名"; ListView_Column.iSubItem=0; ListView_InsertColumn(hListView,ListView_Column.iSubItem,&ListView_Column); ListView_Column.cx=70; ListView_Column.pszText="ID"; ListView_Column.iSubItem++; ListView_InsertColumn(hListView,ListView_Column.iSubItem,&ListView_Column); ListView_Column.cx=50; ListView_Column.pszText="種別"; ListView_Column.iSubItem++; ListView_InsertColumn(hListView,ListView_Column.iSubItem,&ListView_Column); ListView_Column.cx=200; ListView_Column.pszText="タイトル"; ListView_Column.iSubItem++; ListView_InsertColumn(hListView,ListView_Column.iSubItem,&ListView_Column); //リスビューを更新 if(IsWow64()) ListupProcesses64(hListView); else ListupProcesses(hListView); break; case WM_COMMAND: switch(LOWORD(wParam)){ case IDOK: EndDialog(hwnd,GetSelectingProcessId(hListView,lpdwPlatform)); return 1; case IDCANCEL: EndDialog(hwnd,0); return 1; } return 0; case WM_NOTIFY: NMLISTVIEW *nmListView; nmListView=(NMLISTVIEW *)lParam; if(nmListView->hdr.hwndFrom==hListView){ if(nmListView->hdr.code==NM_DBLCLK){ if(nmListView->iItem==-1) return 1; SendMessage(hwnd,WM_COMMAND,IDOK,0); return 1; } } break; case WM_DESTROY: ImageList_Destroy(hImageList); return 1; } return 0; } #endif //THETEXT