• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1080
  • Last Modified:

Get selected file

Is there any way to get selected file in windows explorer to Delphi.

If I mark a file in explorer like “c:\test\fix.txt”
Then I want to grab this with Delphi cod.
0
Dark_King
Asked:
Dark_King
  • 12
  • 7
  • 3
  • +3
1 Solution
 
mikelittlewoodCommented:
What do u mean "get selected file"?

Do you mean open a file?
0
 
Dark_KingAuthor Commented:
No
I want the path of selected (marked) file inside explorer to my app in Delphi
If I select  “c:\test\fix.txt” in Explorer the result in Delphi should be " “c:\test\fix.txt”
0
 
geobulCommented:
Hi,

I can't quite understand, sorry. Do you mean to drag a selected file from Explorer and drop it on your Delphi form? If not and you have several instances of Explorer all having selected files then what?

Regards, Geo
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!

 
2266180Commented:
hm.. I can think of some way of getting the window caption and then the window itself and iterating through child controls for the list that displays the files and read the selected item ... but I am too lazy at this hour to search up some code :D
0
 
Dark_KingAuthor Commented:
I have a windows program and in one function I want to use windows hotkey, I need to get this path from selected (marked) file in explorer.

I try to shorten up the Context Menu function to only use a hotkey, in this case I need full path and file name like I do with %1 on Context Menu function, but this is handle from explorer.

I don't think this is possible without rewrite Explorer, I ask because it cold be some API or Windows grab function, I don't now
0
 
heretoreadCommented:
Dont think there is an easy way, as it would be specific to explorer, you could always try and hook CreateFile();
0
 
AmigoJackCommented:
ok, i think this is possible, but i havent tried it yet. let me explain what i imagine:
- your application defines a systemwide hotkey, that means:
- explorer-window is active, you press i.e. CTRL+F11
basically explorers could look very differently. the easiest way would be if there is a combobox which has the full path inside - that could be the first try. another try is to get the path out of the window's title, but only few people use that. the third try would be to get the current selection of the directory tree - and trace the entries up to the root to build up the path. unfortunately users can even turn-off this directory tree. this means that whoever will use your application must meet a minimum of explorer layout. getting the selected filename itself should be even more simple.

based on that ideas it sounds quite possible to me to get the current selected file including the path. however, this could fail if we are within some "special folder", which has no drive as a root.

Dark_King, if this sounds acceptable to you, i will try it. but give me ~5 days for that. otherwise you have to inform yourself about "shell explorer extensions", which give you the possibility to add an entry to the shell context menu by compiling a specific dll.
0
 
Dark_KingAuthor Commented:
AmigoJack
I can’t use a program that’s depending on users’ explorer settings, and it should not be stuck with default folders.

"shell explorer extensions"
This is already in my program, I was looking for more future to it by using only hotkey(Select file in explorer and press hotkey). And like I say before,
“”I don't think this is possible without rewrite Explorer, I ask because it cold be some API or Windows grab function, I don't now””
0
 
Dark_KingAuthor Commented:
I can only think about some hook to explorer that’s making this work, make any sense?
0
 
2266180Commented:
for that you need to know what function(s) to hook. madhook component from madshi will help you hook quite well ... but you still need the functions. msdn might unveil their name but ... there some heavy searching involved
0
 
Dark_KingAuthor Commented:
Yea I now I have searching on this for some time now, so for that reason I ask here.
0
 
2266180Commented:
hm... I did some searching and found the following article on shell extensions (couldn't find the function which needs to be hooked, but I guess that some extensive seraching might do the trick):
http://www.codeproject.com/shell/wildcardselect.asp
according to it:
"The only place where we can figure out whether the user clicked on a file or on the background of the window is in Initialize()."
and further more:
"Surely, there must be a way for Windows itself to know which filename belongs to a particular list item? Well, I took a guess here, and assumed that the lParam member of a list item contains the PIDL to the file. (For more about PIDLs and stuff, see Mike Dunn's article on namespace extensions.) I was right - it must have been my lucky day ;-) We don't really need to do anything with that PIDL, except feed it to SHGetPathFromIDList(), which in turn gives us the path to the file that this list item represents."
so I guess you could look at that code in the Initialize() function and see how they get the selected file BEFORE the menu is shown. so you can have a shell extension with no menu entry but which actually gets the files and maybe feeds them to a service or something (depends what you want to do with the selected file)
0
 
AmigoJackCommented:
"the lParam member of a list item contains the PIDL" sounds very promising :) i will try to investigate into that. combined with a hotkey from/pointing to your application your wishes should soon meet reality
0
 
Dark_KingAuthor Commented:
I’m looking forward to hearing from you.
0
 
AmigoJackCommented:
ok, ive tested it and im able to get the selected filename from the explorer. the information about getting the path also did turned out to be useless even in the example from the link. but i found out that it doesnt matter wheather the address-box is visible or not, i could read out its content. this only has two issues: 1.) at the time i read it, the user might have entered any crap (without pressing enter), but this is really a rare case and could be discarded; and 2.) i always assume i have the full path in there, but i suspect you can set explorer settings also to only display the current folder - could you check that? if you are lucky with all that, then i could give you all the code on getting the selected file. otherwise i have to disappoint you by not reaching the aim :/
0
 
Dark_KingAuthor Commented:
“suspect you can set explorer settings also to only display the current folder”
Not shore, I did not find that setting.

You realise path need to have “filename” in it to!

If you have that and I cold use it in my DLL you have earn all points and my full respect on time helping me.

I found out if I trace explorer.exe with sysinternal’s monitor it has full path when I click on a file, but it has lot more junk filling
0
 
AmigoJackCommented:
ok here we go :) create a new project, add an edit and a button to it, then replace ALL of the code of unit1.pas with the following one. i adopted an example from the link shown within, which purpose was to get the items positions:

====================START==================
Unit Unit1;
//
// Sujet : Position des icônes sur le bureau
//
// Par Nono40 : http://nono40.developpez.com   http://nono40.fr.st
//              mailTo:nono40@fr.st
//
// Le 18/05/2003
//

Interface

Uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, shlobj;

Type
  TForm1 = Class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  Private
    { Déclarations privées }
  protected
    procedure WndProc(var Message: TMessage); override;
  Public
    { Déclarations publiques }
  End;

Var
  Form1: TForm1;

Implementation

{$R *.dfm}

Const
  // listview and item messages
  LVM_FIRST                        = $1000;
  LVM_GETITEMCOUNT                 = LVM_FIRST+ 4;
  LVM_GETITEM                      = LVM_FIRST+ 5;

  // item constants
  LVIF_TEXT                        = $0001;
  LVIF_STATE                       = $0008;

  // item states
  LVIS_FOCUSED                     = $0001;
  LVIS_SELECTED                    = $0002;

Type
  // item struct (i know nowadays this slightly differs, but this seems to work also)
  TLV_ITEM= Record
    mask        : Cardinal;
    iItem       : Integer;
    iSubItem    : Integer;
    state       : Cardinal;
    stateMask   : Cardinal;
    pszText     : Pointer;
    cchTextMax  : Integer;
    iImage      : Integer;
    _lParam     : LPARAM;
  End;

  // a custom extension to meet our needs :)
  PDatas= ^TDatas;
  TDatas= Record
    LV_ITEM  : TLV_ITEM;
    LV_TEXTE : Array[0..255] Of Char;
  End;

  // dynamic function use, so this also runs under win9X
  TVirtualAllocEx= Function(hProcess: THandle; lpAddress: Pointer; dwSize, flAllocationType: DWORD; flProtect: DWORD): Pointer; stdcall;
  TVirtualFreeEx= Function(hProcess: THandle; lpAddress: Pointer; dwSize, dwFreeType: DWORD): Pointer; stdcall;

Const
  TailleMap= SizeOf(TDatas);

Var
  HandleMAP,  // for win9X
  HandleCB,  // handle combobox
  HandleLV  :THandle;  // handle listview
  ProcessLV :Cardinal; // handle explorer process
  DatasLV   :PDatas;   // pointer to our info of...
  Datas     :TDatas;   // the item-captions itself

  WindowsNT      :Boolean;  // win9X?
  VirtualAllocEx :TVirtualAllocEx;
  VirtualFreeEx  :TVirtualFreeEx;

// capture messages
procedure TForm1.WndProc(var Message: TMessage);
begin
  if message.msg= WM_HOTKEY then begin  // hotkey pressed
    case message.WParam of  // which one?
      1: Button1Click(nil);
    end;
    exit;
  end;
  inherited WndProc(Message);
end;

// read the memory-mapped data
Procedure LecturePartage;
Var N: Cardinal;
Begin
  If WindowsNT Then ReadProcessMemory(ProcessLV, DatasLV, @Datas, SizeOf(Datas), N)
               Else Datas:= DatasLV^;
End;

// write the memory-mapped data
Procedure EcriturePartage;
Var N: Cardinal;
Begin
  If WindowsNT Then WriteProcessMemory(ProcessLV, DatasLV, @Datas, SizeOf(Datas), N)
               Else DatasLV^:= Datas;
End;

// allocate needed memory
Procedure CreationPartage;
Var ProcessID: Cardinal;
Begin
  If WindowsNT Then Begin
    GetWindowThreadProcessId(HandleLV, @ProcessID);  // get pid of listview
    ProcessLV:= OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID);  // obtain rights to operate memory
    // Allocation d'une zone dans le Process obtenu
    DatasLV:= VirtualAllocEx(ProcessLV, Nil, TailleMAP, MEM_COMMIT, PAGE_READWRITE);
  End Else Begin
    HandleMAP:= CreateFileMapping(
          $FFFFFFFF           // Handle mémoire
          ,Nil                // Sécurité par défaut
          ,PAGE_READWRITE     // Accès en lecture/écriture
          ,0                  // Taille de la zone partagée   HIGH
          ,TailleMAP          // Taille de la zone partagée   LOW
          ,'LISTVIEWINFO');   // Nom du partage
    DatasLV:= MapViewOfFile(
          HandleMAP           // Handle du partage mémoire
          ,FILE_MAP_WRITE     // Accès en lecture/écriture
          ,0                  // Début de la zone  HIGH
          ,0                  // Début de la zone  LOW
          ,0);                // Zone entière
  End;
  Datas.LV_ITEM.pszText   := @(DatasLV^.LV_TEXTE);
  Datas.LV_ITEM.cchTextMax:= SizeOf(Datas.LV_TEXTE);
  EcriturePartage;
End;

Procedure TForm1.Button1Click(Sender: TObject);
Var
  i1, i2: Integer;
  s: string;
Begin
  edit1.Text:= '<no item focused>';  // suspect nothing is focused, like an empty
  setlength(s, 300);  // reserve some space
  i1:= SendMessage(HandleCB, WM_GETTEXT, 300, longint(@s[1]));  // get combobox content
  setlength(s, i1);  // set string to the length we actually got
  if s[length(s)]<> '\' then s:= s+ '\';

  // get count of items
  i2:= SendMessage(HandleLV, LVM_GETITEMCOUNT, 0, 0);
  // check every item listed
  For i1:= 0 To i2- 1 Do Begin
    Datas.LV_ITEM.mask       := LVIF_TEXT or LVIF_STATE;  // we want the text and the state of the item
    Datas.LV_ITEM.iItem      := i1;  // for the "i"th item
    Datas.LV_ITEM.iSubItem   := 0;  // no subitem = item itself
    Datas.LV_ITEM.state      := 0;  // ensure blank
    Datas.LV_ITEM.stateMask  := $FFFF;  // we want all states

    EcriturePartage;
    SendMessage(HandleLV, LVM_GETITEM, 0, Integer(DatasLV));
    LecturePartage;

    // only one item can have the focus, so here we check
    if Datas.LV_ITEM.state and LVIS_FOCUSED<> 0 then edit1.Text:= s+ Datas.LV_TEXTE;
  End;
End;

procedure TForm1.FormCreate(Sender: TObject);
begin
  RegisterHotKey(Handle, 1, MOD_WIN, VK_F9);  // register hotkey WIN+F9
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnregisterHotKey(Form1.Handle, 1);
end;

Initialization
  HandleLV:= FindWindowEx(0       , 0, 'ExploreWClass'   , Nil);
  HandleCB:= FindWindowEx(HandleLV, 0, 'WorkerW'         , nil);
  HandleCB:= FindWindowEx(HandleCB, 0, 'ReBarWindow32'   , nil);
  HandleCB:= FindWindowEx(HandleCB, 0, 'ComboBoxEx32'    , nil);  // we got the combobox
  HandleLV:= FindWindowEx(HandleLV, 0, 'SHELLDLL_DefView', Nil);
  HandleLV:= FindWindowEx(HandleLV, 0, 'SysListView32'   , Nil);  // we got the listview

  WindowsNT:= Win32Platform= VER_PLATFORM_WIN32_NT;
  If WindowsNT Then Begin  // assign functions
    @VirtualAllocEx:= GetProcAddress(GetModuleHandle('KERNEL32.DLL'), 'VirtualAllocEx');
    @VirtualFreeEx := GetProcAddress(GetModuleHandle('KERNEL32.DLL'), 'VirtualFreeEx');
  End;

  CreationPartage;  // prepare data
Finalization
  If WindowsNT Then VirtualFreeEx(ProcessLV, DatasLV, 0, MEM_RELEASE) Else Begin
    UnMapViewOfFile(DatasLV);
    CloseHandle(HandleMAP);
  End;
end.
==================END====================

how does it work? ive tested this under xp, but most parts should also work under win9X - however, i couldnt test that right now. either you press the button to get the current selection from the explorer - or you press the key combination WIN+F9 (see the code to change it, could also be something like CTRL+ALT+F9 or anything you like). the last one also means your application can be fully invisible but you can still get the selection.

one more thing to prevent mistakes of understanding: it is a difference if something is selected OR focused. the focus can only be at one position - the focus uniquely marks where keyboard input goes to - so only one window with one control in it can have the focus at one time. this is also for a listview the same: only ONE item can be focused (and we are looking for that one). a selection instead can be everywhere and also occur in multiple ways. a selection wont be lost also if the focus changes. for listviews, several / one / no item(s) can be selected. but dont want to get all the selected, right? (would be a very small change in the code)

anyway - test it - give feedback :)
0
 
Dark_KingAuthor Commented:
You have something here but don’t work if I select a new file in another dir.

It works like this for me.

First Explorer that’s is open is the only windows it read from, and it only read path
from this dir that’s was open when your program start.

If two explorer is running and I set focus on explorer that’s was open as second program,
It still read from first open (not in focus) explorer.

And if no explorer is running before your app it doesn’t work.

It seams it can only read path from first already running explorer and current dir explorer are in, change dir it stop working.

HEHE, I’m very bad in English, I hade to read my explanation over and over to
Understand it, I hope you do.
0
 
Dark_KingAuthor Commented:
If I select a file in one open explorer is that windows not in focus then?
0
 
AmigoJackCommented:
>>but don’t work if I select a new file in another dir.<<
how do you mean that? changing to another directory within the SAME explorer window, then selecting a file, then pressing the hotkey will not bring you the selection? if you mean that the program can trace your actions then youve been misleaded - i always said the program only REacts, it is not aware of when something changes. it only reacts to a hotkey or pressing the button.

>>First Explorer that’s is open is the only windows it read from<<
true. the code is laid out to that. if youre working with the hotkey (please confirm this) then i could easily use the current foreground window (thats the one which is active and thus has the focus). this can be done easily.

>>, and it only read path from this dir that’s was open when your program start.<<
do you mean you only get the path and NOT the currently focused listview item? maybe thats because there is no listview item focused at all? a bit confusing, because even double-clicking to show another directory sets the focus to the first listview item. can you give an explanation on how to reproduce this behaviour?

>>And if no explorer is running before your app it doesn’t work.<<
thats how the code works for now. can also be changed, see remark above.

>>It seams it can only read path from first already running explorer and current dir explorer are in, change dir it stop working.<<
like i said: let me know how i can also experience this behaviour. i repeat also: the program ONLY reacts. it is not active (e.g. "knowing" when you change directories), it only analyzes the content and state of the listview at the moment the hotkey is pressed. once.

>>HEHE, I’m very bad in English, I hade to read my explanation over and over to
Understand it, I hope you do.<<
i think i did so. hope youll understand my remarks
0
 
Dark_KingAuthor Commented:
>> let me know how i can also experience this behaviour
I write this down only so you can empty your brain from it.
******Not working*******
1: Open explorer (Default it has open this computer)
2: Start your Delphi program
3: change dir in explorer (exemple c:\windows) and select a file.
4: Hit WIN+F9
It won’t give me the path.

******Not working*******
1: Start your Delphi program
2: Open explorer (Default it has open this computer)
3: change dir in explorer (exemple c:\windows) and select a file.
4: Hit WIN+F9
It won’t give me the path.

******Not working*******
1: Open explorer (Default it has open this computer)
2: change dir in explorer (exemple c:\windows) and select a file.
3: Start your Delphi program
4: change dir in explorer (exemple C:\WINDOWS\system32) and select a file.
5: Hit WIN+F9

******Working*******
1: Open explorer (Default it has open this computer)
2: change dir in explorer (exemple c:\windows) and select a file.
3: Start your Delphi program
4: Hit WIN+F9

*****here are my real messages*****
I figure out now your cod works, it’s only the example that’s not working.
I need to study this cod to figure out how I start all this from my dll app.

It looks like it always works for me if I start your program after I select a file.
Is it possibly to have that function when I hit WIN+F9, it does all check when I hit hotkey.

What I can’t figure out is this.
If the program works if I start it after selecting a file in explorer,
And all functions is call first when I hit button or hotkey (looks like that).
Why can’t your program start before explorer.

And I need to say you have made this possibly, and it is really working to.
0
 
AmigoJackCommented:
i will check all these, it should be possible to make the program work also when no explorer is open at startup and else. also all functionality within one single function should be no problem. please wait until ~ 23:00 GMT + 02:00 (thats in about 12 hours from now). i see no major problems coming up to make it work like it should :)
0
 
Dark_KingAuthor Commented:
NICE and once again big thanks.
I’m not at work on Tuesdays, I be back at Fridays.
0
 
AmigoJackCommented:
now it should be working like youre expecting it. i tried getting the current focus, started another explorer, also got the focus of that. even if "my computer" is displayed (which isnt a real folder) the program gets the focus (whereas the path is then "my computer"). anyhow - simply test it - and say if something still isnt working. but it looks good now :)

i only left one procedure, as it is called at two places. you shouldnt have problems implementing that procedure and the <button1click>-procedure in a dll. registering a hotkey and catching its activation is done by your application, not the dll. so - good luck

=====================START=======================
Unit Unit1;
//
// Sujet : Position des icônes sur le bureau
//
// Par Nono40 : http://nono40.developpez.com   http://nono40.fr.st
//              mailTo:nono40@fr.st
//
// Le 18/05/2003
//

Interface

Uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, shlobj;

Type
  TForm1 = Class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  Private
    { Déclarations privées }
  protected
    procedure WndProc(var Message: TMessage); override;
  Public
    { Déclarations publiques }
  End;

Var
  Form1: TForm1;

Implementation

{$R *.dfm}

Const
  // listview and item messages
  LVM_FIRST                        = $1000;
  LVM_GETITEMCOUNT                 = LVM_FIRST+ 4;
  LVM_GETITEM                      = LVM_FIRST+ 5;

  // item constants
  LVIF_TEXT                        = $0001;
  LVIF_STATE                       = $0008;

  // item states
  LVIS_FOCUSED                     = $0001;
  LVIS_SELECTED                    = $0002;

Type
  // item struct (i know nowadays this slightly differs, but this seems to work also)
  TLV_ITEM= Record
    mask        : Cardinal;
    iItem       : Integer;
    iSubItem    : Integer;
    state       : Cardinal;
    stateMask   : Cardinal;
    pszText     : Pointer;
    cchTextMax  : Integer;
    iImage      : Integer;
    _lParam     : LPARAM;
  End;

  // a custom extension to meet our needs :)
  PDatas= ^TDatas;
  TDatas= Record
    LV_ITEM  : TLV_ITEM;
    LV_TEXTE : Array[0..255] Of Char;
  End;

  // dynamic function use, so this also runs under win9X
  TVirtualAllocEx= Function(hProcess: THandle; lpAddress: Pointer; dwSize, flAllocationType: DWORD; flProtect: DWORD): Pointer; stdcall;
  TVirtualFreeEx= Function(hProcess: THandle; lpAddress: Pointer; dwSize, dwFreeType: DWORD): Pointer; stdcall;

Const
  TailleMap= SizeOf(TDatas);

// capture messages
procedure TForm1.WndProc(var Message: TMessage);
begin
  if message.msg= WM_HOTKEY then begin  // hotkey pressed
    case message.WParam of  // which one?
      1: Button1Click(nil);
    end;
    exit;
  end;
  inherited WndProc(Message);
end;

// write the memory-mapped data
Procedure EcriturePartage(WindowsNT: Boolean; ProcessLV: Cardinal; var DatasLV: PDatas; Datas: TDatas);
Var N: Cardinal;
Begin
  If WindowsNT Then WriteProcessMemory(ProcessLV, DatasLV, @Datas, SizeOf(Datas), N)
               Else DatasLV^:= Datas;
End;

Procedure TForm1.Button1Click(Sender: TObject);
Var
  i1, i2: Integer;
  s: string;

  HandleMAP,  // for win9X
  HandleCB,  // handle combobox
  HandleLV  :THandle;  // handle listview
  ProcessLV :Cardinal; // handle explorer process
  DatasLV   :PDatas;   // pointer to our info of...
  Datas     :TDatas;   // the item-captions itself
  ProcessID,
  N         : Cardinal;

  WindowsNT      :Boolean;  // win9X?
  VirtualAllocEx :TVirtualAllocEx;
  VirtualFreeEx  :TVirtualFreeEx;

Begin
  edit1.Text:= '<no item focused>';  // suspect nothing is focused, like an empty

  HandleCB:= FindWindowEx(GetForeGroundWindow, 0, 'WorkerW'         , nil);
  if HandleCB= 0 then begin
    HandleLV:= FindWindowEx(0       , 0, 'ExploreWClass'   , Nil);
    HandleCB:= FindWindowEx(HandleLV, 0, 'WorkerW'         , nil);
  end else HandleLV:= GetForeGroundWindow;
  HandleCB:= FindWindowEx(HandleCB, 0, 'ReBarWindow32'   , nil);
  HandleCB:= FindWindowEx(HandleCB, 0, 'ComboBoxEx32'    , nil);  // we got the combobox
  HandleLV:= FindWindowEx(HandleLV, 0, 'SHELLDLL_DefView', Nil);
  HandleLV:= FindWindowEx(HandleLV, 0, 'SysListView32'   , Nil);  // we got the listview

  if (HandleLV= 0) or (HandleCB= 0) then exit;  // no explorer exists

  WindowsNT:= Win32Platform= VER_PLATFORM_WIN32_NT;
  If WindowsNT Then Begin  // assign functions
    @VirtualAllocEx:= GetProcAddress(GetModuleHandle('KERNEL32.DLL'), 'VirtualAllocEx');
    @VirtualFreeEx := GetProcAddress(GetModuleHandle('KERNEL32.DLL'), 'VirtualFreeEx');
  End;

  If WindowsNT Then Begin
    GetWindowThreadProcessId(HandleLV, @ProcessID);  // get pid of listview
    ProcessLV:= OpenProcess(PROCESS_ALL_ACCESS, False, ProcessID);  // obtain rights to operate memory
    // Allocation d'une zone dans le Process obtenu
    DatasLV:= VirtualAllocEx(ProcessLV, Nil, TailleMAP, MEM_COMMIT, PAGE_READWRITE);
  End Else Begin
    HandleMAP:= CreateFileMapping(
          $FFFFFFFF           // Handle mémoire
          ,Nil                // Sécurité par défaut
          ,PAGE_READWRITE     // Accès en lecture/écriture
          ,0                  // Taille de la zone partagée   HIGH
          ,TailleMAP          // Taille de la zone partagée   LOW
          ,'LISTVIEWINFO');   // Nom du partage
    DatasLV:= MapViewOfFile(
          HandleMAP           // Handle du partage mémoire
          ,FILE_MAP_WRITE     // Accès en lecture/écriture
          ,0                  // Début de la zone  HIGH
          ,0                  // Début de la zone  LOW
          ,0);                // Zone entière
  End;
  Datas.LV_ITEM.pszText   := @(DatasLV^.LV_TEXTE);
  Datas.LV_ITEM.cchTextMax:= SizeOf(Datas.LV_TEXTE);
  EcriturePartage(WindowsNT, ProcessLV, DatasLV, Datas);

  setlength(s, 300);  // reserve some space
  i1:= SendMessage(HandleCB, WM_GETTEXT, 300, longint(@s[1]));  // get combobox content
  setlength(s, i1);  // set string to the length we actually got
  if s[length(s)]<> '\' then s:= s+ '\';

  // get count of items
  i2:= SendMessage(HandleLV, LVM_GETITEMCOUNT, 0, 0);
  // check every item listed
  For i1:= 0 To i2- 1 Do Begin
    Datas.LV_ITEM.mask       := LVIF_TEXT or LVIF_STATE;  // we want the text and the state of the item
    Datas.LV_ITEM.iItem      := i1;  // for the "i"th item
    Datas.LV_ITEM.iSubItem   := 0;  // no subitem = item itself
    Datas.LV_ITEM.state      := 0;  // ensure blank
    Datas.LV_ITEM.stateMask  := $FFFF;  // we want all states

    EcriturePartage(WindowsNT, ProcessLV, DatasLV, Datas);
    SendMessage(HandleLV, LVM_GETITEM, 0, Integer(DatasLV));
    If WindowsNT Then ReadProcessMemory(ProcessLV, DatasLV, @Datas, SizeOf(Datas), N)
                 Else Datas:= DatasLV^;

    // only one item can have the focus, so here we check
    if Datas.LV_ITEM.state and LVIS_FOCUSED<> 0 then edit1.Text:= s+ Datas.LV_TEXTE;
  End;

  If WindowsNT Then VirtualFreeEx(ProcessLV, DatasLV, 0, MEM_RELEASE) Else Begin
    UnMapViewOfFile(DatasLV);
    CloseHandle(HandleMAP);
  End;
End;

procedure TForm1.FormCreate(Sender: TObject);
begin
  RegisterHotKey(Handle, 1, MOD_WIN, VK_F9);  // register hotkey WIN+F9
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnregisterHotKey(Form1.Handle, 1);
end;

end.
=======================END=========================
0
 
Dark_KingAuthor Commented:
Yes this is great it work 100% as I want.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 12
  • 7
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now