Click here to Skip to main content
15,849,617 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

SW_HIDE doesn't work with ShellExecute on windows 8 and Internet Explorer 10. Does any one has any clue on the same.

I tried the below code.

C++
HINSTANCE hInstance = ShellExecute(NULL, _T("open"),_T("IExplore.exe"), _T("www.google.com"),  CString(szTemp), SW_HIDE);


Any help is appreciated
Posted
Updated 11-Oct-12 23:41pm
v2
Comments
Jochen Arndt 12-Oct-12 4:40am    
I don't have a solution. But the ShellExecute() documentation states for the nCmdShow parameter:
It is up to the application to decide how to handle it.
So this seems to be a behaviour of IE 10.
enhzflep 12-Oct-12 5:31am    
Yeah, just like Jochen said - it's up to the app to decide. Look again at the WinMain signature:

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)

I know I, for one never bother to check the value of nCmdShow on pet-projects. I always show the window, guess the MS apprentices engineers have made the same descision.
Susanta578 12-Oct-12 5:32am    
Thanks for the comment. I also came across the same statement. But just want to know if is there a way to force the parameter nCmdShow.

Try this:

C++
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};

si.cb = sizeof(cb);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;

if(::CreateProcess(
  NULL, // LPCTSTR lpApplicationName,
  _T("\"C:\\Program File\\Internet Explorer\\IExplore.exe\" http://www.google.com"), // LPTSTR lpCommandLine,
  NULL, // LPSECURITY_ATTRIBUTES lpProcessAttributes,
  NULL, //LPSECURITY_ATTRIBUTES lpThreadAttributes,
  FALSE, //bInheritHandles,
  NULL, //DWORD dwCreationFlags,
  NULL, //LPVOID lpEnvironment,
  NULL, //LPCTSTR lpCurrentDirectory,
  &si, //LPSTARTUPINFO lpStartupInfo,
  &pi, //LPPROCESS_INFORMATION lpProcessInformation))
{
    // if window is still visible - brute-force attack
    ::WaitForInputIdle(pi.hProcess, 10000);

    // find the main window
    DWORD dwProcessId = 0;
    HWND hWndMain = NULL;
    HWND hWnd = ::GetWindow(::GetDesktopWindow(), GW_CHILD);
    while(NULL != hWnd)
    {
        DWORD dwThreadId =
        ::GetWindowThreadProcessId(hWnd, &dwProcessId);
        if((dwThreadId == processInfo.dwThreadId) &&
       (dwProcessId == processInfo.dwProcessId))
       {
           const int nMaxCount = 256;
           TCHAR pszClassName[nMaxCount];
           ::GetClassName(hWnd, pszClassName, nMaxCount);
           if(!_tcsicmp(pszClassName, _T("find out the window class of IE using spy")))
           {
               hWndMain = hWnd;
               break;
           }
       }
       hWnd = ::GetWindow(hWnd, GW_HWNDNEXT);
    }    
    if(hWndMain) ::ShowWindow(hWndMain, SW_HIDE);

    ::CloseHandle(pi.hProcess);
    ::CloseHandle(pi.hThread);
}
 
Share this answer
 
v2
Comments
Susanta578 12-Oct-12 8:17am    
Thanks a lot for the solution. But it is not working. IE class name is "IEFrame".
chaau 14-Oct-12 18:40pm    
Try replacing the line:

if(hWndMain) ::SendMessage(hWndMain, WM_SHOWWINDOW, SW_HIDE, 0);

with:

::ShowWindow(hWndMain, SW_HIDE);

See my updated solution
I can't tell what szTemp is used for, but If you are trying to open a web page, just simply type:

C++
HINSTANCE hInstance;

hInstance = ShellExecute(NULL, TEXT("open"), TEXT("http://www.google.com.sa/"), NULL, NULL, SW_HIDE);


This code invokes the default web browser, many people use different browsers, and opens that URL.
 
Share this answer
 
Comments
Susanta578 16-Oct-12 10:16am    
Thanks for the solution. But SW_HIDE is not working in windows8 and IE 10 even if sztemp is null.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900