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.
I am using visual studio 2013 with the default Windows Application settings.
EDIT: this is NOT a duplicate question, what I am asking here is WHY the same CreateProcess() function creates one time the process in background and one time in focus!
#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;
}