 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Gav Guest
|
Posted: Sat Mar 05, 2005 3:23 am Post subject: Opening up Web Browsers inside my App |
|
|
Hi All,
I think I asked this many moons ago but was unsolved, I would still like to
know if it is possible please :)
I have a program I created in C++Builder 3 that opens up all installed Web
Browsers on a users computer with a specified URL (local or www).
This is good for web designers wanting to test their look and feel of web
pages in as many browsers as possible.
It works fine as it is, but opens all these Web Browser in their own space
as would normally happen if the user clicked on them separately.
What I would like to happen is each Web Browser opens up either in a new
form or their own Tab within my program UI and not outside
of the program as they do now.
Any Ideas ?
Thanks
To have a look at what the program does now go to
http://minitutorials.com/apps/mtbrowser/index.shtml and download it from
there.
Opinions on improvements also welcome.
--
Gavin McDonald
www.minitutorials.com
|
|
| Back to top |
|
 |
Gav Guest
|
Posted: Mon Mar 07, 2005 6:36 am Post subject: Re: Opening up Web Browsers inside my App |
|
|
Should I have asked this in another group maybe ?
Thanks
Gav...
"Gav" wrote in message news:422926aa$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Hi All,
I think I asked this many moons ago but was unsolved, I would still like
to know if it is possible please :)
I have a program I created in C++Builder 3 that opens up all installed Web
Browsers on a users computer with a specified URL (local or www).
This is good for web designers wanting to test their look and feel of web
pages in as many browsers as possible.
It works fine as it is, but opens all these Web Browser in their own space
as would normally happen if the user clicked on them separately.
What I would like to happen is each Web Browser opens up either in a new
form or their own Tab within my program UI and not outside
of the program as they do now.
Any Ideas ?
Thanks
To have a look at what the program does now go to
http://minitutorials.com/apps/mtbrowser/index.shtml and download it from
there.
Opinions on improvements also welcome.
--
Gavin McDonald
www.minitutorials.com
|
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Mon Mar 07, 2005 10:47 am Post subject: Re: Opening up Web Browsers inside my App |
|
|
Gav wrote:
| Quote: | I have a program I created in C++Builder 3 that opens up all installed Web
Browsers on a users computer with a specified URL (local or www).
To have a look at what the program does now go to
http://minitutorials.com/apps/mtbrowser/index.shtml and download it from
there.
|
Is that the same program ? I had a look but did not download
it. Does it come with source for bcb3 ?
| Quote: | What I would like to happen is each Web Browser opens up either in a new
form or their own Tab within my program UI and not outside
of the program as they do now.
|
For IE there is TCppWebBrowser.
For Mozilla there was an ActiveX that you could install in c++builder.
Some years ago I managed to put that on the componentpalette
but then when trying to use it in an application I only got errors.
I gave up. But maybe things have changed now.
But I think that your problem can be reformulated in this way:
How can my progam start another application and 'attach' that
instance to one of my forms or to a tabsheet ?
Hans.
|
|
| Back to top |
|
 |
Gav Guest
|
Posted: Mon Mar 07, 2005 1:04 pm Post subject: Re: Opening up Web Browsers inside my App |
|
|
"Hans Galema" <notused (AT) notused (DOT) nl> wrote
| Quote: | Is that the same program ? I had a look but did not download
it. Does it come with source for bcb3 ?
|
It is the same program yes, it does not come with the source but if it helps
I can provide it. At the moment my program use ShellExecute to open
the external programs in their own space.
| Quote: |
What I would like to happen is each Web Browser opens up either in a new
form or their own Tab within my program UI and not outside
of the program as they do now.
For IE there is TCppWebBrowser.
|
Will take a look, thanks. However if I cant get 'all' web browsers to
use my programs space then it may be futile.
| Quote: |
For Mozilla there was an ActiveX that you could install in c++builder.
Some years ago I managed to put that on the componentpalette
but then when trying to use it in an application I only got errors.
I gave up. But maybe things have changed now.
But I think that your problem can be reformulated in this way:
How can my progam start another application and 'attach' that
instance to one of my forms or to a tabsheet ?
|
Now why didn't I phrase it that way, much better thanks.
Now can anyone tell me how I can do that, it's exactly what I want.!
(If your reformulation of the question was a hint at how to do it, I am
taking a look, but am clueless at this stage. I have dropped tabs and
all sorts of things onto a form but cannot get an instance or see any way
of running a program inside a tabsheet)
Gav...
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Mon Mar 07, 2005 1:54 pm Post subject: Re: Opening up Web Browsers inside my App |
|
|
Gav wrote:
| Quote: | How can my progam start another application and 'attach' that
instance to one of my forms or to a tabsheet ?
Now why didn't I phrase it that way, much better thanks.
Now can anyone tell me how I can do that, it's exactly what I want.!
(If your reformulation of the question was a hint at how to do it, I am
taking a look, but am clueless at this stage. I have dropped tabs and
all sorts of things onto a form but cannot get an instance or see any way
of running a program inside a tabsheet)
|
At the moment I'm not exactly sure how to do it. But you will need to
exchange ShellExecute for CreateProcess as you will need the handle
of the process in order to attach the prograsmmwindow to one
of your forms. Or use ShellExecute() and then FindWindow() to get
the handle. I've seen this done in one of these groups I think.
I would have to google for it to find it. At the moment I suggest that
you try yourself first or wait till an expert comes in.
Hans.
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Mon Mar 07, 2005 4:13 pm Post subject: Re: Opening up Web Browsers inside my App |
|
|
Gav wrote:
| Quote: | How can my progam start another application and 'attach' that
instance to one of my forms or to a tabsheet ?
|
Have a look at:
Newsgroups: borland.public.cppbuilder.vcl.components.using
Subject: Docking two forms of two seperate application..
Date: Tue, 8 Mar 2005 01:08:24 +1100
Message-ID: <422c640a$1 (AT) newsgroups (DOT) borland.com>
Hans.
|
|
| Back to top |
|
 |
Gav Guest
|
Posted: Mon Mar 07, 2005 11:29 pm Post subject: Re: Opening up Web Browsers inside my App |
|
|
"Hans Galema" <notused (AT) notused (DOT) nl> wrote
| Quote: | Have a look at:
Newsgroups: borland.public.cppbuilder.vcl.components.using
Subject: Docking two forms of two seperate application..
Date: Tue, 8 Mar 2005 01:08:24 +1100
Message-ID: <422c640a$1 (AT) newsgroups (DOT) borland.com
Hans.
|
Thanks Hans, I had a look and :-
AnsiString TheCaption = text in the titlebar of the other window;
HWND hWnd = FindWindow(0, TheCaption.c_str() );
if ( hWnd)
{
::SetParent ( hWnd, Panel1->Handle );
}
else ShowMessage( TheCaption + "nnnot found");
Works fine, but only if I know the exact title text of the window.
Being web pages that open up in IE, Opera, Netscape, Mozilla etc
then I think I am going to have difficulty knowing the title text as it
is set by the web designer and could be anything.
Is there a way to open the web page in the chosen browser, read in the
title text of its window and then put it into the form?
Thanks for your help, this is the furthest I have got in a long time
and feel there is not much more to go now to get this right.
:)
Gav...
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Tue Mar 08, 2005 8:52 am Post subject: Re: Opening up Web Browsers inside my App |
|
|
Gav wrote:
| Quote: | Works fine, but only if I know the exact title text of the window.
Being web pages that open up in IE, Opera, Netscape, Mozilla etc
then I think I am going to have difficulty knowing the title text as it
is set by the web designer and could be anything.
|
There is GetClassName() too.
| Quote: | Thanks for your help, this is the furthest I have got in a long time
and feel there is not much more to go now to get this right.
|
Please let you inspire by following code:
You only need a TMemo and a TButon on a TForm.
Code lists all the running processes.
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Memo1->Clear();
HWND hwnddesktop = GetDesktopWindow();
HWND hwnd = FindWindowEx(hwnddesktop, 0, 0, 0);
while( hwnd )
{
count++;
char buffer[250];
GetWindowText(hwnd, buffer, sizeof(buffer));
if( ! buffer [0] )
GetClassName(wnd, buffer, sizeof(buffer));
Memo1->Lines->Add( buffer );
hwnd = FindWindowEx(hwnddesktop, hwnd, 0, 0);
}
}
Hans.
|
|
| Back to top |
|
 |
Gav Guest
|
Posted: Wed Mar 09, 2005 10:45 pm Post subject: Re: Opening up Web Browsers inside my App |
|
|
"Hans Galema" <notused (AT) notused (DOT) nl> wrote
| Quote: | There is GetClassName() too.
Please let you inspire by following code:
You only need a TMemo and a TButon on a TForm.
Code lists all the running processes.
Hans.
|
Thanks Hans, I am still working on it. It might also help me cure the
SysFader error message when IE closes.
Other problems include the Window Title Text not being found unless the
Window is open first, which looks
a bit messy. I need to open the window in the background somehow and then
bring it into my Form. SW_MINIMIZE
does not seem to work. But I am working on it, will come back in a week or
so if I still can't do it.
Thanks
Gav...
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Thu Mar 10, 2005 8:30 am Post subject: Re: Opening up Web Browsers inside my App |
|
|
Gav wrote:
| Quote: | .... It might also help me cure the
SysFader error message when IE closes.
|
Don't know what you mean by that. But if your app closes you
first have to set the parents of the catched applications back
to their original value.
Hans.
|
|
| Back to top |
|
 |
Gav Guest
|
Posted: Mon Mar 14, 2005 2:57 pm Post subject: Re: Opening up Web Browsers inside my App |
|
|
Ok, I have not really got any further with this.
How I am approaching it at the moment (which is probably wrong) is like this
..
A user checks checkbox(s) to choose which browser(s) to open typed URL -
'mystring' declared earlier :
char mystring[50];
AnsiString A = AnsiString(ComboBox2->Text);
strcpy(mystring, A.c_str());
Then I currently open it up using ShellExecute method.
I want to open the Browser in either my Form or a Tabbed page instead of the
ShellExecute opening it up in a new Browser Window.
As far as I can see, I still need to open it using ShellExecute first in
order to determine the WindowText (But the window still opens which I dont
want) - then I grab the Window and stick it in my Form/Tab.
So :-
if (CheckBox2->Checked==true) {ShellExecute("parent", "Open",
"Iexplore.exe", mystring , iexplorePath, SW_MAXIMIZE),z=1;
AnsiString TheCaption = "The WindowText I need to match";
HWND hWnd = FindWindow(0, TheCaption.c_str() );
if ( hWnd)
{
::SetParent ( hWnd, PagesDlg->TabSheet2->Handle );
}
else ShowMessage( TheCaption + "nnnot found");
PagesDlg->Show();
}
I think I need to use GetWindowText() somewhere and assign that to be
TheCaption.
How do I look for the WindowText of the window just opened by the
ShellExecute method?
Is ShellExecute the best way to do this or is another method preferred -
considering I dont actually want
the window open in its own space anyway, just straight into thr TabSheet or
Form.?
Any pointers anyone on how to approach this.?
(I still don't see where GetClassName() would help me in all of this)
Thanks.
Gav...
|
|
| Back to top |
|
 |
Mark Jacobs Guest
|
Posted: Tue Apr 19, 2005 12:25 pm Post subject: Re: Opening up Web Browsers inside my App |
|
|
If you are using ShellExecute, then can't you use the special flags to open
the application minimised, while keeping the current app active
(SW_SHOWMINNOACTIVE). Here is the help snippet for ShellExecute :-
The ShellExecute function opens or prints a specified file. The file can be an
executable file or a document file. See ShellExecuteEx also.
HINSTANCE ShellExecute(
HWND hwnd, // handle to parent window
LPCTSTR lpOperation, // pointer to string that specifies operation to perform
LPCTSTR lpFile, // pointer to filename or folder name string
LPCTSTR lpParameters, // pointer to string that specifies executable-file
parameters
LPCTSTR lpDirectory, // pointer to string that specifies default directory
INT nShowCmd // whether file is shown when opened
);
Parameters
hwnd
Specifies 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.
lpOperation
Pointer to a null-terminated string that specifies the operation to perform.
The following operation strings are valid:
String Meaning
"open" The function opens the file specified by lpFile. The file can be an
executable file or a document file. The file can be a folder to open.
"print" The function prints the file specified by lpFile. The file should be a
document file. If the file is an executable file, the function opens the file,
as if "open" had been specified.
"explore" The function explores the folder specified by lpFile.
The lpOperation parameter can be NULL. In that case, the function opens the
file specified by lpFile.
lpFile
Pointer to a null-terminated string that specifies the file to open or print
or the folder to open or explore. The function can open an executable file or
a document file. The function can print a document file.
lpParameters
If lpFile specifies an executable file, lpParameters is a pointer to a
null-terminated string that specifies parameters to be passed to the application.
If lpFile specifies a document file, lpParameters should be NULL.
lpDirectory
Pointer to a null-terminated string that specifies the default directory.
nShowCmd
If lpFile specifies an executable file, nShowCmd specifies how the application
is to be shown when it is opened. This parameter can be one of the following
values:
Value Meaning
SW_HIDE Hides the window and activates another window.
SW_MAXIMIZE Maximizes the specified window.
SW_MINIMIZE Minimizes the specified window and activates the next top-level
window in the Z order.
SW_RESTORE Activates and displays the window. If the window is minimized or
maximized, Windows restores it to its original size and position. An
application should specify this flag when restoring a minimized window.
SW_SHOW Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT Sets the show state based on the SW_ flag specified in the
STARTUPINFO structure passed to the CreateProcess function by the program that
started the application. An application should call ShowWindow with this flag
to set the initial show state of its main window.
SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE Displays the window as a minimized window. The active
window remains active.
SW_SHOWNA Displays the window in its current state. The active window remains
active.
SW_SHOWNOACTIVATE Displays a window in its most recent size and position. The
active window remains active.
SW_SHOWNORMAL Activates and displays a window. If the window is minimized or
maximized, Windows restores it to its original size and position. An
application should specify this flag when displaying the window for the first
time.
If lpFile specifies a document file, nShowCmd should be zero.
Return Values
If the function succeeds, the return value is the instance handle of the
application that was run, or the handle of a dynamic data exchange (DDE)
server application.
If the function fails, the return value is an error value that is less than or
equal to 32. The following table lists these error values:
Value Meaning
0 The operating system is out of memory or resources.
ERROR_FILE_NOT_FOUND The specified file was not found.
ERROR_PATH_NOT_FOUND The specified path was not found.
ERROR_BAD_FORMAT The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).
SE_ERR_ACCESSDENIED The operating system denied access to the specified file.
SE_ERR_ASSOCINCOMPLETE The filename association is incomplete or invalid.
SE_ERR_DDEBUSY The DDE transaction could not be completed because other DDE
transactions were being processed.
SE_ERR_DDEFAIL The DDE transaction failed.
SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the
request timed out.
SE_ERR_DLLNOTFOUND The specified dynamic-link library was not found.
SE_ERR_FNF The specified file was not found.
SE_ERR_NOASSOC There is no application associated with the given filename
extension.
SE_ERR_OOM There was not enough memory to complete the operation.
SE_ERR_PNF The specified path was not found.
SE_ERR_SHARE A sharing violation occurred.
Remarks
The file specified by the lpFile parameter can be a document file or an
executable file. If the file is a document file, the ShellExecute function
opens or prints it, depending on the value of the lpOperation parameter. If
the file is an executable file, the ShellExecute function opens it, even if
lpOperation specifies printing.
You can use ShellExecute to open or explore a shell folder. To open a folder,
use either of the following calls:
ShellExecute(handle, NULL, path_to_folder, NULL, NULL, SW_SHOWNORMAL);
or
ShellExecute(handle, "open", path_to_folder, NULL, NULL, SW_SHOWNORMAL);
To explore a folder, use the following call:
ShellExecute(handle, "explore", path_to_folder, NULL, NULL, SW_SHOWNORMAL);
If lpOperation is NULL, the function opens the file specified by lpFile. If
lpOperation is "open" or "explore", the function will force an open window or
explorer.
See Also
FindExecutable, ShellExecuteEx
--
Mark Jacobs
http://www.dkcomputing.co.uk
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Tue Apr 19, 2005 1:45 pm Post subject: Re: Opening up Web Browsers inside my App |
|
|
Gav wrote:
| Quote: | (I still don't see where GetClassName() would help me in all of this)
|
The code I showed you delivers the Titles of the windows or their classnames.
Now you will mostly not know the exact Title so then use the classname. Maybe
they are always the same.
Now just open some browsers and see which classnames are reported. Now that you
know the classnammes you can use them.
Hans.
|
|
| Back to top |
|
 |
Bob Gonder Guest
|
Posted: Sun Jun 05, 2005 6:55 pm Post subject: Re: Opening up Web Browsers inside my App |
|
|
Gav wrote:
| Quote: | So now I have CreateProcess opening up the chosen web browser(s) no
problem - trouble is I can not give it any arguments - I can not specify
which web site to open up to, it currently opens the default home page no
matter what I tell it.
char DefaultBrowser[50];
|
Should probably be MAXPATH instead of 50.
char Commandline[2048];
Might be better to use AnsiString because Commandline might be rather
long.
wsprintf(Commandline,"%s %s",
DefaultBrowser, "http://www.minitutorials.com");
If you are going to use local files then I think you need quotes too..
wsprintf(Commandline,"%s "%s"",
DefaultBrowser,
"file:c:\Documents and settings\index.html");
CreateProcess(DefaultBrowser, Commandline, 0, 0, 0, 0, 0, 0,
&si, &pi);
| Quote: | The above is a new problem to my original and although a neccesary fix is
required , is not as important as knowing what to do next ...
|
Sorry, don't know what to do next......
The si will let you set the window size and position.
It will also let you start the browser in suspended mode. I think
ResumeThread( pi.hThread) will let it run.
How you get it to attach and stay inside your frame, I don't know.
| Quote: | Assuming CreateProcess() is working , which it is to a point, how do I then
locate the process as it starts and redirect it (dock it) into my
application inside a tabbed page or form.? ( I will need to do this for all
Browser processes as they open, stick them in their own tab or form)
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sun Jun 05, 2005 11:56 pm Post subject: Re: Opening up Web Browsers inside my App |
|
|
"Gav" <brightoncomputers (AT) brightontown (DOT) com.au> wrote
| Quote: | So now I have CreateProcess opening up the chosen web
browser(s) no problem - trouble is I can not give it any
arguments - I can not specify which web site to open up to
|
Yes, you can. That is what the lpCommandLine parameter of CreateProcess()
is for.
| Quote: | I am now doing it like this (GetDefaultBrowser function defined earlier)
:- |
Your code is not using the command line properly. Use one of the following
approaches instead:
void __fastcall TMDIChild1::ITimageClick(TObject *Sender)
{
char DefaultBrowser[MAX_PATH+1] = {0};
MDIChild2->GetDefaultBrowser(DefaultBrowser);
STARTUPINFO si = {sizeof(STARTUPINFO), 0};
PROCESS_INFORMATION pi = {0};
AnsiString CmdLine = (AnsiQuotedStr(DefaultBrowser, '"') + " " +
AnsiQuotedStr("http://www.minitutorials.com", '"'));
if( ::CreateProcess(DefaultBrowser, CmdLine.c_str(), NULL, NULL,
FALSE, 0, NULL, NULL, &si, &pi) )
{
::CloseHandle(pi.hThread);
::CloseHandle(pi.hProcess);
}
}
Or:
void __fastcall TMDIChild1::ITimageClick(TObject *Sender)
{
char DefaultBrowser[MAX_PATH+1] = {0};
MDIChild2->GetDefaultBrowser(DefaultBrowser);
STARTUPINFO si = {sizeof(STARTUPINFO), 0};
PROCESS_INFORMATION pi = {0};
AnsiString CmdLine = (AnsiQuotedStr(DefaultBrowser, '"') + " " +
AnsiQuotedStr("http://www.minitutorials.com", '"'));
if( ::CreateProcess(NULL, CmdLine.c_str(), NULL, NULL, FALSE, 0,
NULL, NULL, &si, &pi) )
{
::CloseHandle(pi.hThread);
::CloseHandle(pi.hProcess);
}
}
| Quote: | Assuming CreateProcess() is working , which it is to a point, how do
I then locate the process as it starts and redirect it (dock it) into my
application inside a tabbed page or form.?
|
You have to loop through every running window, looking for the one that
belongs to the new process you just spawned. Use EnumWindows() and
GetWindowThreadProcessId() for that, using the process ID that
CreateProcess() returned in the PROCESS_INFORMATION structure. For example:
struct MyInfo
{
DWORD dwProcessId;
HWND hWnd;
};
BOOL CALLBACK FindBrowser(HWND hwnd, LPARAM lParam)
{
MyInfo *info = reinterpret_cast<MyInfo*>(lParam);
DWORD dwProcessId = 0;
::GetWindowThreadProcessId(hwnd, &dwProcessId);
if( dwProcessId == info->dwProcessId )
{
info->hWnd = hwnd;
return FALSE;
}
return TRUE;
}
if( ::CreateProcess(...) )
{
MyInfo info = {pi.dwProcessId, NULL};
::EnumWindows((WNDENUMPROC)FindBrowser,
reinterpret_cast<LPARAM>(&info));
if( info.hWnd != NULL )
// use info.hWnd as needed...
}
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|