mirror of
https://github.com/reactos/reactos.git
synced 2024-09-28 21:44:31 +00:00
Move GetModuleFileNameExW usage and create a helper function to obtain process image path
This commit is contained in:
parent
011af792ec
commit
657988f24a
|
@ -340,6 +340,10 @@ GetVersionInfoString(IN LPCWSTR szFileName,
|
||||||
OUT LPWSTR szBuffer,
|
OUT LPWSTR szBuffer,
|
||||||
IN UINT cbBufLen);
|
IN UINT cbBufLen);
|
||||||
|
|
||||||
|
BOOL GetProcessPath(IN DWORD dwProcessId,
|
||||||
|
OUT LPWSTR szBuffer,
|
||||||
|
IN DWORD cbBufLen);
|
||||||
|
|
||||||
class CTaskSwitchWnd :
|
class CTaskSwitchWnd :
|
||||||
public CComCoClass<CTaskSwitchWnd>,
|
public CComCoClass<CTaskSwitchWnd>,
|
||||||
public CComObjectRootEx<CComMultiThreadModelNoCS>,
|
public CComObjectRootEx<CComMultiThreadModelNoCS>,
|
||||||
|
@ -681,18 +685,14 @@ public:
|
||||||
WCHAR windowText[255];
|
WCHAR windowText[255];
|
||||||
|
|
||||||
/* Open process to retrieve the filename of the executable */
|
/* Open process to retrieve the filename of the executable */
|
||||||
HANDLE hTaskProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, TaskGroup->dwProcessId);
|
WCHAR ExePath[MAX_PATH] = {};
|
||||||
if(hTaskProc != NULL) {
|
if(GetProcessPath(TaskGroup->dwProcessId, ExePath, _countof(ExePath)))
|
||||||
WCHAR ExePath[MAX_PATH] = {};
|
{
|
||||||
|
if(GetVersionInfoString(ExePath, L"FileDescription", windowText, _countof(windowText)))
|
||||||
if(GetModuleFileNameExW(hTaskProc, NULL, ExePath, _countof(ExePath)) && GetVersionInfoString(ExePath, L"FileDescription", windowText, _countof(windowText))) {
|
|
||||||
tbbi.pszText = windowText;
|
tbbi.pszText = windowText;
|
||||||
}
|
|
||||||
|
|
||||||
if (ExtractIconExW(ExePath, 0, NULL, &icon, 1) <= 0)
|
if (ExtractIconExW(ExePath, 0, NULL, &icon, 1) <= 0)
|
||||||
icon = static_cast<HICON>(LoadImageW(NULL, MAKEINTRESOURCEW(OIC_SAMPLE), IMAGE_ICON, 0, 0, LR_SHARED | LR_DEFAULTSIZE));
|
icon = static_cast<HICON>(LoadImageW(NULL, MAKEINTRESOURCEW(OIC_SAMPLE), IMAGE_ICON, 0, 0, LR_SHARED | LR_DEFAULTSIZE));
|
||||||
|
|
||||||
CloseHandle(hTaskProc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tbbi.cbSize = sizeof(tbbi);
|
tbbi.cbSize = sizeof(tbbi);
|
||||||
|
@ -1007,18 +1007,15 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open process to retrieve the filename of the executable */
|
/* Open process to retrieve the filename of the executable */
|
||||||
HANDLE hTaskProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, TaskGroup->dwProcessId);
|
WCHAR ExePath[MAX_PATH] = {};
|
||||||
if(hTaskProc != NULL) {
|
if(GetProcessPath(TaskGroup->dwProcessId, ExePath, _countof(ExePath)))
|
||||||
WCHAR ExePath[MAX_PATH] = {};
|
{
|
||||||
|
if(GetVersionInfoString(ExePath, L"FileDescription", windowText, _countof(windowText))) {
|
||||||
if(GetModuleFileNameExW(hTaskProc, NULL, ExePath, _countof(ExePath)) && GetVersionInfoString(ExePath, L"FileDescription", windowText, _countof(windowText))) {
|
|
||||||
tbBtn.iString = (DWORD_PTR) windowText;
|
tbBtn.iString = (DWORD_PTR) windowText;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ExtractIconExW(ExePath, -1, NULL, &icon, 1) <= 0)
|
if (ExtractIconExW(ExePath, -1, NULL, &icon, 1) <= 0)
|
||||||
icon = static_cast<HICON>(LoadImageW(NULL, MAKEINTRESOURCEW(OIC_SAMPLE), IMAGE_ICON, 0, 0, LR_SHARED | LR_DEFAULTSIZE));
|
icon = static_cast<HICON>(LoadImageW(NULL, MAKEINTRESOURCEW(OIC_SAMPLE), IMAGE_ICON, 0, 0, LR_SHARED | LR_DEFAULTSIZE));
|
||||||
|
|
||||||
CloseHandle(hTaskProc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskGroup->IconIndex = ImageList_ReplaceIcon(m_ImageList, -1, icon);
|
TaskGroup->IconIndex = ImageList_ReplaceIcon(m_ImageList, -1, icon);
|
||||||
|
@ -1239,13 +1236,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
WCHAR ItemExePath[MAX_PATH] = {0};
|
WCHAR ItemExePath[MAX_PATH] = {0};
|
||||||
|
GetProcessPath(dwProcessId, ItemExePath, _countof(ItemExePath));
|
||||||
HANDLE hTaskProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwProcessId);
|
|
||||||
if (hTaskProc != NULL)
|
|
||||||
{
|
|
||||||
GetModuleFileNameExW(hTaskProc, NULL, ItemExePath, _countof(ItemExePath));
|
|
||||||
CloseHandle(hTaskProc);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Try to find an existing task group */
|
/* Try to find an existing task group */
|
||||||
TaskGroup = m_TaskGroups;
|
TaskGroup = m_TaskGroups;
|
||||||
|
@ -1260,12 +1251,7 @@ public:
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WCHAR ExePath[MAX_PATH] = {0};
|
WCHAR ExePath[MAX_PATH] = {0};
|
||||||
hTaskProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, TaskGroup->dwProcessId);
|
GetProcessPath(dwProcessId, ExePath, _countof(ExePath));
|
||||||
if (hTaskProc != NULL)
|
|
||||||
{
|
|
||||||
GetModuleFileNameExW(hTaskProc, NULL, ExePath, _countof(ExePath));
|
|
||||||
CloseHandle(hTaskProc);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!lstrcmpW(ExePath, ItemExePath))
|
if(!lstrcmpW(ExePath, ItemExePath))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
#include <winver.h>
|
#include <winver.h>
|
||||||
|
#include <psapi.h>
|
||||||
|
|
||||||
typedef struct _LANGCODEPAGE
|
typedef struct _LANGCODEPAGE
|
||||||
{
|
{
|
||||||
|
@ -257,3 +258,20 @@ GetVersionInfoString(IN LPCWSTR szFileName,
|
||||||
|
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL GetProcessPath(IN DWORD dwProcessId,
|
||||||
|
OUT LPWSTR szBuffer,
|
||||||
|
IN DWORD cbBufLen)
|
||||||
|
{
|
||||||
|
HANDLE hTaskProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwProcessId);
|
||||||
|
BOOL bRet = FALSE;
|
||||||
|
if(hTaskProc != NULL) {
|
||||||
|
if(GetModuleFileNameExW(hTaskProc, NULL, szBuffer, cbBufLen)) {
|
||||||
|
bRet = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle(hTaskProc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bRet;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue