[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.
Re: brain freeze - how would open a particular folder (in Windows) from my app?
well to open a folder in explorer:
VB Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL As Long = 1
Private Sub Command1_Click()
ShellExecute Me.hwnd, "Open", "C:\TEST\", vbNullString, vbNullString, SW_SHOWNORMAL
End Sub
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?
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.)?
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. :)
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 :blush:
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.
Re: brain freeze - how would open a particular folder (in Windows) from my app?
:blush: See my edit above :blush: :blush:
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 :( )
Re: brain freeze - how would open a particular folder (in Windows) from my app?
woo, got it to work:
VB Code:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Enum FolderView
viewDEFAULT = 0
viewICON = &H7029
viewLIST = &H702B
viewREPORT = &H702C
viewTHUMBNAIL = &H702D
viewTILE = &H702E
End Enum
Private Const SW_SHOWNORMAL As Long = 1
Private Const WM_COMMAND = &H111
Private Sub Command1_Click()
OpenFolder "C:\", viewREPORT
End Sub
Private Sub OpenFolder(ByVal sFolderPath As String, Optional ByVal eView As FolderView = viewDEFAULT)
Dim N As Long, lhWnd As Long, lPrevhWnd As Long
If Len(Dir(sFolderPath, vbDirectory)) = 0 Then Exit Sub
lPrevhWnd = FindWindow("CabinetWClass", vbNullString)
ShellExecute Me.hwnd, "Open", sFolderPath, vbNullString, vbNullString, SW_SHOWNORMAL
If eView Then
Do
DoEvents: N = N + 1
lhWnd = FindWindow("CabinetWClass", vbNullString)
Loop Until Not (lPrevhWnd = lhWnd Or lhWnd = 0) Or N = 100000
If N = 100000 Or lhWnd = 0 Then Exit Sub
Call Sleep(100)
lhWnd = FindWindowEx(lhWnd, 0&, "SHELLDLL_DefView", vbNullString)
SendMessage lhWnd, WM_COMMAND, ByVal eView, 0&
End If
End Sub
Re: brain freeze - how would open a particular folder (in Windows) from my app?
That was fast, bushmobile! (has Merri been programming you ? :bigyello: :bigyello: )
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 ? :bigyello: :bigyello: )
:lol:
I've made a more robust version and added some functionality. Post #10 has been updated accordingly :)
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.
Re: brain freeze - how would open a particular folder (in Windows) from my app?
Re: brain freeze - how would open a particular folder (in Windows) from my app?
Bush, your code works fine ! :thumb:
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".
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
Re: [RESOLVED]brain freeze - how would open a particular folder (in Windows) from my
Tq that code work for me.