问题描述
限时送ChatGPT账号..命令 CreateProcess 和命令 WaitForSingleObject可以打开图片吗?如果是 我怎样才能打开图像?我尝试打开,但我不知道在哪里打开路径
The Command CreateProcess With the command WaitForSingleObject can to open an image? If Yes How can I open the image? I tried to open but i don't know Where to put the path to open
if (CreateProcess(NULL, "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Paint.lnk", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
推荐答案
如果您只想使用默认应用打开现有图像,请使用 ShellExectue API.例如:
If you just want to open an existing image using defualt app then use ShellExectue API. For example:
ShellExecuteW(NULL, L"open", L"Z:\\cat.PNG", NULL, NULL, SW_SHOW);
您也可以使用 mspaint 使用相同的 API 打开图像:
You could also open image with mspaint using the same API:
ShellExecuteW(NULL, L"open", L"C:\\Windows\\system32\\mspaint.exe", L"Z:\\cat.PNG", NULL, SW_SHOW);
ShellExecuteEx 会让你等待完成过程.
ShellExecuteEx will let you wait for finishing process.
您可以使用 创建流程.正如@DavidHeffernan 指出的第二个参数 CreateProcess 应该指向可写内存,否则会引发访问冲突.为了清楚起见,我将省略第一个参数.示例:
You can do the same using CreateProcess. As @DavidHeffernan pointed out the second parameter of CreateProcess should point to writable memory else it will raise access violation. To make it clear I will just omit the first parameter. Example:
STARTUPINFOW process_startup_info{ 0 };
process_startup_info.cb = sizeof(process_startup_info); // setup size of strcture in bytes
PROCESS_INFORMATION process_info{ 0 };
wchar_t commandline_args[] = L"\"C:\\Windows\\system32\\mspaint.exe\" Z:\\cat.PNG";
if (CreateProcessW(NULL, commandline_args, NULL, NULL, TRUE, 0, NULL, NULL, &process_startup_info, &process_info))
{
//WaitForSingleObject(process_info.hProcess, INFINITE); // uncomment to wait till process finish
CloseHandle(process_info.hProcess);
CloseHandle(process_info.hThread);
}
我强烈建议阅读 这篇 CodeProject 文章(生成过程的新手基本指南).
I strongly recommend to read this CodeProject article (A newbie's elementary guide to spawning processes).
这篇关于命令 CreateProcess C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论