-
Jun 5th, 2006, 09:17 PM
#1
Thread Starter
PowerPoster
[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.
-
Jun 5th, 2006, 09:25 PM
#2
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
-
Jun 5th, 2006, 09:37 PM
#3
Thread Starter
PowerPoster
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.
-
Jun 6th, 2006, 05:45 AM
#4
Thread Starter
PowerPoster
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.
-
Jun 6th, 2006, 05:56 AM
#5
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.
-
Jun 6th, 2006, 06:04 AM
#6
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
-
Jun 6th, 2006, 06:07 AM
#7
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.
-
Jun 6th, 2006, 06:17 AM
#8
Re: brain freeze - how would open a particular folder (in Windows) from my app?
-
Jun 6th, 2006, 06:25 AM
#9
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 )
-
Jun 6th, 2006, 06:33 AM
#10
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
Last edited by bushmobile; Jun 6th, 2006 at 08:07 AM.
-
Jun 6th, 2006, 06:39 AM
#11
Re: brain freeze - how would open a particular folder (in Windows) from my app?
That was fast, bushmobile! (has Merri been programming you ? )
-
Jun 6th, 2006, 08:00 AM
#12
Re: brain freeze - how would open a particular folder (in Windows) from my app?
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
-
Jun 6th, 2006, 08:28 AM
#13
Thread Starter
PowerPoster
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.
-
Jun 6th, 2006, 08:29 AM
#14
Re: brain freeze - how would open a particular folder (in Windows) from my app?
no probs
-
Jun 6th, 2006, 10:52 AM
#15
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".
-
Jan 4th, 2009, 10:49 PM
#16
-
Dec 6th, 2012, 09:32 PM
#17
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|