Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

close the favorites window in internet explorer + delphi

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
nikolaosk
Asked:
nikolaosk
  • 9
  • 5
1 Solution
 
CodedKCommented:
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
 
CodedKCommented:
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
 
nikolaoskAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
CodedKCommented:
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
 
CodedKCommented:
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
 
nikolaoskAuthor Commented:
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
 
CodedKCommented:
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
 
nikolaoskAuthor Commented:
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
 
CodedKCommented:
:/
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
 
CodedKCommented:
As for WinXP i am sure that this solution will work in every pc.
0
 
nikolaoskAuthor Commented:
thanks for your effort. let me know if the classname approach works.otherwise we will have to go from the registry

0
 
CodedKCommented:
Give me one or two days :)
0
 
nikolaoskAuthor Commented:
okey.thanks
0
 
CodedKCommented:
:) :) :)

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.

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now