调整使用 createprocess 创建的应用程序的大小和位置?

发布于 12-21 02:52 字数 1227 浏览 6 评论 0原文

我正在使用 createprocess 执行一个应用程序,比如记事本。

我需要覆盖该应用程序的默认大小和位置,因此我修改了 STARTUPINFO,并指定了 dwX、dwY、dwYSize、dwXSize 并将 STARTF_USEPOSITION||STARTF_USESIZE 添加到 dwFlags。

但该应用程序根本无法打开。
如果我放置 STARTF_USEPOSITION 和 STARTF_USESIZE 之一,应用程序将打开,但不会重新定位或调整大小。

有办法做到这一点吗?

{
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");
}

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");
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水水月牙2024-12-28 02:52:47

应用程序可能会忽略 STARTUPINFO 中的所有数据,或仅使用 wShowWindow

您可以尝试使用WaitForInputIdle,然后使用FindWindow,然后使用SetWindowPos

Application may ignore all data in STARTUPINFO, or use only wShowWindow.

You can try to use WaitForInputIdle, then FindWindow and then SetWindowPos.

向地狱狂奔2024-12-28 02:52:47

记事本似乎没有使用 GetStartupInfo() 来读取创建时传入的 STARTUPINFO 。我过去为解决这个问题所做的事情是将有效的PROCESS_INFORMATION传递给CreateProcess

由此,您将能够获取创建的进程的 PID。然后,您可以使用 EnumWindowsGetWindowThreadProcessId 进行轮询,直到找到窗口。这比 FindWindow 更准确,后者可能会与记事本的其他实例进行匹配。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文