Launching and Closing the Internet Explorer from Your VC++ App

Environment: Visual C++

Introduction

The Vice President (academic) of Valley View University (in Ghana) wanted me to develop a software application to monitor the transactions that go on in our newly established Internet cafe center.

The problem definition or specification requires launching and closing the IE from the application. Initially, I decided to create a custom browser, but I felt it would be more convient to use the standard browser. The ShellExecute() function could launch the IE from my program, but what about closing the IE from my program? With the help of MSDN, I found that the BroadcastSystemMessage() fuction could do the job. For more on BroadcastSystemMessage(), check MSDN.

I chose BSF_POSTMESSAGE, WM_CLOSE, BSM_APPLICATIONS, NULL, and NULL as parameters of BroadcastSystemMessage() function.

The codes are below:

/*lounching IE, you need an html file on your pc or if you
  have access to the net you can use a remote address*/
void lounchIE()
{
  HWND h=FindWindowEx(NULL,NULL,NULL,
                      "Microsoft Internet Explorer") ;
  ShellExecute(h,"open","C:\\simple.html",
               NULL,NULL,SW_SHOWNORMAL);

}

//closing IE and all applications

void CloseIE()
{
  int app=BSM_APPLICATIONS;
  unsigned long  bsm_app=(unsigned long )app;
  BroadcastSystemMessage(BSF_POSTMESSAGE,&bsm_app,
                         WM_CLOSE,NULL,NULL);

}

Problem: The shot-down window may display. When you choose Cancel, you can only run your application from the icons of the applications on the Desktop.



Comments

  • A solution for the release version...

    Posted by Legacy on 06/07/2002 12:00am

    Originally posted by: BN37

    After looking closer at my code, I found out that the function itself was not the problem. I checked the ON_COMMAND line used to initiate the block of code. At that time, I had found my mistake: it said ON_COMMAND_EX(...) instead of ON_COMMAND(...). If any of you programmers have a similar problem, it wouldn't hurt to check the simplest things.

    Reply
  • Compiled Release Version Errors

    Posted by Legacy on 06/06/2002 12:00am

    Originally posted by: BN37

    I have been looking for code that will open other apps on the user's computer and web pages/sites on the net but every version of code when compiled into the release version through VC++6 (though debug version seems to work just fine)and executed loads the desired target but then brings up an error and then closes the app which the newly opened app or page has been called from.  Could someone help me here.  I would greatly appreciate it.
    
    

    Below are some versions of the code that I have experiemented with:

    (Version 1)
    {
    HWND h=FindWindowEx(NULL,NULL,NULL,
    "Microsoft Internet Explorer") ;

    ShellExecute(h,"open","C:\\",
    NULL,NULL,SW_SHOWNORMAL);
    }

    (Version 2)

    {
    CString strFile = "C:/";
    ShellExecute(NULL, "open", (LPCTSTR)strFile, "", "", SW_SHOW);
    }

    Reply
  • Alternative simple way to close explorer

    Posted by Legacy on 06/04/2002 12:00am

    Originally posted by: Martynas

    Hello,

    I close epxlorer in simple way:

    HWND hExplorer = ::FindWindow( "IEFrame", NULL );
    if ( hExplorer == NULL )
    hExplorer = ::FindWindow( "CabinetWClass", NULL );

    if( hExplorer != NULL )
    {
    ::PostMessage( hExplorer, WM_CLOSE, 0, 0 );
    }

    This can also be put into a loop (with some precautions) to close all explorer instances. If you want I can present full code for it.

    • Important

      Posted by ammar_amk on 07/13/2004 09:58am

      Can I please know how to send the selected text from Internet Explorer to our VC++ program

      Reply
    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Best-in-Class organizations execute on a strategy that supports the multi-channel nature of customer requests. These leading organizations do not just open up their service infrastructures to accommodate new channels, but also empower their teams to deliver an effective and consistent experience regardless of the channel selected by the customer. This document will highlight the key business capabilities that support a Best-in-Class customer engagement strategy.

  • Live Event Date: August 19, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT You deployed your app with the Bluemix PaaS and it's gaining some serious traction, so it's time to make some tweaks. Did you design your application in a way that it can scale in the cloud? Were you even thinking about the cloud when you built the app? If not, chances are your app is going to break. Check out this upcoming webcast to learn various techniques for designing applications that will scale successfully in Bluemix, for the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds