xhmeng 发表于 2024-5-24 12:44 可以另外编写一个控制台EXE,其中用Exec ShowHide方式调用要运行的EXE(文件名改为abc.dll 或者 abc.dat) Winexec("D:\\notepad.exe 1.txt",WM_SHOWWINDOW);
xhmeng 发表于 2024-5-24 12:44 可以另外编写一个控制台EXE,其中用Exec ShowHide方式调用要运行的EXE(文件名改为abc.dll 或者 abc.dat) [C++] 纯文本查看 复制代码#include #include #include #include #include #include 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创建的进程就无法移动。
[Asm] 纯文本查看 复制代码 #include #include #include #include #include [i] #include 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; } 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; }