获取进程图标 - GetProcessIconImage
函数简介
获取指定进程的图标,并返回图像句柄。
接口名称
GetProcessIconImage
DLL调用
int64_t GetProcessIconImage(int64_t instance, int64_t pid, int32_t targetWidth, int32_t targetHeight)
参数定义:
instance(长整型数): OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。pid(长整型数): 进程ID。targetWidth(整型数): 目标图标宽度(像素)。targetHeight(整型数): 目标图标高度(像素)。
示例:
// 获取进程ID为1234的进程图标,尺寸为32x32
int64_t iconHandle = GetProcessIconImage(instance, 1234, 32, 32);
if (iconHandle != 0) {
// 使用图标句柄进行绘制或其他操作
// 例如:使用 DrawGuiImagePtr 绘制图标
// DrawGuiImagePtr(instance, drawHandle, iconHandle, x, y, width, height);
// 使用完毕后释放图像资源
// FreeImage(instance, iconHandle);
} else {
printf("获取进程图标失败\n");
}
// 获取大尺寸图标(64x64)
int64_t largeIcon = GetProcessIconImage(instance, 1234, 64, 64);
// 获取小尺寸图标(16x16)
int64_t smallIcon = GetProcessIconImage(instance, 1234, 16, 16);
返回值
长整型数:
返回进程图标的image句柄,失败返回0
注意事项
- 图标会自动缩放到指定的目标宽度和高度
- 常用的图标尺寸:16x16(小图标)、32x32(标准图标)、64x64(大图标)
- 返回的图像句柄可以用于屏幕绘制等操作
- 如果进程没有图标或进程不存在,返回0
- 使用完毕后建议释放图像资源以节省内存
