I'm executing an application say notepad, using createprocess.
I need to override the default size and position of that application so i modified STARTUPINFO, and specified dwX,dwY,dwYSize,dwXSize and added STARTF_USEPOSITION||STARTF_USESIZE to dwFlags.
But the application is not opening at all.
If i put one of STARTF_USEPOSITION and STARTF_USESIZE, the application opens but not reposition or resize.
Is there anyway to do that??
{
STARTUPINFO siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);
siStartupInfo.dwFlags = STARTF_USEPOSITION|STARTF_USESIZE;//||STARTF_USESHOWWINDOW;
siStartupInfo.wShowWindow=SW_SHOWDEFAULT;
siStartupInfo.dwX=900;
siStartupInfo.dwY=300;
siStartupInfo.dwXSize=1000;
siStartupInfo.dwYSize=1000;
if(CreateProcess("H:\\WINXP\\system32\\notepad.exe", // Application name
NULL , // Application arguments
0,
0,
FALSE,
NORMAL_PRIORITY_CLASS,
0,
0, // Working directory
&siStartupInfo,
&piProcessInfo) )
printf("Sucessful\n");
else
printf("Error");
}
Application may ignore all data in
STARTUPINFO
, or use onlywShowWindow
.You can try to use
WaitForInputIdle
, thenFindWindow
and thenSetWindowPos
.It seems notepad is not using
GetStartupInfo()
to read theSTARTUPINFO
passed in when it's created. Something I have done in the past to get round this is to pass a validPROCESS_INFORMATION
toCreateProcess
.From this, you will be able to get out the created process' PID. You can then poll with
EnumWindows
andGetWindowThreadProcessId
until you find the window. This is more accurate thanFindWindow
, which potentially would match against other instances of notepad.