Solved

close the favorites window in internet explorer + delphi

Posted on 2006-07-03
14
290 Views
Last Modified: 2010-04-05
hi there experts,

this is my problem

1) i open the internet explorer application
2) i click the ""Favorites" button on the standard buttons menu
3) the favorites menu appears on the left hand side.

i want to be able to close that  "Favorites" window using delphi

procedure ClosefavWindow;
var
th:thandle;
  begin
    th:=FindWindow('IEFrame',nil);
//using findwindowex somewhere here
    SendMessage(th, wm_close, 0, 0);
end;  



thanks
0
Comment
Question by:nikolaosk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
14 Comments
 
LVL 16

Expert Comment

by:CodedK
ID: 17032243
Hi nikolaosk...

What about this :

procedure TForm1.Button3Click(Sender: TObject);
begin
 SetForegroundWindow(FindWindow('IEFrame',nil));
 Application.ProcessMessages;

 keybd_event(VK_CONTROL,0,0,0);       //Hold Ctrl
 keybd_event(ord('I'),0,0,0);                //Press I

 keybd_event(ord('I'),0,KEYEVENTF_KEYUP,0);             //Release I
 keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);   //Release Ctrl
end;

This will sent the Ctrl+I to the IExplorer window.
0
 
LVL 16

Expert Comment

by:CodedK
ID: 17032427
You can also try a different approach through the registry :

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Toolbar\WebBrowser\ITBarLayout

Disabled :
HKU\Software\Microsoft\Internet Explorer\Toolbar\WebBrowser\ITBarLayout:

11 00 00 00 4C 00 00 00 00 00 00 00 34 00 00 00 1F 00 04 00 57 00 00 00 01 00 00 00 20 07 00 00 A0
0F 00 00 05 00 00 00 62 05 00 00 26 00 00 00 02 00 00 00 21 07 00 00 A0 0F 00 00 04 00 00 00 21 01
00 00 A0 0F 00 00 03 00 00 00 20 03 00 00 00 00 00 00 08 00 00 00 60 05 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 39 35 83 47 C5 D0 25 41 9F A8 08 19 E2 EA AC 93 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

Enabled :

11 00 00 00 4C 00 00 00 00 00 00 00 34 00 00 00 1F 00 04 00 57 00 00 00 01 00 00 00 20 07 00 00 A0
0F 00 00 05 00 00 00 62 05 00 00 26 00 00 00 02 00 00 00 21 07 00 00 A0 0F 00 00 04 00 00 00 21 01
00 00 A0 0F 00 00 03 00 00 00 20 03 00 00 00 00 00 00 08 00 00 00 60 05 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 39 35 83 47 C5 D0 25 41 9F A8 08 19 E2 EA AC 93 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 61 4E A2 EF 78 B0 D0 11 89 E4 00 C0 4F C9 E2 6E 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00

Hope this helps.
0
 

Author Comment

by:nikolaosk
ID: 17035619
hi there CodedK,

your code works. but there is an obvious problem. i want to send the ctrl+I, only when the favorites button on the standard button toolbar is enabled.only then. if it is not enabled-pressed then by sending the ctrl+I has the oppossite effect than the one i want.so i want to check first if the favorites button is enabled and then use your code

thanks
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:CodedK
ID: 17037963
Thats true ...
Well try that:

This is the unit:
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Registry, StrUtils;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function ReadRegBinary(Key: HKEY; Name: string; var Buffer; BufSize: Integer): integer;
var
  DataType: Integer;
  Status: integer;
begin
  result := -1;
  DataType := REG_NONE;
  try
    // return the size of the buffer required
    if BufSize = 0 then begin
    // get data type and buffer size
      Status := RegQueryValueEx(Key, PChar(Name), nil, @DataType, nil, @BufSize);
      if Status  = ERROR_SUCCESS then begin
        result := BufSize;
      end;
    end else begin
      // get data
      if RegQueryValueEx(Key, PChar(Name), nil, @DataType, PByte(Buffer),
         @BufSize) = ERROR_SUCCESS then result := BufSize
      else result := -1;
    end;
  except
    result := -1;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  Key: HKEY;
  buf: array of byte;
  size: integer;
  i,loop: integer;
  s: string;
begin
  Memo1.Clear;
  if RegOpenKeyEx
  (HKEY_CURRENT_USER, 'Software\Microsoft\Internet Explorer\Toolbar\WebBrowser', 0, KEY_READ, Key)
  = ERROR_SUCCESS then
  try
    size := ReadRegBinary(Key, 'ITBarLayout', buf, 0);
    if size <> -1 then begin
      SetLength(buf, size);
      ReadRegBinary(Key, 'ITBarLayout', buf, size);
    end;
  finally
    RegCloseKey(Key);
  end;

  s := '';
  for i := 0 to High(buf) do begin
    s := s + IntToHex(buf[i],2);
  end;
  Memo1.Lines.Add(s);

  for i:=0 to Memo1.Lines.Count-1 do
  if AnsiContainsStr(Memo1.Lines[i],'614EA2EF78B0D01189E400C04FC9E26E')
  then
   begin
     SetForegroundWindow(FindWindow('IEFrame',nil));
     Application.ProcessMessages;

     keybd_event(VK_CONTROL,0,0,0);
     keybd_event(ord('I'),0,0,0);

     keybd_event(ord('I'),0,KEYEVENTF_KEYUP,0);
     keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);
   end;
end;

end.
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-



This is the form 'dfm' ... DONT FORGET to put both scroll bars in memo1.....
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
object Form1: TForm1
  Left = 437
  Top = 400
  Width = 216
  Height = 98
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  FormStyle = fsStayOnTop
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 72
    Top = 16
    Width = 89
    Height = 25
    Caption = 'Send command'
    TabOrder = 0
    OnClick = Button1Click
  end
  object Memo1: TMemo
    Left = 8
    Top = 8
    Width = 25
    Height = 25
    ScrollBars = ssBoth
    TabOrder = 1
    Visible = False
  end
end

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

:)
0
 
LVL 16

Expert Comment

by:CodedK
ID: 17037977
Above i just check the registry if it contains the value :
'614EA2EF78B0D01189E400C04FC9E26E'

inside the key : 'ITBarLayout'

Path :
"HKEY_CURRENT_USER --->  Software\Microsoft\Internet Explorer\Toolbar\WebBrowser"

If thats true it will send Ctrl+I to Internet Explorer.
The code is little big for the "read registry" part coz data is in binary !

So i hope you'll be happy :)
0
 

Author Comment

by:nikolaosk
ID: 17044468
thanks but is there any other way to check that the favorites button is enabled other than reading the registry?

wy do i need the memo1 in your code?
0
 
LVL 16

Expert Comment

by:CodedK
ID: 17044517
I store the value from the registry inside the memo....
Its too big to store in a string.
I told you to put both scrolls so i can find the value = 614EA2EF78B0D01189E400C04FC9E26E.

I'd guess that it could be done with the class of the favorites window BUT
even if i tried with several child classes that belong to that window ... I couldnt send the
commands !!!

Anyway there is always another way :)

Its not too big, its just the function plus 10 lines and the Send Ctrl+I commands.
0
 

Author Comment

by:nikolaosk
ID: 17044640
if you are telling me that the this registry key will be in the same path for all computers running windows xp and windows 2000 like below

inside the key : 'ITBarLayout'

Path :
"HKEY_CURRENT_USER --->  Software\Microsoft\Internet Explorer\Toolbar\WebBrowser"

then i i will use your code.

i am going to use that code in a dll. so i can not have memo objects and buttons

i need the function as it is

function ReadRegBinary(Key: HKEY; Name: string; var Buffer; BufSize: Integer): integer;


but i need the other to be a dll function

somthing like this

function sendmessagetofavorites

//if favorites is eabled then


begin
     SetForegroundWindow(FindWindow('IEFrame',nil));
     Application.ProcessMessages;

     keybd_event(VK_CONTROL,0,0,0);
     keybd_event(ord('I'),0,0,0);

     keybd_event(ord('I'),0,KEYEVENTF_KEYUP,0);
     keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);
end function



thanks a lot
0
 
LVL 16

Expert Comment

by:CodedK
ID: 17044671
:/
I dont have a pc with win2k that i can experiment BUT i can tell you
that even if you go with the class method you should take this under consideration too :

Next version of IExplorer is on the way.
Next Windows version is on the way.

I'll keep on searching for the right class :)
0
 
LVL 16

Expert Comment

by:CodedK
ID: 17044675
As for WinXP i am sure that this solution will work in every pc.
0
 

Author Comment

by:nikolaosk
ID: 17044845
thanks for your effort. let me know if the classname approach works.otherwise we will have to go from the registry

0
 
LVL 16

Expert Comment

by:CodedK
ID: 17044858
Give me one or two days :)
0
 

Author Comment

by:nikolaosk
ID: 17048627
okey.thanks
0
 
LVL 16

Accepted Solution

by:
CodedK earned 250 total points
ID: 17054732
:) :) :)

Okey ! I found it !   :) :)
(It took me some hours and i think that i'm happier than you !)

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
procedure TForm1.Button1Click(Sender: TObject);
begin
 If FindWindowex(FindWindow('IEframe',nil),0,'BaseBar',nil)<>0 then
  If IsWindowVisible(FindWindowex(FindWindow('IEframe',nil),0,'BaseBar',nil)) then
    Begin
      SetForegroundWindow(FindWindow('IEFrame',nil));
      Application.ProcessMessages;

      keybd_event(VK_CONTROL,0,0,0);
      keybd_event(ord('I'),0,0,0);

      keybd_event(ord('I'),0,KEYEVENTF_KEYUP,0);
      keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);
   end;
end;
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

The only thing that could reduce the code now is to directly send the command to the handle of the child window
to close... But if you close it Explorer things that it crashed and it close itself !

So i should just set it to invisible...
If i find how... i'll post :)

Hope that would do :)

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question