C# 无法获取Syslistview32 内容
 #include <windows.h>
#include <commctrl.h> 


TCHAR* ClassName = TEXT("FC数据下载 [运行监控] 日志检测"); //类名和窗口名
TCHAR* TitleName = TEXT("FC数据下载 [运行监控] 日志检测");
HWND hwnd;
int total,column;
HDC hdc;
PAINTSTRUCT ps;
HFONT hFont;
CHAR szText[100] = TEXT("日志总数:");
CHAR hint[20];
int i;
char itemText[100]={0};
LVITEM lvitem, *plvitem;
char ItemBuf[512],*pItem;
DWORD PID;
HANDLE hProcess;
static HWND hwndPB;

//FC数据下载 [运行监控] 
CHAR hint1[20] = TEXT("成功:");
CHAR hint2[20] = TEXT("失败:");
CHAR hint3[20] = TEXT("未关闭文件:");

int a = 0;
int b = 0;
int c = 0;

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpszCmdLine,int nCmdShow){
     HWND hwnd; //主窗口句柄,在CreateWindow中赋值
     MSG msg; //消息变量,在GetMessage中使用
     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; //窗口的额外参数.用于基于同一窗口类的窗口各自区分.
     //在自定义对话框类时必须指定为DLGWINDOWEXTRA的大小
     wndclass.lpszMenuName = NULL; //菜单名.可以用作子窗口的id
     wndclass.style =CS_HREDRAW | CS_VREDRAW; //窗口风格
     wndclass.lpfnWndProc = WndProc; //窗口过程
     wndclass.hInstance = hInstance; //包含窗口过程的实例句柄
     if( !RegisterClass(&wndclass) ){ //注册窗口类
         MessageBox(NULL, "窗口注册失败!","错误",MB_ICONEXCLAMATION|MB_OK);
         return 0;
     } 
     hwnd = CreateWindowEx( //创建窗口
         WS_EX_TOPMOST,
         ClassName, //窗口类名
         TitleName, //窗口标题
         WS_OVERLAPPEDWINDOW, //窗口风格
         CW_USEDEFAULT, //初始的x坐标
         CW_USEDEFAULT, //初始的y坐标
         500, //初始的宽度
         700, //初始的高度
         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 ); //更新窗口
     if(hwnd == NULL) {
        MessageBox(NULL, "窗口创建失败!","错误",MB_ICONEXCLAMATION|MB_OK);
        return 0;
     }
     while( GetMessage(&msg,NULL,0,0) )     {  //消息循环
         TranslateMessage(&msg); //将WM_XXXKEYXXX消息翻译为WM_CHAR消息
         DispatchMessage(&msg); //传递消息到窗口过程
     }
    return msg.wParam; //返回
}


DWORD WINAPI PBThreadProc( LPVOID lpParameter ){

     //FC数据下载 [运行监控]
     hwnd = FindWindowEx(0,0,"Afx:400000:b:10003:6:e002c3","FC数据下载 [ 运行监控 ]");
     hwnd = FindWindowEx(hwnd,NULL,"AfxMDIFrame42s","");
     hwnd = FindWindowEx(hwnd,NULL,"#32770","");
     hwnd = FindWindowEx(hwnd,NULL,"#32770","");
     hwnd = FindWindowEx(hwnd,NULL,"SysListView32","List1");

     if(!hwnd){
         HWND hwnd_box = FindWindowEx(0,0,ClassName,TitleName);
         MessageBox(hwnd_box,"FC数据下载 [运行监控] 未启动","友情提示",MB_ICONEXCLAMATION);
     }
     //获取总条数
     total = SendMessage(hwnd, LVM_GETITEMCOUNT, 0, 0);


     HWND hwndPB = (HWND) lpParameter; //进度条的窗口句柄
     PBRANGE range; //进度条的范围
     SendMessage( hwndPB, PBM_SETRANGE, //设置进度条的范围
     (WPARAM)0, (LPARAM)(MAKELPARAM(0,total)) );
     SendMessage( hwndPB, PBM_GETRANGE, //获取进度条的范围
     (WPARAM)TRUE, //TRUE 表示返回值为范围的最小值,FALSE表示返回最大值
     (LPARAM)&range );
     while(TRUE){
         SendMessage( hwndPB, PBM_DELTAPOS, //设置进度条的新位置为当前位置加上范围的1/40
         (WPARAM)1, (LPARAM)0 );//((range.iHigh-range.iLow)/20)
         if( SendMessage( hwndPB, PBM_GETPOS, (WPARAM)0, (LPARAM)0 ) == range.iHigh ){ //取得进度条当前位置
             break;
        }
     }
}

LRESULT WINAPI WndProc( HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam ){

    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
            );
         return 0;
         }

        case WM_PAINT:{
             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, 10, 75, hint1, lstrlen(hint1));
             TextOut(hdc, 10, 98, hint2, lstrlen(hint2));
             TextOut(hdc, 10, 125, hint3, lstrlen(hint3));

             //FC数据下载 [运行监控]
             hwnd = FindWindowEx(0,0,"Afx:400000:b:10003:6:e002c3","FC数据下载 [ 运行监控 ]");
             hwnd = FindWindowEx(hwnd,NULL,"AfxMDIFrame42s","");
             hwnd = FindWindowEx(hwnd,NULL,"#32770","");
             hwnd = FindWindowEx(hwnd,NULL,"#32770","");
             hwnd = FindWindowEx(hwnd,NULL,"SysListView32","List1");

             total = ListView_GetItemCount(hwnd);
             TextOut(hdc, 80, 10, _itoa(total,hint,10), lstrlen(_itoa(total,hint,10)));
             GetWindowThreadProcessId(hwnd,&PID);
             hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,PID);   
             plvitem=(LVITEM*)VirtualAllocEx(hProcess, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE);
             pItem=(char*)VirtualAllocEx(hProcess, NULL, 128, MEM_COMMIT, PAGE_READWRITE);  
             if(hProcess != NULL){
                 int j = 155;
                 for(i=0; i < total; i++){ 
                     lvitem.mask = LVIF_TEXT;
                     lvitem.cchTextMax=512;
                     //FC数据下载 [运行监控]
                     lvitem.iSubItem=2; 
                     lvitem.pszText=pItem;
                     WriteProcessMemory(hProcess, plvitem, &lvitem, sizeof(LVITEM), NULL);
                    SendMessage(hwnd, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)plvitem);
                     ReadProcessMemory(hProcess, pItem, ItemBuf, 512, NULL);


                     //FC数据下载 [运行监控]
                    if(strcmp(ItemBuf,"成功") == 0){ // strcmp 相等 
                         a+=1;
                    } 
                    if(strcmp(ItemBuf,"失败") == 0){ // strstr 包含 
                         b+=1;
                    } 
                    if(strstr(ItemBuf,"Z:") != NULL && strstr(ItemBuf,".") != NULL ){ //&& strstr(ItemBuf,".") != NULL 
                         c+=1;
                         //打印出未关闭的文件路径 
                         TextOut(hdc, 10, j, ItemBuf, lstrlen(ItemBuf));
                         j+=30;
                    }
                }

                //FC数据下载 [运行监控]
                TextOut(hdc, 60, 76, _itoa(a,hint,10), lstrlen(_itoa(a,hint,10)));
                TextOut(hdc, 60, 99, _itoa(b,hint,10), lstrlen(_itoa(b,hint,10)));
                TextOut(hdc, 98, 125, _itoa(c,hint,10), lstrlen(_itoa(c,hint,10)));
             }
             CloseHandle(hwnd);
             CloseHandle(hProcess);
             VirtualFreeEx(hProcess, plvitem, 0, MEM_RELEASE);
             VirtualFreeEx(hProcess, pItem, 0, MEM_RELEASE);
             return 0 ;
        } 

        case WM_SIZE:{
            RECT rc;
            GetClientRect(hwnd, &rc);
            MoveWindow(
                 hwndPB,
                 10,//rc.left 距离左边距
                 40,//(rc.bottom - rc.top )/9 距离上边距
                 (rc.right - rc.left)-20,// 进度条长度
                 25,//(rc.bottom - rc.top )/12  进度条高度
                 TRUE);
         return 0;
         }
         case WM_DESTROY:
            PostQuitMessage(0);
             return 0;
    }
    return DefWindowProc( hwnd,message,wParam,lParam );
}

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!