Question

Get selected file

Asked by: Dark_King

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.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-05-09 at 06:32:26ID21843462
Tags

delphi

,

get

Topic

Delphi Programming

Participating Experts
5
Points
500
Comments
26

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Delphi Database Explorer problem
    I have several foxpro tables in a local directory, c:\support. In ODBC32, I highlight the Visual Foxpro Database (In User DSN tab), and click Add, then I select Microsoft Visual FoxPro Driver, Click Finish, In the Data Source Name box, I fill Support, then choose Free Table d...
  2. Delphi 'screen grab' component
    Hi, Can anyone recommend a good screen grab component? I'd like it to be pretty flexible and allow me programatically select an area to grab. Thanks.
  3. Codding Problem
    I have a coddint problem I have 4 numeric values from a table that I want to add and then divide into 4 and the result put it in a 5 txtbox, how can I make this happend, Can some one tell me the code, please!!! Thanks Ya'll
  4. ordering the select randomly by cod
    Hello Guy, I have a table with some fields, this table is a questionnaire table for students. See the its structure: COD - integer autonumber Question - String Answer - String Well, what I need is: make a selection randomly to create a test each time that user run the s...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: mikelittlewoodPosted on 2006-05-09 at 07:12:08ID: 16639447

What do u mean "get selected file"?

Do you mean open a file?

 

by: Dark_KingPosted on 2006-05-09 at 07:27:24ID: 16639571

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”

 

by: geobulPosted on 2006-05-09 at 08:16:27ID: 16640025

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

 

by: ciulyPosted on 2006-05-09 at 10:48:03ID: 16641382

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

 

by: Dark_KingPosted on 2006-05-09 at 12:23:57ID: 16642374

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

 

by: heretoreadPosted on 2006-05-10 at 16:16:36ID: 16653942

Dont think there is an easy way, as it would be specific to explorer, you could always try and hook CreateFile();

 

by: AmigoJackPosted on 2006-05-15 at 14:04:15ID: 16685852

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.

 

by: Dark_KingPosted on 2006-05-15 at 23:14:10ID: 16688002

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

 

by: Dark_KingPosted on 2006-05-15 at 23:19:00ID: 16688023

I can only think about some hook to explorer that’s making this work, make any sense?

 

by: ciulyPosted on 2006-05-15 at 23:29:34ID: 16688065

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

 

by: Dark_KingPosted on 2006-05-15 at 23:45:04ID: 16688127

Yea I now I have searching on this for some time now, so for that reason I ask here.

 

by: ciulyPosted on 2006-05-16 at 00:15:56ID: 16688246

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)

 

by: AmigoJackPosted on 2006-05-16 at 01:31:47ID: 16688653

"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

 

by: Dark_KingPosted on 2006-05-16 at 01:54:20ID: 16688751

I’m looking forward to hearing from you.

 

by: AmigoJackPosted on 2006-05-19 at 13:54:17ID: 16721519

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 :/

 

by: Dark_KingPosted on 2006-05-21 at 13:19:16ID: 16729885

“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

 

by: AmigoJackPosted on 2006-05-23 at 12:34:42ID: 16745640

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 :)

 

by: Dark_KingPosted on 2006-05-23 at 23:49:06ID: 16748927

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.

 

by: Dark_KingPosted on 2006-05-23 at 23:55:38ID: 16748954

If I select a file in one open explorer is that windows not in focus then?

 

by: AmigoJackPosted on 2006-05-24 at 00:55:04ID: 16749181

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

 

by: Dark_KingPosted on 2006-05-24 at 01:44:16ID: 16749406

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

 

by: AmigoJackPosted on 2006-05-24 at 01:55:42ID: 16749450

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 :)

 

by: Dark_KingPosted on 2006-05-24 at 11:11:41ID: 16754191

NICE and once again big thanks.
I’m not at work on Tuesdays, I be back at Fridays.

 

by: AmigoJackPosted on 2006-05-24 at 11:20:30ID: 16754275

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

 

by: Dark_KingPosted on 2006-05-26 at 00:27:52ID: 16767049

Yes this is great it work 100% as I want.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...