问题
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");
}
回答1:
Application may ignore all data in STARTUPINFO
, or use only wShowWindow
.
You can try to use WaitForInputIdle
, then FindWindow
and then SetWindowPos
.
回答2:
It seems notepad is not using GetStartupInfo()
to read the STARTUPINFO
passed in when it's created. Something I have done in the past to get round this is to pass a valid PROCESS_INFORMATION
to CreateProcess
.
From this, you will be able to get out the created process' PID. You can then poll with EnumWindows
and GetWindowThreadProcessId
until you find the window. This is more accurate than FindWindow
, which potentially would match against other instances of notepad.
来源:https://stackoverflow.com/questions/8472764/resize-and-reposition-the-application-created-using-createprocess