Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: IExplorerBrowser - how to implement key navigation


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Apr 9, 2016 8:23 AM Last Post By: raf bakker
Eric Holzer

Posts: 8
Registered: 5/7/10
IExplorerBrowser - how to implement key navigation  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 12, 2016 7:50 AM
Hello,

I would like to open folder view with IExplorerBrowser.
Here is the example that works:
unit Unit1;
 
interface
 
uses
  Winapi.Windows, Winapi.Messages, Winapi.ShlObj, Winapi.ActiveX,
  System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormResize(Sender: TObject);
  private
    { Private declarations }
 
    FExplorerBrowser: IExplorerBrowser;
    FInputObject: IInputObject;
 
    procedure Initialize;
    procedure MsgHandler(var Msg: TMsg; var Handled: Boolean);
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage := MsgHandler;
  Initialize;
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
   FInputObject := nil;
   FExplorerBrowser.Destroy;
   FExplorerBrowser := nil;
end;
 
procedure TForm1.FormResize(Sender: TObject);
var phdwp: NativeUInt;
begin
  phdwp := 0;
  if Assigned(FExplorerBrowser) then
     FExplorerBrowser.SetRect(phdwp, ClientRect );
end;
 
procedure TForm1.MsgHandler(var Msg: TMsg; var Handled: Boolean);
begin
    if (Msg.message >= WM_KEYFIRST) and (Msg.message <= WM_KEYLAST) then begin
     if Assigned(FInputObject) and (FInputObject.HasFocusIO =  S_OK) then
        FInputObject.TranslateAcceleratorIO(Msg);
    end;
end;
 
 
procedure TForm1.Initialize;
    var
      FS: TFolderSettings;
      R: TRect;
      HRes: HRESULT;
      pidlPath: PItemIDList;
    begin
 
      HRes := CoCreateInstance( CLSID_ExplorerBrowser, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER , IID_IExplorerBrowser, FExplorerBrowser);     //CLSCTX_LOCAL_SERVER
 
      if Succeeded(HRes) then
      begin
        FS.fFlags := 0;
        FS.ViewMode := FVM_DETAILS;
 
        R := self.GetClientRect;
        HRes := FExplorerBrowser.Initialize(self.Handle, R, FS);
 
        if Succeeded(HRes) then
        begin
          HRes := FExplorerBrowser.SetOptions( EBO_NOWRAPPERWINDOW or EBO_ALWAYSNAVIGATE );
 
          if Succeeded(HRes) then
          begin
            HRes := FExplorerBrowser.QueryInterface(IID_IInputObject, FInputObject );
            if Succeeded(HRes) then
            begin
              pidlPath := ILCreateFromPath('c:\Windows' );
              try
                if Assigned(pidlPath) then
                  HRes := FExplorerBrowser.BrowseToIDList(pidlPath, 0);
              finally
                ILFree(pidlPath);
              end;
            end;
          end;
        end;
      end;
    end;
 
end.
 


My problem is the key navigation. If I try to move the selection with Down or Up key, the selection skip two items down or up. If I try to open folder with Enter then additional the Explorer will be opened.
If I open the context menu with Alt+Enter, then the focus is gone.

Someone know how to implement right key navigation and how to control the focus?

Thanks,
Eric
Joachim Marder

Posts: 16
Registered: 8/20/01
Re: IExplorerBrowser - how to implement key navigation  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 15, 2016 8:26 AM   in response to: Eric Holzer in response to: Eric Holzer
Hi Eric.

I just wanted to let you know that we wrapped IExplorerBrowser in a commercial, ready-to-use Delphi VCL control. We found many pitfalls like this on the way.
Please find more info here: http://www.jam-software.com/shellbrowser_delphi/explorer-browser.shtml

Best regards,

Joachim Marder
JAM Software

Eric Holzer wrote:
Hello,

I would like to open folder view with IExplorerBrowser.
Here is the example that works:
unit Unit1;
 
interface
 
uses
  Winapi.Windows, Winapi.Messages, Winapi.ShlObj, Winapi.ActiveX,
  System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormResize(Sender: TObject);
  private
    { Private declarations }
 
    FExplorerBrowser: IExplorerBrowser;
    FInputObject: IInputObject;
 
    procedure Initialize;
    procedure MsgHandler(var Msg: TMsg; var Handled: Boolean);
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage := MsgHandler;
  Initialize;
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
   FInputObject := nil;
   FExplorerBrowser.Destroy;
   FExplorerBrowser := nil;
end;
 
procedure TForm1.FormResize(Sender: TObject);
var phdwp: NativeUInt;
begin
  phdwp := 0;
  if Assigned(FExplorerBrowser) then
     FExplorerBrowser.SetRect(phdwp, ClientRect );
end;
 
procedure TForm1.MsgHandler(var Msg: TMsg; var Handled: Boolean);
begin
    if (Msg.message >= WM_KEYFIRST) and (Msg.message <= WM_KEYLAST) then begin
     if Assigned(FInputObject) and (FInputObject.HasFocusIO =  S_OK) then
        FInputObject.TranslateAcceleratorIO(Msg);
    end;
end;
 
 
procedure TForm1.Initialize;
    var
      FS: TFolderSettings;
      R: TRect;
      HRes: HRESULT;
      pidlPath: PItemIDList;
    begin
 
      HRes := CoCreateInstance( CLSID_ExplorerBrowser, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER , IID_IExplorerBrowser, FExplorerBrowser);     //CLSCTX_LOCAL_SERVER
 
      if Succeeded(HRes) then
      begin
        FS.fFlags := 0;
        FS.ViewMode := FVM_DETAILS;
 
        R := self.GetClientRect;
        HRes := FExplorerBrowser.Initialize(self.Handle, R, FS);
 
        if Succeeded(HRes) then
        begin
          HRes := FExplorerBrowser.SetOptions( EBO_NOWRAPPERWINDOW or EBO_ALWAYSNAVIGATE );
 
          if Succeeded(HRes) then
          begin
            HRes := FExplorerBrowser.QueryInterface(IID_IInputObject, FInputObject );
            if Succeeded(HRes) then
            begin
              pidlPath := ILCreateFromPath('c:\Windows' );
              try
                if Assigned(pidlPath) then
                  HRes := FExplorerBrowser.BrowseToIDList(pidlPath, 0);
              finally
                ILFree(pidlPath);
              end;
            end;
          end;
        end;
      end;
    end;
 
end.
 


My problem is the key navigation. If I try to move the selection with Down or Up key, the selection skip two items down or up. If I try to open folder with Enter then additional the Explorer will be opened.
If I open the context menu with Alt+Enter, then the focus is gone.

Someone know how to implement right key navigation and how to control the focus?

Thanks,
Eric

Edited by: Joachim Marder on Feb 15, 2016 5:26 PM

Edited by: Joachim Marder on Feb 15, 2016 5:27 PM

Edited by: Joachim Marder on Feb 15, 2016 5:28 PM
raf bakker

Posts: 4
Registered: 5/28/07
Re: IExplorerBrowser - how to implement key navigation  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 9, 2016 8:23 AM   in response to: Eric Holzer in response to: Eric Holzer
Set Handled := True
procedure TForm1.MsgHandler(var Msg: TMsg; var Handled: Boolean);
begin
if (Msg.message >= WM_KEYFIRST) and (Msg.message <= WM_KEYLAST) then begin
if Assigned(FInputObject) and (FInputObject.HasFocusIO = S_OK) then
begin
FInputObject.TranslateAcceleratorIO(Msg);
Handled := True;
end;
end;
end;

That is all. Raf Bakker

Eric Holzer wrote:
Hello,

I would like to open folder view with IExplorerBrowser.
Here is the example that works:
unit Unit1;
 
interface
 
uses
  Winapi.Windows, Winapi.Messages, Winapi.ShlObj, Winapi.ActiveX,
  System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormResize(Sender: TObject);
  private
    { Private declarations }
 
    FExplorerBrowser: IExplorerBrowser;
    FInputObject: IInputObject;
 
    procedure Initialize;
    procedure MsgHandler(var Msg: TMsg; var Handled: Boolean);
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage := MsgHandler;
  Initialize;
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
   FInputObject := nil;
   FExplorerBrowser.Destroy;
   FExplorerBrowser := nil;
end;
 
procedure TForm1.FormResize(Sender: TObject);
var phdwp: NativeUInt;
begin
  phdwp := 0;
  if Assigned(FExplorerBrowser) then
     FExplorerBrowser.SetRect(phdwp, ClientRect );
end;
 
procedure TForm1.MsgHandler(var Msg: TMsg; var Handled: Boolean);
begin
    if (Msg.message >= WM_KEYFIRST) and (Msg.message <= WM_KEYLAST) then begin
     if Assigned(FInputObject) and (FInputObject.HasFocusIO =  S_OK) then
        FInputObject.TranslateAcceleratorIO(Msg);
    end;
end;
 
 
procedure TForm1.Initialize;
    var
      FS: TFolderSettings;
      R: TRect;
      HRes: HRESULT;
      pidlPath: PItemIDList;
    begin
 
      HRes := CoCreateInstance( CLSID_ExplorerBrowser, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER , IID_IExplorerBrowser, FExplorerBrowser);     //CLSCTX_LOCAL_SERVER
 
      if Succeeded(HRes) then
      begin
        FS.fFlags := 0;
        FS.ViewMode := FVM_DETAILS;
 
        R := self.GetClientRect;
        HRes := FExplorerBrowser.Initialize(self.Handle, R, FS);
 
        if Succeeded(HRes) then
        begin
          HRes := FExplorerBrowser.SetOptions( EBO_NOWRAPPERWINDOW or EBO_ALWAYSNAVIGATE );
 
          if Succeeded(HRes) then
          begin
            HRes := FExplorerBrowser.QueryInterface(IID_IInputObject, FInputObject );
            if Succeeded(HRes) then
            begin
              pidlPath := ILCreateFromPath('c:\Windows' );
              try
                if Assigned(pidlPath) then
                  HRes := FExplorerBrowser.BrowseToIDList(pidlPath, 0);
              finally
                ILFree(pidlPath);
              end;
            end;
          end;
        end;
      end;
    end;
 
end.
 


My problem is the key navigation. If I try to move the selection with Down or Up key, the selection skip two items down or up. If I try to open folder with Enter then additional the Explorer will be opened.
If I open the context menu with Alt+Enter, then the focus is gone.

Someone know how to implement right key navigation and how to control the focus?

Thanks,
Eric
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02