Solved

hWnd

Posted on 2000-05-14
7
869 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
Industry Leaders: 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

707 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