gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
I need create process with C++ WinAPI for example, taskmgr.exe and window of taskmgr…
- User
I need create process with C++ WinAPI for example, taskmgr.exe and window of taskmgr must be child of window of program which creates process.
- Assistant
To create a process with C++ WinAPI, you can use the CreateProcess function. Here is an example code:
code#include <Windows.h> int main() { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); // Set the path to the executable you want to run wchar_t commandLine[] = L"C:\\Windows\\System32\\taskmgr.exe"; // Start the process BOOL result = CreateProcess(NULL, commandLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); if (!result) { // Handle error return 1; } // Get the handle of the window that created the process HWND parentWindow = GetForegroundWindow(); // Set the parent of the taskmgr window to be the parentWindow SetParent(pi.hProcess, parentWindow); // Wait for the process to exit WaitForSingleObject(pi.hProcess, INFINITE); // Close process and thread handles CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return 0; }