Solved

hWnd

Posted on 2000-05-14
7
865 Views
Last Modified: 2013-11-20
I would like my programm to change the url of my browser. I know I have to use:

::ShellExecute(hWnd, NULL, _T("http://www.experts-exchange.com"), NULL, NULL, SW_SHOWNORMAL);

but I don't know how to get  hWnd  for the browser window.
What I want is my programm to go onto the browser window and perform the change of the URL.

How can I do it?

Thanks in advance.
0
Comment
Question by:javiscript
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:JunHaan
ID: 2808466
javiscript,
Here is a possible solution :

You could use ::FindWindow() to get the handle of your browser. Although so, you'd need to know the exact title of your browser window, which is always different because the window title is dependent on the website's title too.

Lets say you have a Netscape browser up, and am in this page(which in this case, you are) with the title "MFC Programming Question - Netscape"...

You could insert this in one of your application's event handlers:

//Start of code

HWND hWnd; //This will hold the handle to the window

hWnd = ::FindWindow( NULL, "MFC Programming Question - Netscape" );
::ShellExecute( hWnd, NULL, _T("http://www.experts-exchange.com"), NULL, NULL, SW_SHOWNORMAL );

//End of code

This could only work if you know the exact title of the website.
I am looking forward to a better solution, of course...
Hope this helps, for the mean time! :)
0
 
LVL 2

Expert Comment

by:JunHaan
ID: 2808475
javiscript,
Here is a possible solution :

You could use ::FindWindow() to get the handle of your browser. Although so, you'd need to know the exact title of your browser window, which is always different because the window title is dependent on the website's title too.

Lets say you have a Netscape browser up, and am in this page(which in this case, you are) with the title "MFC Programming Question - Netscape"...

You could insert this in one of your application's event handlers:

//Start of code

HWND hWnd; //This will hold the handle to the window

hWnd = ::FindWindow( NULL, "MFC Programming Question - Netscape" );
::ShellExecute( hWnd, NULL, _T("http://www.experts-exchange.com"), NULL, NULL, SW_SHOWNORMAL );

//End of code

This could only work if you know the exact title of the website.
I am looking forward to a better solution, of course...
Hope this helps, for the mean time! :)
0
 
LVL 3

Expert Comment

by:_mb_
ID: 2808609
A better way would be, to find the window handle based on the instance handle, that ShellExecute() returns. Then you don't need to know the application title.

Here's the code:

HINSTANCE hInst = ::ShellExecute(hWnd, NULL, _T("http://www.experts-exchange.com"), NULL, NULL, SW_SHOWNORMAL);

HWND winHandle;

if( (winHandle = ::FindWindow(NULL, NULL) )
{
     do{
          if( hInst == ::GetWindowLong(winHandle, GWL_INSTANCE) )
               break;
     }while( (winHandle = ::GetWindow(winHandle, GW_HWNDNEXT) );
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Accepted Solution

by:
chensu earned 86 total points
ID: 2808647
"hwnd
Window handle to a parent window. This window receives any message boxes that an application produces. For example, an application may report an error by producing a message box."

The hWnd is not the window handle of the Web browser. You may use NULL or your window handle. In a CWnd derived class member function, use

hWnd = this->GetSafeHwnd();
0
 

Expert Comment

by:caiman23
ID: 2808695
I get an error about

GWL_INSTANCE: undeclared identifier.

What is GWL_INSTANCE?
How can I declare it?
0
 
LVL 3

Expert Comment

by:_mb_
ID: 2808817
Sorry,it must be GWL_HINSTANCE, it's an windows api constant.
By the way: I add a check, if we have the applications parent window.

if( (winHandle = ::FindWindow(NULL, NULL) )
{
     do{
          if( !GetParent(winHandle) )
          {
                if( hInst == ::GetWindowLong(winHandle, GWL_HINSTANCE) )
                     break;
          }
     }while( (winHandle = ::GetWindow(winHandle, GW_HWNDNEXT) );
}
0
 
LVL 2

Expert Comment

by:JunHaan
ID: 2809533
I would say chensu and mb is correct...
Here is a piece of code from mb and chensu's comment to try out... it works!

//Start code

HWND hWnd;
HWND winHandle;

hWnd = this->GetSafeHwnd();

HINSTANCE hInst = ::ShellExecute(hWnd, NULL, _T("http://www.experts-exchange.com"), NULL, NULL, SW_SHOWNORMAL);

if( winHandle = ::FindWindow(NULL, NULL) )
{
   do{
      if( !::GetParent(winHandle) )
               {
                    if( (long)hInst == ::GetWindowLong(winHandle,                                                                              GWL_HINSTANCE) )
                    break;
               }
      }while( winHandle = ::GetWindow(winHandle, GW_HWNDNEXT) );
}

//End of code

                                
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to monitor remote shell execution on linux 9 113
only14 challenge 19 89
java ^ examples 8 75
Is there a simple front-end menu system. 9 145
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

732 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