Article View: borland.public.cppbuilder.nativeapi
Article #6083Re: Opening up Web Browsers inside my App
From: Gav
Date: Tue, 07 Jun 2005 23:18
Date: Tue, 07 Jun 2005 23:18
122 lines
4343 bytes
4343 bytes
Hi Gambit,
> Please show your latest code.
>
>
> Gambit
No problem, from the top in case any headers may be missing I have :-
#include <vcl.h>
#pragma hdrstop
#include <Registry.hpp>
#include "MTB2Child1.h"
#include "MTB2Child3.h"
#include "MTBconversion2.h"
#include "MTB2conversion.h"
#include "Main.h"
#include "windows.h"
#include "shellapi.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ChildWin"
#pragma resource "*.dfm"
TMDIChild1 *MDIChild1;
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;
}
//---------------------------------------------------------------------------
__fastcall TMDIChild1::TMDIChild1(TComponent* Owner)
: TMDIChild(Owner)
{
.....
.....
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) )
{
WaitForInputIdle(CreateProcess, 200);
Sleep(175);
//WaitForInputIdle; <- ??
::CloseHandle(pi.hThread);
::CloseHandle(pi.hProcess);
MyInfo info = {pi.dwProcessId, NULL};
::EnumWindows((WNDENUMPROC)FindBrowser,reinterpret_cast<LPARAM>(&info));
if( info.hWnd != NULL )
{
::SetParent ( info.hWnd, Form4->Handle );
Form4->Show();
}
}
}
....
....
....
}
The above code does do what I want it to do but only sometimes.
I have had to experiment with the values of
WaitForInputIdle(CreateProcess, 200);
Sleep(175);
Sometimed changing 200 to 220 or 230 or 250 also works when the current
value fails. INFINITE does not work.
Strange I know but it will not work at all ever if the Sleep(175); is not in
there.
175 seems the optimal minimal value that works (i.e. 174 will not work)
Without the Sleep then this if statement does not execute.
if( info.hWnd != NULL )
{
::SetParent ( info.hWnd, Form4->Handle );
Form4->Show();
}
I am probably using WaitForInputIdle() incorrectly but I can't see where.
Maybe this is the wrong approach?
Gav...
Technical Details
Message-ID:
<42a62b57@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<422926aa$1@newsgroups.borland.com> <422c31bd$1@newsgroups.borland.com> <422c515c@newsgroups.borland.com> <422c5d8e$1@newsgroups.borland.com> <42a2f6aa$1@newsgroups.borland.com> <42a3910a$1@newsgroups.borland.com> <42a44aa2$1@newsgroups.borland.com> <42a4855c$1@newsgroups.borland.com> <42a588ed@newsgroups.borland.com> <42a5a49d@newsgroups.borland.com> <42a5bb59$1@newsgroups.borland.com> <42a5bdbf@newsgroups.borland.com> <42a5d4dd@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,91b603800ded4d32 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Gav" <brightoncomputers@brightontown.com.au> Newsgroups: borland.public.cppbuilder.nativeapi References: <422926aa$1@newsgroups.borland.com> <422c31bd$1@newsgroups.borland.com> <422c515c@newsgroups.borland.com> <422c5d8e$1@newsgroups.borland.com> <42a2f6aa$1@newsgroups.borland.com> <42a3910a$1@newsgroups.borland.com> <42a44aa2$1@newsgroups.borland.com> <42a4855c$1@newsgroups.borland.com> <42a588ed@newsgroups.borland.com> <42a5a49d@newsgroups.borland.com> <42a5bb59$1@newsgroups.borland.com> <42a5bdbf@newsgroups.borland.com> <42a5d4dd@newsgroups.borland.com> Subject: Re: Opening up Web Browsers inside my App Date: Wed, 8 Jun 2005 07:18:48 +0800 Lines: 126 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 203.121.204.130 Message-ID: <42a62b57@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1118186327 203.121.204.130 (7 Jun 2005 16:18:47 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail