CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Oct 2005
    Posts
    526

    open a folder and select the specified file ?

    ShellExecute(GetSafeHwnd(),_T("open"),_T("explorer"),_T("D:\\interface source"),NULL,SW_SHOW);

    the code above can open the folder,but want to achieve a further request,
    I want to select a specified file in it ( you know make it hight-lighted).

    my approach is to find out the window refers to the process of "explorer",
    get its handle,send a message to its list control within it.such approach make my program quite complicated.

  2. #2
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Smile Re: open a folder and select the specified file ?

    Quote Originally Posted by suchuhui80
    I want to select a specified file in it .( you know make it hight-lighted).
    using CFileDialog or not?
    If I Helped You, "Rate This Post"

    Thanks
    Guna

  3. #3
    Join Date
    Oct 2005
    Posts
    526

    Re: open a folder and select the specified file ?

    of course not.only that window opened by system (you know what I say).

  4. #4
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Re: open a folder and select the specified file ?

    i can't underswtand ur problem can u explain?
    If I Helped You, "Rate This Post"

    Thanks
    Guna

  5. #5
    Join Date
    Oct 2005
    Location
    Bangalore
    Posts
    1,051

    Re: open a folder and select the specified file ?

    seems like you are tryin to implement a explorer kinda API ....you might wanna look at these links
    Treeview Control
    CTreeFileCtrl & CSortedArray v1.06
    - Sreehari
    "Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
    " Everybody is sent to Earth on a purpose. I am so Lagging behind that i won't die." – Calvin

  6. #6
    Join Date
    Oct 2005
    Posts
    526

    Re: open a folder and select the specified file ?

    I am not going to implement a explorer,
    all I want to do is to have the explorer openned the folder of the specified file and select the file.
    The former can be easy achieved by the code below :
    ShellExecute(GetSafeHwnd(),_T("open"),_T("explorer"),_T("D:\\interface source"),NULL,SW_SHOW);
    but how to achieve the second one ?
    This is the explicitest way I can clarify.

  7. #7
    Join Date
    May 2005
    Posts
    4,954

    Re: open a folder and select the specified file ?

    Quote Originally Posted by suchuhui80
    my approach is to find out the window refers to the process of "explorer",
    get its handle,send a message to its list control within it.such approach make my program quite complicated.
    What’s so complicated in that approach?
    ::FindWindow()/::FindWindowEx() and ::SendMessage() ?

    Another way you can consider is after launching Explorer, set the focus to the file list window, and then simply emulate keyboard keys with the file name that you want to select.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  8. #8
    Join Date
    Oct 2005
    Posts
    526

    Re: open a folder and select the specified file ?

    Quote Originally Posted by golanshahar
    What’s so complicated in that approach?
    ::FindWindow()/::FindWindowEx() and ::SendMessage() ?

    Another way you can consider is after launching Explorer, set the focus to the file list window, and then simply emulate keyboard keys with the file name that you want to select.

    Cheers
    I know somes of sofeware can achieve my request,that seems cool.
    And I know definitely that someone has successfully written this similar
    routine before,I will be appreciated being given help.

    thank you golanshahar. if I finally can't figure it out,I should have considered two ways,one is what I considered it to be complicated,
    another is your non-precise and non-reliable approach ( I mean no offence :-) ). thanks.

  9. #9
    Join Date
    May 2005
    Posts
    4,954

    Re: open a folder and select the specified file ?

    Quote Originally Posted by suchuhui80
    thank you golanshahar. if I finally can't figure it out,I should have considered two ways,one is what I considered it to be complicated,
    Why you think its complicated? using ::FindWindow(..) and ::SendMessage(..) ? What’s so complicated about it? By the time are replying this thread you could have written this “complicated” program 100 times
    If you have problem using those functions simply ASK! Don’t say it complicated.

    Quote Originally Posted by suchuhui80
    another is your non-precise and non-reliable approach ( I mean no offence :-) ). thanks.
    What’s non precise and non-reliable here? I do agree that the "complicated" solution using ::FindWindow(..) and ::SendMessage(..) is more correct. My solution is simply simulating user action, when you open Explorer and set focus to the file list when you start typing the name of the file you want it will get selected, are you saying that this approach of explorer is non-reliable and non precise?

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  10. #10
    Join Date
    Oct 2005
    Posts
    526

    Wink Re: open a folder and select the specified file ?

    Quote Originally Posted by golanshahar
    Why you think its complicated? using ::FindWindow(..) and ::SendMessage(..) ? What’s so complicated about it? By the time are replying this thread you could have written this “complicated” program 100 times
    If you have problem using those functions simply ASK! Don’t say it complicated.



    What’s non precise and non-reliable here? I do agree that the "complicated" solution using ::FindWindow(..) and ::SendMessage(..) is more correct. My solution is simply simulating user action, when you open Explorer and set focus to the file list when you start typing the name of the file you want it will get selected, are you saying that this approach of explorer is non-reliable and non precise?

    Cheers
    thanks for replying.
    maybe we can discuss this issue if it really do not occupy much of your invaluable time.In my defense, I consider the fomer solution to be complicated because I alway consider that there should be a shortcut ( for example,changing the param for ::ShellExecute(),or simplely invoking a API ).For the second solution,it's difficult to find out the specified folder window,what if there are two alike title of this sort of window ? Besides,
    if I successfully get the handle of my specified folder window and I try to
    imitate user action to select the file,what if the fold has a sub-folder with the same name ? what if the fold has a file with the same name ? Besides,what if ,no what if again for this will make my thread lengthy.
    I am not new to developing software,so it's natural to make software more precise and more reliable :-).
    Last edited by suchuhui80; March 17th, 2006 at 08:39 PM.

  11. #11
    Join Date
    May 2005
    Posts
    4,954

    Re: open a folder and select the specified file ?

    Quote Originally Posted by suchuhui80
    what if there are two alike title of this sort of window ?
    In that case you need also check that the EXE is Explorer and not something else.
    Or that the class name of the window is "ExploreWClass" which is the class of explorer (at least in windows XP ).
    If you got 2 Explorers open i don’t think its a problem cause if i understand what you need to do you can simply open one of them.

    Quote Originally Posted by suchuhui80
    Besides,
    if I successfully get the handle of my specified folder window and I try to
    imitate user action to select the file,what if the fold has a sub-folder with the same name ?
    Here it might fails (it will select the first of the two it will run into that’s depend on the current sorting of explorer) , that’s why even in my last post I told you that this solution is less good than the first one.

    Quote Originally Posted by suchuhui80
    what if the fold has a file with the same name ? Besides,what if ,no what if again for this will make my thread lengthy.
    I am not new to developing software,so it's natural to make software more precise and more reliable :-).
    There cant be a folder like the file name under the same folder, Explorer wont let it, unless you have file with the same name with an extension (maybe the extension is hidden so it looks like you have folder and file with the same name).

    BTW another way to look for the items in Explorer by using Active accessibility.


    Cheers
    Last edited by golanshahar; March 18th, 2006 at 07:21 AM.
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  12. #12
    Join Date
    Oct 2005
    Posts
    526

    Cool Re: open a folder and select the specified file ?

    Quote Originally Posted by golanshahar

    BTW another way to look for the items in Explorer by using Active accessibility.


    Cheers
    what is meaning of " active accessibility" ?

    may I enlist your help a little further ?:-)

  13. #13
    Join Date
    Oct 2005
    Posts
    526

    Smile Re: open a folder and select the specified file ?

    it's fortunate that the invention of the Internet offers me who is unforunate to stay at non-software corp a way to ask somebody else.

  14. #14
    Join Date
    May 2005
    Posts
    4,954

    Re: open a folder and select the specified file ?

    Quote Originally Posted by suchuhui80
    what is meaning of " active accessibility" ?

    may I enlist your help a little further ?:-)
    Sure

    Here is the link Active Accessibility.
    It will enable you to get the data from file explorer.
    Download the AccExplorer32.exe run it and look at the File explorer file list you should be able to grab all the text from there. (This tool is used similar to Spy++ )

    You can also look at this thread to see how to use ::AccessibleObjectFromWindow(..).

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  15. #15
    Join Date
    Jul 2003
    Posts
    731

    Re: open a folder and select the specified file ?

    I am trying to do the same thing. I open the folder in explore but want the concerned file to be selected as well in that folder.

    How do I use ::FindWindow(..) and ::SendMessage(..) to implement this? because the other method is the OLE and I don't want to go with OLE for this.
    Good Answers, Good Points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured