Results 1 to 17 of 17

Thread: [RESOLVED]brain freeze - how would open a particular folder (in Windows) from my app?

  1. #1

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Resolved [RESOLVED]brain freeze - how would open a particular folder (in Windows) from my app?

    This has got to be easy but I'm having a brain freeze. What I want to do is, from my app, after the user has provided a folder name (for example "C:\CurrentInvoices\Inv1234"), open that folder in the Windows interface - as if the user moved my app to the side and navigated to that folder from "My Computer" or Windows Explorer.

    Furthermore, if the user is running XP, how could I specify that the folder should be opened in "thumbnail" view (and if not, use large icon view)?

    Any help is much appreciated.
    Last edited by Hack; Jun 6th, 2006 at 10:55 AM.
    "It's cold gin time again ..."

    Check out my website here.

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: brain freeze - how would open a particular folder (in Windows) from my app?

    well to open a folder in explorer:
    VB Code:
    1. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    2.                 ByVal hwnd As Long, _
    3.                 ByVal lpOperation As String, _
    4.                 ByVal lpFile As String, _
    5.                 ByVal lpParameters As String, _
    6.                 ByVal lpDirectory As String, _
    7.                 ByVal nShowCmd As Long) As Long
    8.  
    9. Private Const SW_SHOWNORMAL As Long = 1
    10.  
    11. Private Sub Command1_Click()
    12.     ShellExecute Me.hwnd, "Open", "C:\TEST\", vbNullString, vbNullString, SW_SHOWNORMAL
    13. End Sub

  3. #3

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: brain freeze - how would open a particular folder (in Windows) from my app?

    Thank you very much - that's what I was looking for!

    Any ideas on how to specify the folder view?
    "It's cold gin time again ..."

    Check out my website here.

  4. #4

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: brain freeze - how would open a particular folder (in Windows) from my app?

    Hey folks, what is the feasibility of the second part of this - i.e., open a Windows folder in a particular View (Thumbnail, Large Icon, Detail, etc.)?
    "It's cold gin time again ..."

    Check out my website here.

  5. #5
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: brain freeze - how would open a particular folder (in Windows) from my app?

    All I know is, to set view mode you need to implement the IFolderView interface. It has a SetCurrentViewMode method.

    But unfortunetly I don't know how to do it fron VB.
    I tried standard listview messages, but they are causing problem in report view.

    I hope someone has a better answer.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  6. #6
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: brain freeze - how would open a particular folder (in Windows) from my app?

    This is determined by the contents of the "Desktop.ini" & "Folder.htt" files in any particular folder (unless you've set explorer to use the same view for all folders). Have a look at http://msdn.microsoft.com/library/de...ing/custom.asp and the link to "Web View". I suppose you could create/delete these on the fly...

    ON SECOND THOUGHTS... take a look at this:- http://vbnet.mvps.org/index.html?cod...hooklvview.htm It seems to be similar to what you're looking for
    Last edited by schoolbusdriver; Jun 6th, 2006 at 06:19 AM. Reason: Found more info

  7. #7
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: brain freeze - how would open a particular folder (in Windows) from my app?

    I would prefer not to change user's default view settings of that folder.

    If the folder is a system/protected folder, this may bring many other issues.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  8. #8
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: brain freeze - how would open a particular folder (in Windows) from my app?

    See my edit above

  9. #9
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: brain freeze - how would open a particular folder (in Windows) from my app?

    Looking at that code, it may be possible to to get the explorer window handle and set m_lvInitialView to suit.... (can't do it now - have to go to work )

  10. #10
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: brain freeze - how would open a particular folder (in Windows) from my app?

    woo, got it to work:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    4.                 ByVal hwnd As Long, _
    5.                 ByVal lpOperation As String, _
    6.                 ByVal lpFile As String, _
    7.                 ByVal lpParameters As String, _
    8.                 ByVal lpDirectory As String, _
    9.                 ByVal nShowCmd As Long) As Long
    10.  
    11. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    12.                 ByVal lpClassName As String, _
    13.                 ByVal lpWindowName As String) As Long
    14.  
    15. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    16.                 ByVal hWnd1 As Long, _
    17.                 ByVal hWnd2 As Long, _
    18.                 ByVal lpsz1 As String, _
    19.                 ByVal lpsz2 As String) As Long
    20.  
    21. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    22.                 ByVal hwnd As Long, _
    23.                 ByVal wMsg As Long, _
    24.                 ByVal wParam As Long, _
    25.                 lParam As Any) As Long
    26.    
    27. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    28.  
    29. Private Enum FolderView
    30.     viewDEFAULT = 0
    31.     viewICON = &H7029
    32.     viewLIST = &H702B
    33.     viewREPORT = &H702C
    34.     viewTHUMBNAIL = &H702D
    35.     viewTILE = &H702E
    36. End Enum
    37.  
    38. Private Const SW_SHOWNORMAL As Long = 1
    39. Private Const WM_COMMAND = &H111
    40.  
    41. Private Sub Command1_Click()
    42.     OpenFolder "C:\", viewREPORT
    43. End Sub
    44.  
    45. Private Sub OpenFolder(ByVal sFolderPath As String, Optional ByVal eView As FolderView = viewDEFAULT)
    46.     Dim N As Long, lhWnd As Long, lPrevhWnd As Long
    47.     If Len(Dir(sFolderPath, vbDirectory)) = 0 Then Exit Sub
    48.    
    49.     lPrevhWnd = FindWindow("CabinetWClass", vbNullString)
    50.     ShellExecute Me.hwnd, "Open", sFolderPath, vbNullString, vbNullString, SW_SHOWNORMAL
    51.    
    52.     If eView Then
    53.         Do
    54.             DoEvents: N = N + 1
    55.             lhWnd = FindWindow("CabinetWClass", vbNullString)
    56.         Loop Until Not (lPrevhWnd = lhWnd Or lhWnd = 0) Or N = 100000
    57.        
    58.         If N = 100000 Or lhWnd = 0 Then Exit Sub
    59.         Call Sleep(100)
    60.        
    61.          lhWnd = FindWindowEx(lhWnd, 0&, "SHELLDLL_DefView", vbNullString)
    62.         SendMessage lhWnd, WM_COMMAND, ByVal eView, 0&
    63.     End If
    64. End Sub

  11. #11
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: brain freeze - how would open a particular folder (in Windows) from my app?

    That was fast, bushmobile! (has Merri been programming you ? )

  12. #12
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: brain freeze - how would open a particular folder (in Windows) from my app?

    Quote Originally Posted by schoolbusdriver
    That was fast, bushmobile! (has Merri been programming you ? )


    I've made a more robust version and added some functionality. Post #10 has been updated accordingly

  13. #13

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: brain freeze - how would open a particular folder (in Windows) from my app?

    Thanks to all of you.
    Bushmobile, your code was of great help - thank you very much.
    "It's cold gin time again ..."

    Check out my website here.

  14. #14
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: brain freeze - how would open a particular folder (in Windows) from my app?

    no probs

  15. #15
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: brain freeze - how would open a particular folder (in Windows) from my app?

    Bush, your code works fine !
    I just want to add that,
    I have 'explorer view' (folder tree + file list) as my default view.
    Like,
    Explorer.exe /e, C:\
    In this mode, you need to change the "CabinetWClass" to "ExploreWClass".
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  16. #16
    Lively Member wiz....'s Avatar
    Join Date
    Nov 2008
    Location
    Asia, Earth, Solar System, Milky Way Galaxy, Near Andromeda Galaxy, Universe
    Posts
    78

    Re: [RESOLVED]brain freeze - how would open a particular folder (in Windows) from my app?

    Sorry to revive an old post but I this there is even simpler code to open a folder in the explorer......

    dim
    a = LOCATION OF FILE
    Shell a, vbMaximizedFocus
    PAIN n SUFFERING-Pain is Inevitable,,suffering is optional...........
    WORK EXPECTATION--U can do anything in this world if u don't look for credit.........

  17. #17
    New Member
    Join Date
    Dec 2012
    Posts
    1

    Re: [RESOLVED]brain freeze - how would open a particular folder (in Windows) from my

    Tq that code work for me.

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