🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #6138

Re: Opening up Web Browsers inside my App

#6138
From: Remy Lebeau (TeamB)
Date: Sun, 05 Jun 2005 23:56
95 lines
4040 bytes
"Gav" <brightoncomputers@brightontown.com.au> wrote in message
news:42a2f6aa$1@newsgroups.borland.com...

> 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.

> 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);
        }
    }

> 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
Technical Details
Message-ID: <42a3910a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.moat.net!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
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>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,91b603800ded4d32
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
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>
Subject: Re: Opening up Web Browsers inside my App
Date: Sun, 5 Jun 2005 16:56:25 -0700
Lines: 97
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <42a3910a$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1118015754 68.69.17.41 (5 Jun 2005 16:55:54 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.moat.net!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mail