Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to get the screen coordinates of the rectangle in which web pages are render Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
23-Nov-03
Category
Internet / Web
Language
Delphi 3.x
Views
196
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Eddie Shipman 

I am writing a Delphi application that needs to know the screen coordinates (top, 
left) of where the IE 'browser section' starts. What I mean by 'browser section' is 
the rectangle where web pages are rendered - not where the IE window is. I can find 
out where the IE window is, and where the client coordinates start, but not the 
where the 'browser section' starts. I want to lay my Delphi window precisely on top 
of the where the browser section is. But depending on how many toolbars the users 
is displaying where this browser section may start is a mystery.

Answer:

1   unit Unit1;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7     Buttons, ComCtrls, StdCtrls;
8   
9   type
10    TForm1 = class(TForm)
11      SpeedButton1: TSpeedButton;
12      Label1: TLabel;
13      procedure SpeedButton1Click(Sender: TObject);
14    private
15      { Private declarations }
16    public
17      { Public declarations }
18      procedure FindIEBrowserWindowHandle;
19    end;
20  
21  var
22    Form1: TForm1;
23    IEBrowserWindowHandle: THandle;
24  
25  implementation
26  
27  {$R *.DFM}
28  
29  function EnumIEChildProc(AHandle: hWnd; AnObject: TObject): BOOL; stdcall;
30  var
31    tmpS: string;
32    theClassName: string;
33    theWinText: string;
34  begin
35    Result := True;
36    SetLength(theClassName, 256);
37    GetClassName(AHandle, PChar(theClassName), 255);
38    SetLength(theWinText, 256);
39    GetWindowText(AHandle, PChar(theWinText), 255);
40    tmpS := StrPas(PChar(theClassName));
41    if theWinText <> EmptyStr then
42      tmpS := tmpS + ' "' + StrPas(PChar(theWinText)) + '"'
43    else
44      tmpS := tmpS + '""';
45    if Pos('Explorer_Server', tmpS) > 0 then
46    begin
47      IEBrowserWindowHandle := AHandle;
48    end;
49  end;
50  
51  function IEWindowEnumProc(AHandle: hWnd; AnObject: TObject): BOOL; stdcall;
52  {callback for EnumWindows}
53  var
54    theClassName: string;
55    theWinText: string;
56    tmpS: string;
57  begin
58    Result := True;
59    SetLength(theClassName, 256);
60    GetClassName(AHandle, PChar(theClassName), 255);
61    SetLength(theWinText, 256);
62    GetWindowText(AHandle, PChar(theWinText), 255);
63    tmpS := StrPas(PChar(theClassName));
64    if theWinText <> EmptyStr then
65      tmpS := tmpS + ' "' + StrPas(PChar(theWinText)) + '"'
66    else
67      tmpS := tmpS + '""';
68    if Pos('IEFrame', tmpS) > 0 then
69    begin
70      EnumChildWindows(AHandle, @EnumIEChildProc, longInt(0));
71    end;
72  end;
73  
74  procedure TForm1.FindIEBrowserWindowHandle;
75  begin
76    Screen.Cursor := crHourGlass;
77    try
78      EnumWindows(@IEWindowEnumProc, LongInt(0));
79    finally
80      Screen.Cursor := crDefault;
81    end;
82  end;
83  
84  procedure TForm1.SpeedButton1Click(Sender: TObject);
85  var
86    caption: array[0..127] of Char;
87    s: string;
88    R: TRect;
89  begin
90    FindIEBrowserWindowHandle;
91    if IEBrowserWindowHandle > 0 then
92    begin
93      GetWindowRect(IEBrowserWindowHandle, R);
94      s := 'IE Browser Window located at: ' + IntToStr(R.Top) + ', ' + 
95  IntToStr(R.Left)
96        + ', ' + IntToStr(R.Bottom) + ', ' + IntTOStr(R.Right);
97      Label1.Caption := s;
98    end
99    else
100     label1.Caption := 'Not Found';
101 end;
102 
103 end.



			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC