Constantin Constantin - 4 years ago 148
C++ Question

Force to show a window from a process started with SW_HIDE as STARTUPINFO?

I want to create/show a window from a DLL, but this DLL is loaded from a process which was created with STARTUPINFOW::wShowWindow set to

SW_HIDE
before. Unfortunately I can't change any of the code which creates the process:

STARTUPINFOW startupInfo;
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
startupInfo.dwFlags = STARTF_USESHOWWINDOW;
startupInfo.wShowWindow = SW_HIDE;
PROCESS_INFORMATION processInfo;
memset(&processInfo, 0, sizeof(processInfo));

CreateProcessW(NULL, getCommand(), NULL, NULL, FALSE, 0, NULL, getWorkingDir(), &startupInfo, &processInfo);


I'm creating the window normally using Win32 api:

ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProcRouter;
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = L"Window";
RegisterClassEx(&wc);
DWORD dwStyle = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
RECT WindowRect;
WindowRect.left = (long)0;
WindowRect.right = (long)width;
WindowRect.top = (long)0;
WindowRect.bottom = (long)height;
AdjustWindowRect(&WindowRect, dwStyle, FALSE);
HWND handle = CreateWindowEx(0,
wc.lpszClassName,
L"Title",
dwStyle,
0, 0,
WindowRect.right - WindowRect.left,
WindowRect.bottom - WindowRect.top,
nullptr,
nullptr,
wc.hInstance,
(void*) this);
ShowWindow(handle, SW_SHOW);
SetFocus(handle);


But the window is not shown; only if I launch the parent process manually (so the
STARTUPINFO
code from the first code-snippet is never executed).
The only solutions I know about are either changing the code which creates the process or creating a entirely new process (without
SW_HIDE
as
STARTUPINFO
) inside my DLL.

So I was wondering if there is any way to force showing the window, even that the parent process is using
SW_HIDE
as
STARTUPINFO::wShowWindow
?

Answer Source

The STARTUPINFO value is only used the first time a process calls ShowWindow(), so if you call it a second time your window will be shown.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download