第一个SDK程序:显示系统当前进程
来源:互联网 发布:淘宝卖家查询工具 编辑:程序博客网 时间:2024/06/06 09:39
#include <windows.h>#include <stdio.h>#include <conio.h>#include <string>#include <tlhelp32.h> // 声明快照函数的头文件#include <hello.h> // 自定义头文件//***************************************************************************************using namespace std;int WINAPI WinMain(HINSTANCE hInstance, // 入口函数 HINSTANCE, LPSTR lpCmdLine, int nCmdShow ){ if (!InitApplication(hInstance)) // 应用初始化 return FALSE; if (!InitInstance(hInstance,nCmdShow)) // 实例初始化 return FALSE; MSG msg; while (GetMessage(&msg, NULL, 0, 0)) // 消息循环 { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam;}//***************************************************************************************BOOL InitApplication(HINSTANCE hInstance) // 应用初始化{ WNDCLASS wc; // Data structure of the window class wc.style = CS_HREDRAW|CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)MainWndProc; // Name of the Window Function wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon (NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = TEXT("My1stWClass"); // Name of the window class return RegisterClass(&wc);}//***************************************************************************************BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) // 实例初始化{ HWND hWnd = CreateWindow(TEXT("My1stWClass"), // Name of the window class TEXT("My First Window"), // Title of the window WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); if (!hWnd) return FALSE; ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE;}//***************************************************************************************// 窗口过程函数LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ PAINTSTRUCT ps; HDC hdc; PROCESSENTRY32 pe32; // 给系统内的所有进程拍快照 HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); // 在使用这个结构之前,先设置它的大小 pe32.dwSize = sizeof(pe32); if(hProcessSnap == INVALID_HANDLE_VALUE) { printf("CreateToolhelp32Snapshot调用失败!\n"); return -1; } // 遍历进程快照,轮流显示每个进程的信息 BOOL bMore = Process32First(hProcessSnap, &pe32); string process[1000]; int k = 0; while(bMore) { char temp[100]; sprintf(temp, "%05x %s", (unsigned)pe32.th32ProcessID, pe32.szExeFile); process[k++] = temp; bMore = Process32Next(hProcessSnap, &pe32); } CloseHandle(hProcessSnap); // 清除snapshot对象 switch (message) { case WM_PAINT: // 窗口客户区得刷新 { char title[100] = "进程ID: 模块名: "; hdc = BeginPaint (hWnd, &ps); //按照每行33个进程的格式输出 int over = 0, kk = 0; for (int j = 0;; j++) { for (int i = 0; i <= 33; i++) { if (!i) TextOut(hdc, 300 * j + 50, 20 * i, title, lstrlen(title)); else { TextOut(hdc, 300 * j + 50, 20 * i, process[kk].c_str(), lstrlen(process[kk].c_str())); kk++; if (kk == k) { over = 1; break; } } } if (over) break; } EndPaint (hWnd, &ps); return 0; } case WM_DESTROY: // 窗口关闭 { PostQuitMessage(0); return 0; } default: // 缺省消息的处理 return DefWindowProc(hWnd, message, wParam, lParam); }}
下面是hello.h的内容
//*************************************************************************************** // Prototype for the Window Function LRESULT CALLBACK MainWndProc(HWND,UINT,WPARAM,LPARAM);// Prototypes of functions called by WinMain BOOL InitApplication(HINSTANCE);BOOL InitInstance(HINSTANCE,int);//***************************************************************************************虽然我也感觉这头文件实在是没必要,不过老师要求也zhi
0 0
- 第一个SDK程序:显示系统当前进程
- 第一个wxPython程序:显示系统当前进程
- 第一个SDK程序
- 第一个windows sdk程序
- 开发第一个安卓程序(按钮显示一个当前的系统时间)
- 第一个Frasm程序 显示’G‘
- C# 系统分析器(第一个C#程序)
- 我的第一个WIN32 Platform SDK 程序
- DJI SDK开发——第一个程序
- LeapMotion SDK 开发之一 编写第一个LeapMotion VC++ 程序
- 查询系统当前消耗句柄最多的10个进程
- 显示当前进程
- 保证系统中只运行当前程序的一个进程
- rootfs中第一个程序init进程分析
- 列出系统当前进程
- 枚举当前系统进程
- 第一个init进程
- 编写安卓app程序显示当前系统时间
- Oracle数据库开发--oracle sql developer工具/存储过程/函数/触发器
- org.springframework.core.task.TaskRejectedException:Executor[]did not accept task异常解决
- maven的两种打包方式
- TCP 的三次握手和四次挥手
- 数组类 【】 == !=运算符重载
- 第一个SDK程序:显示系统当前进程
- 变量与内存的关系
- 51nod-1358-浮波那契(构造矩阵)
- Postgresql 索引
- JavaScript中的正则表达式
- TSAP传输服务访问点
- 理解angular2.0组件通讯
- kmp模板
- 爬虫-java-webmagic-搜视节目单(输出到单个文件)