18,124
社区成员
发帖
与我相关
我的任务
分享
DWORD PID ;
int iItem=0;
LV_ITEM lvitem, *plvitem;
char itemText[512],*pItem;
DWORD dword = GetWindowThreadProcessId(hwnd,&PID);
HANDLE hProcess=OpenProcess(PROCESS_ALL_ACCESS,false,PID);
if(hProcess != NULL)
{
for(i=0; i < total; i++)
{
lvitem.iItem = i;
lvitem.iSubItem = 1;
lvitem.pszText = szBuf;
lvitem.cchTextMax = 1024;
if(hwnd3 != NULL)
{
ListView_GetItem(hwnd3,&lvitem);
}else
{
HWND hwnd_box = FindWindowEx(0,0,ClassName,TitleName);
MessageBox(hwnd_box,"无法获取目标程序句柄!","友情提示",MB_ICONEXCLAMATION);
}
string str = szBuf;
printf("%s",szBuf);
/**
memset(itemText, 0, sizeof(itemText));
ListView_GetItemText(hwnd3,i,1,itemText,1024);
//string str = itemText;
printf("%s\n",itemText);
**/
//char比较是否相等
if (strcmp(szBuf,system)==0)
{
b+=1;
}
//判断char字符串是否包含
if (strstr(szText,hint1) != NULL)
{
a+=1;
}
}
CloseHandle(hProcess);
}
#include <windows.h>
#include <commctrl.h>
#pragma comment(lib, "comctl32")
#include <stdio.h>
#include <string>
#include <sstream>
#include <iostream>
#include <stddef.h>
#include <stdlib.h>
#include <cstdlib>
#include <cstddef>
using namespace std;
HWND hwnd0,hwnd1,hwnd2,hwnd3;
int total;
int a=0;
int b=0;
TCHAR* ClassName = TEXT("MyWindow");
TCHAR* TitleName = TEXT("任务管理器测试");
CHAR szText[100] = TEXT("总任务数:");
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.hbrBackground =(HBRUSH)COLOR_WINDOW; //窗口背景
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW); //鼠标
wndclass.hIcon = LoadIcon(NULL,IDI_QUESTION); //图标
wndclass.lpszClassName = ClassName;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.lpszMenuName = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW; //窗口风格
wndclass.lpfnWndProc = WndProc;
wndclass.hInstance = hInstance;
if( !RegisterClass(&wndclass) )
return 0;
hwnd = CreateWindow(
ClassName, // 窗口类名
TitleName, //窗口标题
WS_OVERLAPPEDWINDOW, //窗口风格
CW_USEDEFAULT, //初始的x坐标
CW_USEDEFAULT,
400, //初始的宽度
600,
NULL,
NULL,
hInstance,
NULL
);
//窗口居中
RECT rect;
int xLeft,yTop;
GetWindowRect(hwnd,&rect);
xLeft = (GetSystemMetrics(SM_CXFULLSCREEN)-(rect.right-rect.left))/2;
yTop = (GetSystemMetrics(SM_CYFULLSCREEN)-(rect.bottom-rect.top))/2;
SetWindowPos(hwnd, HWND_TOPMOST, xLeft,yTop,-1,-1, SWP_NOSIZE | SWP_NOZORDER);
ShowWindow( hwnd,nCmdShow );
UpdateWindow( hwnd );
while( GetMessage(&msg,NULL,0,0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
DWORD WINAPI PBThreadProc( LPVOID lpParameter )
{
HWND hwndPB = (HWND) lpParameter; //进度条的窗口句柄
PBRANGE range; //进度条的范围
hwnd1 = FindWindowEx(0,0,"#32770","Windows 任务管理器");
hwnd2 = FindWindowEx(hwnd1,NULL,"#32770","Processes");
hwnd3 = FindWindowEx(hwnd2,NULL,"SysListView32","进程");
/*
hwnd0 = FindWindowEx(0,0,"AfxMDIFrame42s","");
hwnd1 = FindWindowEx(hwnd0,NULL,"#32770","");
hwnd2 = FindWindowEx(hwnd1,NULL,"#32770","");
hwnd3 = FindWindowEx(hwnd2,NULL,"SysListView32","List1");
*/
if(!hwnd3)
{
HWND hwnd_box = FindWindowEx(0,0,ClassName,TitleName);
MessageBox(hwnd_box,"程序未启动!","友情提示",MB_ICONEXCLAMATION);
}
//获取总条数
total = SendMessage(hwnd3, LVM_GETITEMCOUNT, 0, 0);
SendMessage( hwndPB, PBM_SETRANGE ,
(WPARAM)0, (LPARAM)(MAKELPARAM(0,total)) );//设置进度条的范围
SendMessage( hwndPB, PBM_GETRANGE,
(WPARAM)TRUE,
(LPARAM)&range );
while(TRUE)
{
SendMessage( hwndPB, PBM_DELTAPOS, //设置进度条的新位置为当前位置加上范围的1/20
(WPARAM)1, (LPARAM)0 );//((range.iHigh-range.iLow)/20)
if( SendMessage( hwndPB, PBM_GETPOS, (WPARAM)0, (LPARAM)0 ) //取得进度条当前位置
== range.iHigh )
{
break;
}
}
//int number = ListView_GetItemCount(hwnd3);
}
DWORD WINAPI BeingCount()
{
}
LRESULT WINAPI WndProc( HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam )
{
HDC hdc;
PAINTSTRUCT ps;
HFONT hFont;
static HWND hwndPB;
switch( message )
{
case WM_CREATE:
{
InitCommonControls(); //确保已注册了进度条类PROGRESS_CLASS
hwndPB = CreateWindowEx(
0,
PROGRESS_CLASS,
NULL,
WS_CHILD | WS_VISIBLE,
0,0,0,0, //位置和大小在WM_SIZE中设置
hwnd,
(HMENU)0,
((LPCREATESTRUCT)lParam)->hInstance,
NULL);
CreateThread( //操作进度条的线程
NULL,
0,
(LPTHREAD_START_ROUTINE)PBThreadProc,
hwndPB,
0,
0
);
CreateThread( //循环对比线程
NULL,
0,
(LPTHREAD_START_ROUTINE)BeingCount,
hwndPB,
0,
0
);
return 0;
}
case WM_SIZE:
{
RECT rc;
GetClientRect(hwnd, &rc);
MoveWindow(
hwndPB,
10,//rc.left 距离左边距
35,//(rc.bottom - rc.top )/9 距离上边距
(rc.right - rc.left)-20,// 进度条长度
25,//(rc.bottom - rc.top )/12 进度条高度
TRUE
);
return 0;
}
case WM_PAINT:
{
CHAR hint[10];
//开始绘图并返回环境句柄
hdc = BeginPaint (hwnd, &ps);
hFont=CreateFont(20,0,0,0,0,0,0,0,GB2312_CHARSET,0,0,0,0,TEXT("微软雅黑"));
SetBkMode(hdc,TRANSPARENT);//字体背景不变
(HFONT)SelectObject(hdc,hFont);
TextOut(hdc, 10, 10, szText, lstrlen(szText));
TextOut(hdc, 80, 10, _itoa(total,hint,10), lstrlen(_itoa(total,hint,10)));
CHAR h[50] = TEXT("SYSTEM :");
TextOut(hdc, 10, 70, h, lstrlen(h));
CHAR h1[50] = TEXT("w_zhanghf :");
TextOut(hdc, 10, 95, h1, lstrlen(h1));
//if...else if...else
TCHAR szBuf[1024];
int i=0;
CHAR hint1[100] = TEXT("总任务数:");
CHAR system[100] = TEXT("SYSTEM");
DWORD PID ;
int iItem=0;
LV_ITEM lvitem, *plvitem;
char itemText[512],*pItem;
DWORD dword = GetWindowThreadProcessId(hwnd,&PID);
HANDLE hProcess=OpenProcess(PROCESS_ALL_ACCESS,false,PID);
if(hProcess != NULL)
{
for(i=0; i < total; i++)
{
lvitem.iItem = i;
lvitem.iSubItem = 1;
lvitem.pszText = szBuf;
lvitem.cchTextMax = 1024;
if(hwnd3 != NULL)
{
ListView_GetItem(hwnd3,&lvitem);
}else
{
HWND hwnd_box = FindWindowEx(0,0,ClassName,TitleName);
MessageBox(hwnd_box,"无法获取目标程序句柄!","友情提示",MB_ICONEXCLAMATION);
}
string str = szBuf;
printf("%s",szBuf);
/**
memset(itemText, 0, sizeof(itemText));
ListView_GetItemText(hwnd3,i,1,itemText,1024);
//string str = itemText;
printf("%s\n",itemText);
**/
//char比较是否相等
if (strcmp(szBuf,system)==0)
{
b+=1;
}
//判断char字符串是否包含
if (strstr(szText,hint1) != NULL)
{
a+=1;
}
}
CloseHandle(hProcess);
}
/**
if(!hProcess)
{
HWND hwnd_box = FindWindowEx(0,0,ClassName,TitleName);
MessageBox(hwnd_box,"操作失败!","友情提示",MB_ICONEXCLAMATION);
}else{
plvitem=(LVITEM*)VirtualAllocEx(hProcess, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE);
pItem=(char*)VirtualAllocEx(hProcess, NULL, 512, MEM_COMMIT, PAGE_READWRITE);
if ((!plvitem)||(!pItem))
{
HWND hwnd_box = FindWindowEx(0,0,ClassName,TitleName);
MessageBox(hwnd_box,"无法分配内存!","友情提示",MB_ICONEXCLAMATION);
}else{
lvitem.cchTextMax=512;
lvitem.iItem=1;
//lvitem.iSubItem=1;//PID
lvitem.iSubItem=1; //ProcessName
lvitem.pszText=pItem;
WriteProcessMemory(hProcess, plvitem, &lvitem, sizeof(LVITEM), NULL);
//SendMessage(hwnd3, LVM_GETITEMTEXT, (WPARAM)iItem, (LPARAM)plvitem);
ListView_GetItem(hwnd3,&lvitem);
ReadProcessMemory(hProcess, pItem, itemText, 512, NULL);
MessageBox(NULL,itemText,"itemText",NULL);
}
//释放内存
CloseHandle(hwnd3);
CloseHandle(hProcess);
VirtualFreeEx(hProcess, plvitem, 0, MEM_RELEASE);
VirtualFreeEx(hProcess, pItem, 0, MEM_RELEASE);
}
**/
TextOut(hdc, 82, 70,_itoa(b,hint,10), lstrlen(_itoa(b,hint,10)));
TextOut(hdc, 102, 95,_itoa(a,hint,10), lstrlen(_itoa(a,hint,10)));
EndPaint (hwnd, &ps) ;
return 0 ;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc( hwnd,message,wParam,lParam );
}