Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

close the favorites window in internet explorer + delphi

Posted on 2006-07-03
14
Medium Priority
?
296 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

722 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