使用创建过程和ms绘画打开图像

问题描述 投票:-1回答:1

嗨,我有任务用mspaint(Microsoft Paint)打开图像,并用创建过程(windows.h)

我该怎么做?我尝试:

STARTUPINFO info = { sizeof(info) };
    PROCESS_INFORMATION processInfo;
    std::string p = pic.getPath();
    if (CreateProcessA(LPCSTR(p),"C:\\Windows\\system32\\mspaint.exe", NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo))
    {
        WaitForSingleObject(processInfo.hProcess, INFINITE);
        CloseHandle(processInfo.hProcess);
        CloseHandle(processInfo.hThread);
    }

还有另一件事,我需要使用控件c将其关闭,并确保我的exe文件不会关闭我也该怎么做?

谢谢

c++ windows winapi paint createprocess
1个回答
0
投票

您对CreateProcessA()的参数全部错误。请尝试以下方法:

STARTUPINFO info = { sizeof(info) };
PROCESS_INFORMATION processInfo;
std::string p = pic.getPath();
std::string cmd = "C:\\Windows\\system32\\mspaint.exe \"" + p + "\"";
if (CreateProcessA(NULL, const_cast<LPSTR>(cmd.c_str()), NULL, NULL, FALSE, 0, NULL, NULL, &info, &processInfo))
{
    WaitForSingleObject(processInfo.hProcess, INFINITE);
    CloseHandle(processInfo.hProcess);
    CloseHandle(processInfo.hThread);
}

关于关闭MSPaint进程,您无需为此使用CTRL-C。查找属于MSPaint窗口的HWND,然后向其发送WM_CLOSEWM_QUIT消息。 CreateProcess()告诉您生成的进程的主线程ID,使用EnumThreadWindows()查找属于该线程的HWND。然后使用SendMessage()向其发送消息。

© www.soinside.com 2019 - 2024. All rights reserved.