?? pviewce.cpp
字號:
0, (DLGPROC)ModuleDialogProc);
SetFocus(g_hWndListViews[MODULELV]);
}
}
}
break;
case WM_NOTIFY:
{
NMHDR* pnmhdr = (NMHDR*)lParam;
if (LVN_ITEMACTIVATE == pnmhdr->code)
{
NMLISTVIEW* pnmlv = (NMLISTVIEW*)lParam;
if (pnmhdr->hwndFrom == g_hWndListViews[PROCESSLV])
{
DialogBox(g_hInst, MAKEINTRESOURCE(IDD_DLGPROCESS),
0, (DLGPROC)ProcessDialogProc);
SetFocus(g_hWndListViews[PROCESSLV]);
}
else if (pnmhdr->hwndFrom == g_hWndListViews[THREADLV])
{
DialogBox(g_hInst, MAKEINTRESOURCE(IDD_DLGTHREAD),
0, (DLGPROC)ThreadDialogProc);
SetFocus(g_hWndListViews[THREADLV]);
}
else if (pnmhdr->hwndFrom == g_hWndListViews[MODULELV])
{
DialogBox(g_hInst, MAKEINTRESOURCE(IDD_DLGMODULE),
0, (DLGPROC)ModuleDialogProc);
SetFocus(g_hWndListViews[MODULELV]);
}
}
}
break;
case WM_DESTROY:
CleanupListViewes();
PostQuitMessage(0);
break;
case WM_SIZE:
{
// Check to see if app is being Minimized
if (SIZE_MINIMIZED == wParam)
{
// App being minimized we'll just close instead
PostMessage(hWnd, WM_DESTROY, 0, 0);
}
}
break;
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
BOOL InitApplication()
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hIcon = NULL;
wc.hInstance = g_hInst;
wc.hCursor = NULL;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = pszAppName;
return RegisterClass(&wc);
}
BOOL InitInstance(
int iCmdShow
)
{
g_hWndMain = CreateWindow(pszAppName, pszTitle, WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, g_hInst, NULL);
if (NULL == g_hWndMain)
{
return FALSE;
}
ShowWindow(g_hWndMain, iCmdShow);
UpdateWindow(g_hWndMain);
return TRUE;
}
int WINAPI WinMain (
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nShowCmd
)
{
MSG msg = {0};
// Store the application instance in our global variable.
g_hInst = hInstance;
// Load strings
pszAppName = StringFromResources(IDS_PVIEWCE_APPNAME);
pszTitle = StringFromResources(IDS_PVIEWCE_TITLE);
// Use a globally named mutex to detect another instance of HelloSMS
const HANDLE hMutex = CreateMutex(0, 0, TEXT("_PVIEWCE_EXE_MUTEX_"));
// check the result code
if (0 != hMutex)
{
// No other instances running? Okay to proceed...
if (ERROR_ALREADY_EXISTS != GetLastError())
if (true)
{
// initialize the application
if (NULL != InitApplication())
{
// initialize the instance
if (TRUE == InitInstance(nShowCmd))
{
// begin message pump
while (GetMessage(&msg, NULL, 0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
// Fall through to Cleanup
}
else
{
// Already an instance running - attempt to switch to it and then exit
const HWND hwndExistingInstance = FindWindow(pszAppName, pszTitle);
if (NULL != hwndExistingInstance)
{
SetForegroundWindow((HWND)(((ULONG)hwndExistingInstance) | 0x1));
}
// Fall through to Cleanup
}
}
if (g_hProcessSnap != NULL)
{
VERIFY(CloseToolhelp32Snapshot(g_hProcessSnap));
}
if (g_pmsModuleSnap != NULL)
{
free(g_pmsModuleSnap);
}
if (0 != hMutex)
{
VERIFY(CloseHandle(hMutex));
}
return msg.wParam;
}
BOOL FillProcList(
HANDLE hProcessSnap
)
{
PROCESSENTRY32 pe32 = {0};
LVITEM lvi;
int iItem;
TCHAR tszBuffer[11];
ZeroMemory(&lvi, sizeof(lvi));
// Clear the ListView
SendMessage(g_hWndListViews[PROCESSLV], LVM_DELETEALLITEMS, 0, 0);
// Size of the PROCESSENTRY32 structure must be filled out before use.
pe32.dwSize = sizeof(PROCESSENTRY32);
// Walk the snapshot of processes and for each process, add it to the list
if (TRUE == Process32First(hProcessSnap, &pe32))
{
do
{
// Subitem 0 is the Process name
lvi.pszText = pe32.szExeFile;
lvi.cchTextMax = MAX_PATH;
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.lParam = pe32.th32ProcessID;
iItem = ListView_InsertItem(g_hWndListViews[PROCESSLV], &lvi);
_stprintf(tszBuffer, TEXT("0x%08x"), pe32.th32ProcessID);
lvi.mask = LVIF_TEXT;
ListView_SetItemText(g_hWndListViews[PROCESSLV], iItem, 1, tszBuffer);
} while (Process32Next(hProcessSnap, &pe32));
ListView_SetItemState(g_hWndListViews[PROCESSLV], 0,
LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
}
else
{
// Couldn't walk first node of list
return FALSE;
}
return TRUE;
}
static BOOL FillThreadList(
HANDLE hProcessSnap,
DWORD dwOwnerPID
)
{
THREADENTRY32 te32 = {0};
TCHAR tszBuffer[11];
LVITEM lvi;
int iItem;
// Prepare the LVITEM
ZeroMemory(&lvi, sizeof(lvi));
// Clear the ListView
SendMessage(g_hWndListViews[THREADLV], LVM_DELETEALLITEMS, 0, 0);
// Size of the THREADENTRY32 structure must be filled out before use.
te32.dwSize = sizeof(THREADENTRY32);
// Walk thread snapshot to find all threads of the process we want.
// If the thread belongs to the process we want, add its information
// to the display list.
if (Thread32First(hProcessSnap, &te32))
{
do
{
if (te32.th32OwnerProcessID == dwOwnerPID)
{
_stprintf(tszBuffer, TEXT("0x%08x"), te32.th32ThreadID);
// Subitem 0 is the Process name
lvi.pszText = tszBuffer;
lvi.cchTextMax = ARRAY_LENGTH(tszBuffer);
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.lParam = te32.th32ThreadID;
iItem = ListView_InsertItem(g_hWndListViews[THREADLV], &lvi);
_stprintf(tszBuffer, TEXT("0x%08x"), te32.tpBasePri);
lvi.mask = LVIF_TEXT;
ListView_SetItemText(g_hWndListViews[THREADLV], iItem, 1, tszBuffer);
}
} while (Thread32Next(hProcessSnap, &te32));
ListView_SetItemState(g_hWndListViews[THREADLV], 0,
LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
}
else
{
// Couldn't walk the list of threads.
return FALSE;
}
return TRUE;
}
static BOOL FillModuleList(
DWORD dwOwnerPID
)
{
MODULEENTRY32 me32 = {0};
LVITEM lvi;
int iItem;
TCHAR tszBuffer[11];
int iSnapIndex = PID2ArrayID(dwOwnerPID);
// sanity check
if (iSnapIndex < 0)
{
return FALSE;
}
// Prepare the LVITEM
ZeroMemory(&lvi, sizeof(lvi));
// Clear the ListView
SendMessage(g_hWndListViews[MODULELV], LVM_DELETEALLITEMS, 0, 0);
// Size of the MODULEENTRY32 structure must be filled out before use.
me32.dwSize = sizeof(MODULEENTRY32);
// Walk thread snapshot to find all modules of the process we want.
// If the module belongs to the process we want, add its information
// to the display list.
if (Module32First(g_pmsModuleSnap[iSnapIndex].hSnapShot, &me32))
{
do
{
// Subitem 0 is the Process name
lvi.pszText = me32.szModule;
lvi.cchTextMax = MAX_PATH;
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.lParam = me32.th32ModuleID;
iItem = ListView_InsertItem(g_hWndListViews[MODULELV], &lvi);
_stprintf(tszBuffer, TEXT("0x%08x"), me32.th32ModuleID);
lvi.mask = LVIF_TEXT;
ListView_SetItemText(g_hWndListViews[MODULELV], iItem, 1, tszBuffer);
} while (Module32Next(g_pmsModuleSnap[iSnapIndex].hSnapShot, &me32));
ListView_SetItemState(g_hWndListViews[MODULELV], 0,
LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
}
else
{
// Couldn't walk the list of modules.
return FALSE;
}
return TRUE;
}
static BOOL InitModuleSnap(
HANDLE hProcessSnap
)
{
PROCESSENTRY32 pe32 = {0};
int iCount = 0;
// Size of the PROCESSENTRY32 structure must be filled out before use.
pe32.dwSize = sizeof(PROCESSENTRY32);
// Walk the snapshot of processes and for each process, count it
if (Process32First(hProcessSnap, &pe32))
{
do
{
++iCount;
} while (Process32Next(hProcessSnap, &pe32));
}
else
{
return FALSE; // Couldn't walk the list of processes.
}
g_pmsModuleSnap = (MODSNAP*) malloc(sizeof(MODSNAP) * iCount);
if (g_pmsModuleSnap == NULL)
{
return FALSE;
}
// store the count
g_iTotalProcs = iCount;
// Walk the process list again, this time initializing the modinfo
iCount = 0;
if (Process32First(hProcessSnap, &pe32))
{
do
{
g_pmsModuleSnap[iCount].dwOwnerPID = pe32.th32ProcessID;
g_pmsModuleSnap[iCount].hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pe32.th32ProcessID);
// was the snapshot successful?
if (g_pmsModuleSnap[iCount].hSnapShot == (HANDLE) -1)
{
return FALSE;
}
++iCount;
} while (Process32Next(hProcessSnap, &pe32));
}
else
{
return FALSE; // Couldn't walk the list of processes.
}
return TRUE;
}
static int PID2ArrayID(
DWORD dwOwnerPID
)
{
// sanity check
ASSERT(g_pmsModuleSnap != NULL);
for (int i = 0; i < g_iTotalProcs; i++)
{
if (g_pmsModuleSnap[i].dwOwnerPID == dwOwnerPID)
{
return i;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -