joeslow
asked on
Hide a CPL during CreateProcess
I have a program that starts the TimeDate.cpl (control panel applet?). I would like the Time/Date window to be hidden when it comes up. The following is the code I use on a button click:
STARTUPINFO startUpInfo;
PROCESS_INFORMATION procInfo;
BOOL success;
GetStartupInfo(&startUpInf o);
startUpInfo.dwFlags &= STARTF_USESHOWWINDOW;
startUpInfo.wShowWindow &= SW_HIDE;
success =
CreateProcess(
0, // pointer to name of executable module
"Rundll32.exe Shell32.dll,Control_RunDLL timedate.cpl",
// pointer to command line string
0, // pointer to process security attributes
0, // pointer to thread security attributes
FALSE, // handle inheritance flag
CREATE_NEW_CONSOLE, // creation flags
0, // pointer to new environment block
0, // pointer to current directory name
&startUpInfo, // pointer to STARTUPINFO
&procInfo // pointer to PROCESS_INFORMATION
);
It works, but the window is visible. WHat am I doing wrong?
Thank you,
Joe
STARTUPINFO startUpInfo;
PROCESS_INFORMATION procInfo;
BOOL success;
GetStartupInfo(&startUpInf
startUpInfo.dwFlags &= STARTF_USESHOWWINDOW;
startUpInfo.wShowWindow &= SW_HIDE;
success =
CreateProcess(
0, // pointer to name of executable module
"Rundll32.exe Shell32.dll,Control_RunDLL
// pointer to command line string
0, // pointer to process security attributes
0, // pointer to thread security attributes
FALSE, // handle inheritance flag
CREATE_NEW_CONSOLE, // creation flags
0, // pointer to new environment block
0, // pointer to current directory name
&startUpInfo, // pointer to STARTUPINFO
&procInfo // pointer to PROCESS_INFORMATION
);
It works, but the window is visible. WHat am I doing wrong?
Thank you,
Joe
The problem here is that timedate.cpl is launched by Rundll32.exe. SW_HIDE specifies Rundll32.exe to be hidden.
ASKER
Is there a way to do what I want. I am calling FindWindow to get the handle to it and then sending the SW_HIDE message to it? What I'd really like to do is not have it show at all...
Thank you,
Joe
Thank you,
Joe
Why do you want to hide it?
ASKER
I am trying to control a .cpl application from my own application. I am just using the TimeDate cpl to practice with until I get the real one. The real one is too complex for most users and I am writing a "simpler" version that will control the real one (hopefully hidden from the user). I don't have the source code for the .cpl.
Which cpl are you going to control? Can't you call Win32 API functions to achieve what you want? The way you are doing is not reliable.
ASKER
It's a third party cpl with no API of its own. I am using Win32 API functions to emulate clicking buttons, turning pages, selecting items in combo boxes, etc.
Try
::ShellExecute(hWnd, NULL, _T("timedate.cpl"), NULL, NULL, SW_HIDE);
::ShellExecute(hWnd, NULL, _T("timedate.cpl"), NULL, NULL, SW_HIDE);
That may not work. You may have to end up using FindWindow and ShowWindow(SW_HIDE).
ASKER
I think I am getting this error:
#define SE_ERR_NOASSOC 31
#define SE_ERR_NOASSOC 31
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.