Jump to content

Embed MS Explorer pane in AutoIt GUI


Zachlr
 Share

Recommended Posts

I'm looking to embed an MS explorer (or similar) pane in a GUI, with which the script can interact (get file paths of selected items). FileOpenDialogue() would be a cheap shortcut, and making my own embedded file explorer would be a project in itself. I hope someone can point me in the right direction.

Thanks,

Zach

Link to comment
Share on other sites

  • Moderators

Zachlr,

Lots of ideas here.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

A few more improvements to that thread (I think)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>

Opt("WinTitleMatchMode", 4)

Global $hMigration, $hExplHolder, $hExplorer, $sStartDir = "C:\"
Global $iWidth = 320, $iHeight = 460

; Create the (left) Explorer GUI
$hExplHolder = GUICreate("Explorer", $iWidth + 300, $iHeight, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_CLIPCHILDREN, $WS_SIZEBOX), 0x00000010)

Run('explorer.exe /n, "' & $sStartDir & '"')
WinWait("[CLASS:CabinetWClass]")

$hExplorer = WinGetHandle("[CLASS:CabinetWClass]")
WinSetState($hExplorer, "", @SW_HIDE)
WinMove($hExplorer, "", 0, 0, $iWidth, $iHeight)

_WinAPI_SetParent($hExplorer, $hExplHolder)
_WinAPI_SetWindowLong($hExplorer, $GWL_STYLE, -1064828928)

ControlListView ($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]", "ViewChange", "list")

$hList = GUICtrlCreateListView ("File", $iWidth + 4, 4, 292, 200, 0x0003 + 0x0008 + 0x0004)
GUICtrlSetState (-1, 8)

WinSetState($hExplorer, "", @SW_SHOW)
GUISetState(@SW_SHOW, $hExplHolder)

While 1
   $msg = GUIGetMsg()
   Switch $msg
      Case -3
         Exit
      Case -13
         GUICtrlCreateListViewItem (@GUI_DRAGFILE, $hList)
   EndSwitch
WEnd

Mat

Edit: With no resizing though...

Edited by Mat
Link to comment
Share on other sites

Thanks for the example, Mat. In fact, no resizing/moving works in my favor for this project. The problem is, I can't see any direct way of getting the selected file. Moving it to the listbox would work, but I'd really like to be able to get the selected file(s) location when a toolbar button is clicked, for example. If you could help me out with this, I'd really appreciate it.

Thanks,

Zach

Link to comment
Share on other sites

ControlListView should do what you want, I'll throw together an example for you soon. It is fairly self explanatory.

Mat

Edit:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>

Opt("WinTitleMatchMode", 4)

Global $hMigration, $hExplHolder, $hExplorer, $sStartDir = "C:\"
Global $iWidth = 320, $iHeight = 460

; Create the (left) Explorer GUI
$hExplHolder = GUICreate("Explorer", $iWidth + 300, $iHeight, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_CLIPCHILDREN, $WS_SIZEBOX), 0x00000010)

Run('explorer.exe /n, "' & $sStartDir & '"')
WinWait("[CLASS:CabinetWClass]")

$hExplorer = WinGetHandle("[CLASS:CabinetWClass]")
WinSetState($hExplorer, "", @SW_HIDE)
WinMove($hExplorer, "", 0, 0, $iWidth, $iHeight)

_WinAPI_SetParent($hExplorer, $hExplHolder)
_WinAPI_SetWindowLong($hExplorer, $GWL_STYLE, -1064828928)

ControlListView ($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]", "ViewChange", "list")

;$hList = GUICtrlCreateListView ("File", $iWidth + 4, 4, 292, 200, 0x0003 + 0x0008 + 0x0004)
;GUICtrlSetState (-1, 8)

$hBtn = GUICtrlCreateButton ("Get selected!", $iWidth + 4, 4, 80, 20)

WinSetState($hExplorer, "", @SW_SHOW)
GUISetState(@SW_SHOW, $hExplHolder)

Local $msg, $sSel, $sRet, $aItems

While 1
   $msg = GUIGetMsg()
   Switch $msg
      Case -3
         Exit
      Case $hBtn
         $sSel = ControlListView ($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]", "GetSelected", 1)
         If StringInStr ($sSel, "|") Then ; Multiple selected items
            $sRet = ""
            $aItems = StringSplit ($sSel, "|")
            For $i = 1 to $aItems[0]
               $sRet &= ControlListView ($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $aItems[$i], 0) & @CRLF
            Next
         Else
            $sRet = ControlListView ($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $sSel, 0)
         EndIf
         MsgBox (0, "", $sRet)
      ;Case -13
      ;   GUICtrlCreateListViewItem (@GUI_DRAGFILE, $hList)
   EndSwitch
WEnd
Edited by Mat
Link to comment
Share on other sites

  • Moderators

Mat,

Thanks for that nice example.

M23

P.S. Where did you come across the "applaud/money" quote? Last time I heard that was from Mike Portnoy with Transatlantic at 013 in Tilburg - however, I would be willing to bet that was not where you got it from! :)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

If you ever get the chance to visit the tate, it's amazing. Round the back is the "Monument to the Unknown Artist". The front has a plaque with a Latin phrase: "Non plaudite. Modo pecuniam jacite.", I just had to google the latin when I got back, it made me laugh so much.

http://londondailyphoto.blogspot.com/2009/09/dont-applaud-just-throw-your-money.html

back on subject, I am working on hiding the Rebar for the explorer, but can't seem to resize the listview. If anyone has any ideas on that it would be very nice :)

Mat

Link to comment
Share on other sites

Thank you very much for the example. It'll work just fine for my program. I didn't know the explorer pane could be treated as a regular ListViews.

Good to know its working, the only bug you might want to look at is when no items are selected, it passes the first one to you.

No progress for me on hiding the rebar, I have a possible method, but I have a funny feeling it will change some settings for proper explorer windows. If I get it working accurately I might even post it in example scripts.

Mat

Edit: This is my next attempt...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>

Opt("WinTitleMatchMode", 4)

Global $hMigration, $hExplHolder, $hExplorer, $sStartDir = "C:\"
Global $iWidth = 320, $iHeight = 460

; Create the Explorer GUI
$hExplHolder = GUICreate("Explorer", $iWidth + 300, $iHeight, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_CLIPCHILDREN, $WS_SIZEBOX), 0x00000010)

Run('explorer.exe /n, "' & $sStartDir & '"')
WinWait("[CLASS:CabinetWClass]")

$hExplorer = WinGetHandle("[CLASS:CabinetWClass]")
WinSetState($hExplorer, "", @SW_HIDE)

$hList = ControlGetHandle ($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]")

ControlListView ($hExplorer, "", $hList, "ViewChange", "list")
_WinAPI_SetParent($hList, $hExplHolder)
WinMove ($hList, "", 2, 2, $iWidth, $iHeight)

$hBtn = GUICtrlCreateButton ("Get selected!", $iWidth + 4, 4, 80, 20)

GUISetState(@SW_SHOW, $hExplHolder)

Local $msg, $sSel, $sRet, $aItems

While 1
   $msg = GUIGetMsg()
   Switch $msg
      Case -3
         ExitLoop
      Case $hBtn
         $sSel = ControlListView ($hExplHolder, "", $hList, "GetSelected", 1)
         If StringInStr ($sSel, "|") Then ; Multiple selected items
            $sRet = ""
            $aItems = StringSplit ($sSel, "|")
            For $i = 1 to $aItems[0]
               $sRet &= ControlListView ($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $aItems[$i], 0) & @CRLF
            Next
         Else
            $sRet = ControlListView ($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $sSel, 0)
         EndIf
         MsgBox (0, "", $sRet)
   EndSwitch
WEnd

WinClose ($hExplorer)

No context menus, they appear to be handled by the window itself. It does mean you could potentially set your own context menu to it, though I am unsure how I might go about that. Basically, it deals only with the listview, and steals it off the explorer window. I think this is as good as its going to get at the moment :)

Edited by Mat
Link to comment
Share on other sites

Good to know its working, the only bug you might want to look at is when no items are selected, it passes the first one to you.

No progress for me on hiding the rebar, I have a possible method, but I have a funny feeling it will change some settings for proper explorer windows. If I get it working accurately I might even post it in example scripts.

Mat

Edit: This is my next attempt...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>

Opt("WinTitleMatchMode", 4)

Global $hMigration, $hExplHolder, $hExplorer, $sStartDir = "C:\"
Global $iWidth = 320, $iHeight = 460

; Create the Explorer GUI
$hExplHolder = GUICreate("Explorer", $iWidth + 300, $iHeight, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_CLIPCHILDREN, $WS_SIZEBOX), 0x00000010)

Run('explorer.exe /n, "' & $sStartDir & '"')
WinWait("[CLASS:CabinetWClass]")

$hExplorer = WinGetHandle("[CLASS:CabinetWClass]")
WinSetState($hExplorer, "", @SW_HIDE)

$hList = ControlGetHandle ($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]")

ControlListView ($hExplorer, "", $hList, "ViewChange", "list")
_WinAPI_SetParent($hList, $hExplHolder)
WinMove ($hList, "", 2, 2, $iWidth, $iHeight)

$hBtn = GUICtrlCreateButton ("Get selected!", $iWidth + 4, 4, 80, 20)

GUISetState(@SW_SHOW, $hExplHolder)

Local $msg, $sSel, $sRet, $aItems

While 1
   $msg = GUIGetMsg()
   Switch $msg
      Case -3
         ExitLoop
      Case $hBtn
         $sSel = ControlListView ($hExplHolder, "", $hList, "GetSelected", 1)
         If StringInStr ($sSel, "|") Then ; Multiple selected items
            $sRet = ""
            $aItems = StringSplit ($sSel, "|")
            For $i = 1 to $aItems[0]
               $sRet &= ControlListView ($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $aItems[$i], 0) & @CRLF
            Next
         Else
            $sRet = ControlListView ($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $sSel, 0)
         EndIf
         MsgBox (0, "", $sRet)
   EndSwitch
WEnd

WinClose ($hExplorer)

No context menus, they appear to be handled by the window itself. It does mean you could potentially set your own context menu to it, though I am unsure how I might go about that. Basically, it deals only with the listview, and steals it off the explorer window. I think this is as good as its going to get at the moment :)

Hi,

I really like this script. I like how it shows just the list view, but it doesn't have a path field. I suppose you could use a separate control, such as a combo box or input, as a path field, but I wouldn't know how to send that information to the list view. Additionally, the lack of a context menu isn't really a problem, and being able to make a custom context menu would be great.

Unfortunately, when I ran that script, I noticed some problems. The Get Selected button seems to display 0, regardless of the selection. Moreover, the Get Selection button causes the GUI to "freak out;" rapidly activating and deactivating the window. In addition, once a folder is double clicked, it disappears, and seems to cause other items to disappear when moused-over.

Again, thanks for providing this code. I really like the concept, but like I said, it has some bugs, and I wouldn't know how to fix them. I hope you can get everything working.

Thanks, Zach

Link to comment
Share on other sites

There is definitely some problems in there with the listview, and its not acting very logically...

I am working on it, but there are a lot of problems to overcome conceptually before I even begin fine tuning it.

as for double clicking, its redrawing the window:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>

Opt("WinTitleMatchMode", 4)

Global $hMigration, $hExplHolder, $hExplorer, $sStartDir = "C:\"
Global $iWidth = 320, $iHeight = 460

; Create the Explorer GUI
$hExplHolder = GUICreate("Explorer", $iWidth + 300, $iHeight, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_CLIPCHILDREN, $WS_SIZEBOX), 0x00000010)

Run('explorer.exe /n, "' & $sStartDir & '"')
WinWait("[CLASS:CabinetWClass]")

$hExplorer = WinGetHandle("[CLASS:CabinetWClass]")
;WinSetState($hExplorer, "", @SW_HIDE)

$hList = ControlGetHandle ($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]")

ControlListView ($hExplorer, "", $hList, "ViewChange", "list")
_WinAPI_SetParent($hList, $hExplHolder)
WinMove ($hList, "", 2, 2, $iWidth, $iHeight)

$hBtn = GUICtrlCreateButton ("Get selected!", $iWidth + 4, 4, 80, 20)

GUISetState(@SW_SHOW, $hExplHolder)

Local $msg, $sSel, $sRet, $aItems

While 1
   $msg = GUIGetMsg()
   Switch $msg
      Case -3
         ExitLoop
      Case $hBtn
         $sSel = ControlListView ($hExplHolder, "", $hList, "GetSelected", 1)
         If StringInStr ($sSel, "|") Then ; Multiple selected items
            $sRet = ""
            $aItems = StringSplit ($sSel, "|")
            For $i = 1 to $aItems[0]
               $sRet &= ControlListView ($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $aItems[$i], 0) & @CRLF
            Next
         Else
            $sRet = ControlListView ($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]", "GetText", $sSel, 0)
         EndIf
         MsgBox (0, "", $sRet)
   EndSwitch
WEnd

WinClose ($hExplorer)

As said, work is being done on it.

Mat

Link to comment
Share on other sites

Yeah, I understand. I'm glad you're continuing to work on it though :). It's a great script. I'll just have to use the full embedded window for now, but I'll keep my eye out for the finished product, if you do decide to release it in the example forum.

The script you posted above didn't seem to fix the problem. Are you saying that the window must be shown in order for it to correctly redraw the AutoIt GUI?

Thanks,

Zach

Link to comment
Share on other sites

  • 4 years later...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>

Opt("WinTitleMatchMode", 4)

Global $hMigration, $hExplHolder, $hExplorer, $sStartDir = "C:\"
Global $iWidth = @DesktopWidth - 200, $iHeight = @DesktopHeight - 200

; Create the (left) Explorer GUI
$hExplHolder = GUICreate("Explorer", $iWidth, $iHeight, Default, Default)

Run('explorer.exe /n, "' & $sStartDir & '"')
WinWait("[CLASS:CabinetWClass]")

$hExplorer = WinGetHandle("[CLASS:CabinetWClass]")
WinSetState($hExplorer, "", @SW_HIDE)
WinMove($hExplorer, "", 0, 0, $iWidth, $iHeight)

_WinAPI_SetParent($hExplorer, $hExplHolder)
_WinAPI_SetWindowLong($hExplorer, $GWL_STYLE, -1064828928)

ControlListView($hExplorer, "", "[CLASS:SysListView32; INSTANCE:1]", "ViewChange", "list")

$hList = GUICtrlCreateListView ("File", $iWidth + 4, 4, 292, 200, 0x0003 + 0x0008 + 0x0004)
GUICtrlSetState (-1, 8)

WinSetState($hExplorer, "", @SW_SHOW)
GUISetState(@SW_SHOW, $hExplHolder)

While 1
   $msg = GUIGetMsg()
   Switch $msg
      Case -3
         Exit
      Case -13
         GUICtrlCreateListViewItem (@GUI_DRAGFILE, $hList)
   EndSwitch
WEnd

Made it full screen so the person can see everything without that sidebar junk that was going on. Try this instead and change it to your code. 

:thumbsup:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...