OSDN Git Service

Rewrite CProfile::GetTaskList.
authorKazuhiro Fujieda <fujieda@users.sourceforge.jp>
Fri, 20 May 2011 23:37:22 +0000 (08:37 +0900)
committerKazuhiro Fujieda <fujieda@users.sourceforge.jp>
Thu, 26 May 2011 23:36:10 +0000 (08:36 +0900)
Delete PROCESS_SIZE macro. Make m_TaskList and m_dwTasks in CProfile
private. GetTaskList operates them directly. Remove arguments and
the return value of it. Remove code to delete directory names in it.

xkeymacs/profile.cpp
xkeymacs/profile.h

index 9400360..c587219 100644 (file)
@@ -1108,7 +1108,7 @@ void CProfile::InitApplicationList(CComboBox *const cApplicationList)
 {\r
        cApplicationList->ResetContent();\r
 \r
-       m_dwTasks = GetTaskList(m_TaskList, MAX_TASKS);\r
+       GetTaskList();\r
 \r
        EnumWindows(EnumWindowsProc, (LPARAM)cApplicationList);\r
 \r
@@ -1171,39 +1171,24 @@ void CProfile::InitApplicationList(CComboBox *const cApplicationList)
        cApplicationList->SelectString(-1, CString(MAKEINTRESOURCE(IDS_DEFAULT_TITLE)));\r
 }\r
 \r
-DWORD CProfile::GetTaskList(PTASK_LIST pTask, const DWORD dwNumTasks)\r
+void CProfile::GetTaskList()\r
 {\r
-       for (int i = 0; i < MAX_TASKS; ++i) {\r
-               ZeroMemory(&pTask[i], sizeof(PTASK_LIST));\r
-       }\r
+       ZeroMemory(m_TaskList, sizeof(m_TaskList));\r
 \r
        HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);\r
-       if (hProcessSnap == (HANDLE)-1) {\r
-               return 0;\r
-       }\r
+       if (hProcessSnap == (HANDLE)-1)\r
+               return;\r
 \r
-       DWORD dwTaskCount = 0;\r
+       m_dwTasks = 0;\r
        PROCESSENTRY32 processEntry32 = {sizeof(PROCESSENTRY32)};\r
        if (Process32First(hProcessSnap, &processEntry32)) {\r
                do {\r
-                       LPTSTR pCurChar = NULL;\r
-                       for (pCurChar = processEntry32.szExeFile + lstrlen(processEntry32.szExeFile); *pCurChar != _T('\\') && pCurChar != processEntry32.szExeFile; --pCurChar) {\r
-                               ;\r
-                       }\r
-                       if (*pCurChar == _T('\\')) {\r
-                               ++pCurChar;\r
-                       }\r
-\r
-                       lstrcpy(pTask->ProcessName, pCurChar);\r
-                       pTask->dwProcessId = processEntry32.th32ProcessID;\r
-\r
-                       ++dwTaskCount;\r
-                       ++pTask;\r
-               } while (dwTaskCount < dwNumTasks && Process32Next(hProcessSnap, &processEntry32));\r
+                       lstrcpy(m_TaskList[m_dwTasks].ProcessName, processEntry32.szExeFile);\r
+                       m_TaskList[m_dwTasks++].dwProcessId = processEntry32.th32ProcessID;\r
+               } while (m_dwTasks < MAX_TASKS && Process32Next(hProcessSnap, &processEntry32));\r
        }\r
 \r
        CloseHandle(hProcessSnap);\r
-       return dwTaskCount;\r
 }\r
 \r
 // return application index\r
index 155e8b7..8517f46 100644 (file)
 #include <winperf.h>   // for Windows NT\r
 #include "resource.h"\r
 \r
-#define PROCESS_SIZE        MAX_PATH\r
-\r
 struct TASK_LIST {\r
     DWORD dwProcessId;\r
-    CHAR ProcessName[PROCESS_SIZE];\r
+    CHAR ProcessName[MAX_PATH];\r
 };\r
 typedef TASK_LIST *PTASK_LIST;\r
 \r
@@ -206,8 +204,6 @@ public:
        static void GetApplicationTitle(CComboBox *cApplicationList, CString &rList, int nIndex = -1);\r
        static BOOL IsDefault(CString sz);\r
        static int GetApplicationIndex(CString szApplicationName, BOOL bSaveAndValidate, int *nSettingStyle);\r
-       static TASK_LIST m_TaskList[MAX_TASKS];\r
-       static DWORD m_dwTasks;\r
        static void InitApplicationList(CComboBox *cApplicationList);\r
        static int GetSavedSettingCount();\r
        static void ClearData(CString szCurrentApplication);\r
@@ -242,7 +238,9 @@ private:
        static void SetDllData();\r
        static CXkeymacsData m_XkeymacsData[MAX_APP];\r
        static void DeleteAllRegistryData();\r
-       static DWORD GetTaskList(PTASK_LIST pTask, DWORD dwNumTasks);\r
+       static TASK_LIST m_TaskList[MAX_TASKS];\r
+       static DWORD m_dwTasks;\r
+       static void GetTaskList();\r
        static BOOL IsCommandType(int nCommandType, LPCTSTR szKeyBind);\r
        static int KeyBind2Key(LPCTSTR szKey);\r
        static int KeyBind2CommandType(LPCTSTR szKeyBind);\r