?
Solved

Open Default Browser in a hidden status

Posted on 2005-04-19
9
Medium Priority
?
367 Views
Last Modified: 2013-12-03
Hi,

I will need to open a web broswer in a hidden state and navigate to a URL. I tried to use
ShellExecute(NULL,"open","http://www.google.com",NULL,NULL,SW_HIDE);
However, the browser window will still be visible. (Just like if I use SW_SHOWNORMAL)

Is there anyway to hide the browser window?


Thanks
0
Comment
Question by:ubiwebdev
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 3

Expert Comment

by:Darrylsh
ID: 13824914
Hate to sound suspicious, but what would be the legitimate use for this?  I can't think of any.  Sounds to me like you want to open a browser and direct it to a malicious site, without the user knowing!
0
 

Author Comment

by:ubiwebdev
ID: 13825019
Well, basically, it is full window application that needs to pull some data from our own web server to pre-populate the fields. The reason I need to open the default browser is because I will need to use cookies.

Hate to say that too, however, if you can not answer the question, please don't waste your time to put meaningless comments.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13825194
The browser appears even if you pass SW_HIDE because the flag is only informative, it is simply passed to the associated application. It is up to the application to decide how to handle it.

What you can do here that will work is to have a system wide hook (a CBT hook will be enough) where you'll hook the window creation and if it's your IE instance (identifiable by classname and window title) will set your wndproc for it. There, in the wndproc you'll have to override some displayng messages to make it hidden.

The CBTProc can look like:

LRESULT CALLBACK MyCbtProc(int nCode, WPARAM wParam, LPARAM lParam)
{
      switch(nCode)
      {
            case HCBT_CREATEWND:
                  TCHAR      szClassName[MAX_PATH];
                  HWND      hDlg = (HWND)wParam;
                        
                  GetClassName(hDlg, szClassName, sizeof(szClassName) - 1);
                  if(!lstrcmpi(szClassName, _T("#32770"))) //here the IE class name
                  {
                        GetWindowText(hDlg, szClassName, sizeof(szClassName) - 1);
                        if(!lstrcmpi(szClassName, "Message Source"))  //here the window title
                        {
                              // Save away old proc
                              //
                              SetProp(hDlg, _T("OldWndProc"), (HANDLE) GetWindowLong(hDlg, GWL_WNDPROC));
                              SetWindowLong(hDlg, GWL_WNDPROC, (DWORD)MyIEWndProc);
                              break;
                        }
                  }
            }
      }

      return CallNextHookEx(g_hCBT, nCode, wParam, lParam);
}


And the wndproc:

LRESULT CALLBACK MyIEWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
      WNDPROC      lpOldProc;
      
      lpOldProc = (WNDPROC)GetProp(hWnd, _T("OldWndProc"));

      if(msg == WM_WINDOWPOSCHANGING)
      {
            WINDOWPOS      *pWPos = (WINDOWPOS*)lParam;
            
            pWPos->flags |= SWP_HIDEWINDOW | SWP_NOACTIVATE;
            pWPos->flags &= ~SWP_NOZORDER;
            pWPos->hwndInsertAfter = g_PluginData.hOEWnd;//HWND_BOTTOM;
      }

      return CallWindowProc(lpOldProc, hWnd, msg, wParam, lParam);
}
0
Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

 

Author Comment

by:ubiwebdev
ID: 13825295
Thanks nonubik.
However, I can not know which application will be launched. It can be IE, Firefox, Opera, etc. It all depends on user's setting. Thus, I can not guess which message is the message that I should play with.
Instead of ShellExecute or ShellExecuteEx, is there another way I can launch the default browser and hide it? Or, is there a way that I can get the hWnd after the ShellExecute and then hide it?

Thanks.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13825391
> I can not know which application will be launched
Then do not check the classname, only try to search your page title as substring in the browser's window title.

>Thus, I can not guess which message is the message that I should play with.
The WM_WINDOWPOSCHANGING code I've posted works even for modal dialog boxes ;)

> is there a way that I can get the hWnd after the ShellExecute and then hide it?
I can't think of any right now..
0
 
LVL 3

Expert Comment

by:Darrylsh
ID: 13826382
>> "Hate to say that too, however, if you can not answer the question, please don't waste >> your time to put meaningless comments."

It wasn't a meaningless comment; before I decide to provide help, I want to make sure I am not helping someone create a malicious program.  That would be irresponsible of me.  

Anyway, I would suggest you use a web browser control in your app, that way you can
1. keep it hidden
2. be sure of what browser it is ( IE explorer)
3. still use cookies
0
 

Author Comment

by:ubiwebdev
ID: 13826664
Thanks Darrylsh.

Actually, the current code is using the IE control. However, since these cookies are shared among multiple windows application and web application, we will need to use the default browser. Otherwise, more than one set of cookies will be created for different browser and their value will be different too.

Anyway, the only way I found so far is to search the registry to get the default browser and then use CreateProcess to launch the browser with the SW_HIDE. It worked. However, I was just wondering if there is cleaner/easier way.

0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 14394819
PAQed with points refunded (125)

modulo
Community Support Moderator
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question