Article View: borland.public.cppbuilder.nativeapi
Article #3841Re: API to detect which URL is open in Internet Explorer
From: Thorsten Meyer
Date: Thu, 20 Apr 2006 17:31
Date: Thu, 20 Apr 2006 17:31
162 lines
5285 bytes
5285 bytes
Hi,
i found another solution in the Internet, it works at first only for the
last Instance of the Internet Explorer an discover the number of all other
instances:
It works fine and is a Solution for my Problem!
Code Example:
Form Application with one Button and some Labels to show the values:
unit1.h:
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComObj.hpp>
#include <OleCtrls.hpp>
//--------------------------------------------------------------------------
-
class TForm1 : public TForm
{
__published: // Von der IDE verwaltete Komponenten
TButton *Button1;
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TLabel *Label4;
void __fastcall Button1Click(TObject *Sender);
private: // Anwender-Deklarationen
Variant App;
public: // Anwender-Deklarationen
__fastcall TForm1(TComponent* Owner);
AnsiString GetReg(AnsiString Key, AnsiString Name, HKEY RootKey);
long GetProcessList( );
};
//--------------------------------------------------------------------------
-
extern PACKAGE TForm1 *Form1;
//--------------------------------------------------------------------------
-
#endif
unit1.cpp:
//--------------------------------------------------------------------------
-
#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>
#include <Registry.hpp>
#include <DdeMan.hpp>
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int anzahl = GetProcessList();
Label3->Caption = anzahl;
if(anzahl <= 0)
return;
AnsiString Url;
AnsiString Browser = "IExplore";
TDdeClientConv *dde1 = new TDdeClientConv(this);
AnsiString RegPath =
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" +
Browser;
dde1->ServiceApplication = GetReg( RegPath , "" , HKEY_LOCAL_MACHINE );
if(dde1->SetLink( Browser, "WWW_GetWindowInfo" )==true)
{
char *str = dde1->RequestData( "0xFFFFFFFF" );
Url = str;
Label1->Caption = Url;
StrDispose(str);
}
delete dde1;
}
//--------------------------------------------------------------------------
-
AnsiString TForm1::GetReg(AnsiString Key, AnsiString Name, HKEY RootKey)
{
AnsiString Value;
TRegistry *Reg = new TRegistry();
Reg->RootKey = RootKey;
if(Reg->OpenKey(Key,false)){
if(Reg->ValueExists(Name))
Value = Reg->ReadString(Name);
Reg->CloseKey();
}
Reg->Free();
return Value;
}
//--------------------------------------------------------------------------
-
long TForm1::GetProcessList( )
{
HANDLE hProcessSnap;
HANDLE hProcess;
PROCESSENTRY32 pe32;
DWORD dwPriorityClass;
// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( hProcessSnap == INVALID_HANDLE_VALUE )
{
return -1;
}
// Set the size of the structure before using it.
pe32.dwSize = sizeof( PROCESSENTRY32 );
// Retrieve information about the first process,
// and exit if unsuccessful
if( !Process32First( hProcessSnap, &pe32 ) )
{
CloseHandle( hProcessSnap ); // Must clean up the snapshot object!
return -1;
}
// Now walk the snapshot of processes, and
// display information about each process in turn
AnsiString strings[1000]; //1000 for test only
int index = 0;
long counter = 0;
do
{
if(index > 1000)
break;
strings[index] = pe32.szExeFile;
if(strings[index] == "IEXPLORE.EXE")
{
counter++;
}
index++;
long processID = pe32.th32ProcessID;
long threadcount = pe32.cntThreads;
long parentprocessID = pe32.th32ParentProcessID;
long PriorityBase = pe32.pcPriClassBase;
} while( Process32Next( hProcessSnap, &pe32 ) );
CloseHandle( hProcessSnap );
return counter;
}
Technical Details
Message-ID:
<4447c4ec$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<44465d36@newsgroups.borland.com> <4446769f$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,49a04f82ae43f13c X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Thorsten Meyer" <meyer.t@hhb.bonn.de> Newsgroups: borland.public.cppbuilder.nativeapi References: <44465d36@newsgroups.borland.com> <4446769f$1@newsgroups.borland.com> Subject: Re: API to detect which URL is open in Internet Explorer Date: Thu, 20 Apr 2006 19:31:41 +0200 Lines: 164 Organization: hhbk X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 NNTP-Posting-Host: 217.232.95.62 Message-ID: <4447c4ec$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1145554156 217.232.95.62 (20 Apr 2006 10:29:16 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail