如何使CreateProcess在焦点而不是在后台打开新进程 [英] how to make CreateProcess open new process in focus and not in background

查看:1052
本文介绍了如何使CreateProcess在焦点而不是在后台打开新进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个非常简单的Win程序。它打开记事本,5秒后打开计算。
问题是总是第一个程序在后台打开而不是焦点(见图片)。第二个程序打开焦点。我一直在想这一会儿,我不知道为什么会发生或如何打开第一个程序的焦点。

I created a very simple Win program. it opens notepad and after 5 seconds it opens calc. the problem is that always the first program opens in background and not in focus (see the picture). the second program opens in focus. i've been wondering about this for a while and i can't figure out why it happens or how to open the first program in focus.

我使用的视觉工作室2013的默认Windows应用程序设置。

I am using visual studio 2013 with the default Windows Application settings.

编辑:这不是一个重复的问题,我要求这里是为什么同样的CreateProcess

#include <Windows.h>


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    STARTUPINFO si = { 0 };
    PROCESS_INFORMATION pi = { 0 };
    si.cb = sizeof(si);
    CreateProcess(L"c:\\windows\\system32\\notepad.exe", NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);

    Sleep(5000);

    STARTUPINFO si2 = { 0 };
    PROCESS_INFORMATION pi2 = { 0 };
    si2.cb = sizeof(si2);
    CreateProcess(L"c:\\windows\\system32\\calc.exe", NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si2, &pi2);

    return 0;
}


推荐答案

,非常奇怪,我不知道为什么它的工作,但它的工作原理。

found a way to solve this, very strange, and i have no idea why it works, but it works.

如果我添加:

MSG msg;
TranslateMessage(&msg);

在WinMain中,那么我创建的进程得到焦点,很奇怪。有人可以解释它为什么工作吗?

in the WinMain, then the process I create gets in focus, very strange. can someone explain why it works?

这篇关于如何使CreateProcess在焦点而不是在后台打开新进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆