Link to home
Start Free TrialLog in
Avatar of joeslow
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(&startUpInfo);
    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
Avatar of chensu
chensu
Flag of Canada image

The problem here is that timedate.cpl is launched by Rundll32.exe. SW_HIDE specifies Rundll32.exe to be hidden.
Avatar of joeslow
joeslow

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
Why do you want to hide it?
Avatar of joeslow

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.
Avatar of joeslow

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);
That may not work. You may have to end up using FindWindow and ShowWindow(SW_HIDE).
Avatar of joeslow

ASKER

I think I am getting this error:
#define SE_ERR_NOASSOC                  31
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial