Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

hWnd

Posted on 2000-05-14
7
Medium Priority
?
878 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 23

Accepted Solution

by:
chensu earned 258 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

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!

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

609 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