本帖最后由 durongze 于 2024-5-26 00:01 编辑
xhmeng 发表于 2024-5-24 12:44
可以另外编写一个控制台EXE,其中用Exec ShowHide方式调用要运行的EXE(文件名改为abc.dll 或者 abc.dat)
[C++] 纯文本查看 复制代码 #include <windows.h>
#include <stdio.h>
#include <string.h>
#include <winbase.h>
#include <iostream>
#include <string>
HANDLE StartProcess(LPCTSTR program, LPCTSTR args)
{
HANDLE hProcess = NULL;
PROCESS_INFORMATION processInfo;
STARTUPINFO startupInfo;
::ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
if (::CreateProcess(program, (LPTSTR)args,
NULL, // process security
NULL, // thread security
FALSE, // no inheritance
0, // no startup flags
NULL, // no special environment
NULL, // default startup directory
&startupInfo,
&processInfo)) {
hProcess = processInfo.hProcess;
HWND pwin = ::GetDlgItem(NULL, processInfo.dwProcessId);
RECT rect;
GetWindowRect(pwin, &rect);
int newX, newY, width, height;
width = rect.right - rect.left + 1;
height = rect.bottom - rect.top + 1;
MoveWindow(pwin, 0, 0, width, height, true);
UpdateWindow(pwin);
}
return hProcess;
}
----------------------------------------------
另外可以帮忙看下这个MoveWindow,无效果是咋回事吗?
----------------------------------------------
[C++] 纯文本查看 复制代码 int main (int argc, char** argv)
{
HWND hwnd = GetConsoleWindow();
RECT rect;
GetWindowRect(hwnd, &rect);
int newX, newY, width, height;
width = rect.right - rect.left + 1;
height = rect.bottom - rect.top + 1;
newX = 300, newY = 300;
getchar();
MoveWindow(hwnd, newX, newY, width, height, true);
getchar();
return 0;
}
------------------------
不知道为啥控制台是可以移动的,CreateProcess创建的进程就无法移动。 |