0

I'm trying to make a script cycle views in Windows Explorer (Windows 7 libraries don't allow remembering view settings per folder).

I found postMessage with the WM_COMMAND message (code 0x111), but can't seem to use it to affect the Explorer view. Nothing happens when I send:

PostMessage,0x111,0x702c,0,,ahk_id %parent%

where %parent% is the handle of the window. Examples on the forums are for Windows XP, which seems to work differently. How to get and set the view setting?

user4157124
  • 2,809
  • 13
  • 27
  • 42
jiggunjer
  • 1,905
  • 1
  • 19
  • 18

2 Answers2

0

You can try the following. It starts a persistent script that runs a timer subroutine looking for Save-As type windows, and when it encounters one, it sends that found window certain key strokes. Note, the keys to send WILL DEFINITELY DEPEND on which Win version you use -- and I had trouble with the standard Win 7 shortcuts and hence used a kludgey work-around. It should be clear from the comments in the code what I am doing, and this should get you on your way to doing what you need.

#Persistent 
SetTitleMatchMode, 2 ; Matches all titles with the designated words in it (picks the top most) 
SetTimer, MaxAll, 150  ;  time in ms
return 

MaxAll: 
IfWinActive, Save MoviePlus File As ; runs only on "Save MoviePlus File As" 
    DoIt("Movie") 
IfWinActive, Save ; runs on "Save" "Save As" "Save File" etc. 
    DoIt("Save") 
IfWinExist, Open ; runs on "Open" "Open File" "File Open" etc. 
    DoIt("Open") 
IfWinExist, Import ; runs on "Import" "File Import" "Import Commands" etc. 
    DoIt("Import") 
return 

DoIt(Type) 
{ 
SetTimer, MaxAll, Off ; turn of timer
sleep, 250
WinMaximize ; maximize the window (or comment out)
sleep, 250 
Send, !n ; start at the Filename textbox 
sleep, 250 
Send, +{tab} ; SHIFT+TAB to move to files pane 
sleep, 250 
; Send, ^+5 ; CTRL+SHIFT+5: Win8.1 to go to "List View"
; Send, ^!5 ; CTRL+ALT+5: Win8 to go to "List View"
; Send, {LAlt}vl ; LEFTALT+V+L: Win7 to go to "List View" - but doesn't work consistently
SendEvent, {F3}{tab}{right 2}{down}{end}{up 3}{enter} ; Navigate to "View" drop-down-list starting from from search bar
sleep, 250 
IfEqual, Type, Open ; If the dialog was a File Open 
    { 
    Send, !p ; ALT+P: Toggles preview pane 
    sleep, 250 
    } 
IfEqual, Type, Movie ; If the dialog was for MoviePlus 
    { 
    Send, ^!p ; Ctrl+ALT+P: Toggles preview pane? Google the keyboard shortcuts (I didn't check)
    sleep, 250 
    } 
Send, !n ; back to Filename textbox 
WinWaitClose ; wait to close the dialog 
SetTimer, MaxAll, On ; turn timer back on 
return 
}

+esc::ExitApp  ;  Shift+Esc ends script

HTH,

PGilm
  • 2,262
  • 1
  • 14
  • 26
  • Btw, you should be able to easily adapt this to run on demand (i.e., with a shortcut) - just eliminate the persistence and timer, give it a shortcut trigger and make it a direct GoTo: `GoTo, MaxAll` and you should have it. – PGilm Jul 06 '16 at 16:04
  • 2
    I understand your script, but unfortunately it is not what I need. To properly cycle the view setting of any Explorer window I need to detect the current state. I think I need some dllcall. – jiggunjer Jul 06 '16 at 17:04
  • IDK, doesn't Win7 always start the explorer window in the same state? What do you mean by "cycle"? If you need to go to any particular state from the starting state, my code can get you there. If you just need a shortcut to change the view (icons, tiles, list, details, etc.), there are built in shortcuts (see comments in my code). If you want an AHK shortcut that goes to the next view from whatever the view you are in, that is trickier, I admit, and may involve keeping a variable to track the view state. Certainly, something along those lines is not that hard. – PGilm Jul 06 '16 at 19:50
  • Also check out here (lot of good info): http://superuser.com/questions/185124/how-to-change-windows-explorer-view-by-keyboard – PGilm Jul 06 '16 at 19:51
  • Win7 remembers the state, except when using libraries. My default view for My Documents library is details, but I want some subfolders to be tiles, others to be list, etc. So when browsing my library, my solution is to have a single hotkey I can press several times until I get the right view (cycle through the 8 states). – jiggunjer Jul 07 '16 at 02:58
  • Changing the view is not really a problem, but incrementing it based on the current window state is. Current hotkey solutions have 8 keys mapped to each view. – jiggunjer Jul 07 '16 at 03:01
  • I understand. You could have a single hot key that picks the specific view depending on which window is open, but that would mean updating the window list on changes and new subfolders. How about a hotkey that first puts you into a default "first" view and, e.g., only while that window was still active, subsequent presses moving to the different views (you could order it any way you prefer). That could be accomplished with a settimer (which is canceled when the window is no longer active), or by setting and storing a variable(s) containing the active window info and current view. – PGilm Jul 07 '16 at 13:50
  • I considered the default + variable method. But it seems a bit ugly for something that should be relatively easy, since the languages even have COM support. – jiggunjer Jul 08 '16 at 15:17
0

Found a UDF for AutoIt that works for me. It's called automating windows explorer. The code below I wrote based on the forum example, it shows a working example of getting the view and changing it by incrementing the existing state.

Since it is for Windows 7 I skip the thumbnail and thumbstrip views--I think those are for Vista. The content view is not supported by Vista either.

I googled the Windows Constants names and values. I found the correct view sizes by experimenting/looking at my own results.

#include "Includes\AutomatingWindowsExplorer.au3"

;Icon sizes are standard: 16, 48, 96, 196
;Details & list: 16
;Tiles: 48
;Content: 32 (!)
;~ FVM_ICON        = 1,  (48, 96, 196)
;~ FVM_SMALLICON   = 2,  (16)
;~ FVM_LIST        = 3,
;~ FVM_DETAILS     = 4,
;~ FVM_THUMBNAIL   = 5,  (seems to be same as ICON in win7)
;~ FVM_TILE        = 6,
;~ FVM_THUMBSTRIP  = 7,  (seems to be same as ICON in win7)
;~ FVM_CONTENT     = 8,

Opt( "MustDeclareVars", 1 )

Example()

Func Example()
  ; Windows Explorer on Vista, 7, 8
  Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" )
  If Not $hExplorer Then
    MsgBox( 0, "Automating Windows Explorer", "Could not find Windows Explorer. Terminating." )
    Return
  EndIf

  ; Get an IShellBrowser interface
  GetIShellBrowser( $hExplorer )
  If Not IsObj( $oIShellBrowser ) Then
    MsgBox( 0, "Automating Windows Explorer", "Could not get an IShellBrowser interface. Terminating." )
    Return
  EndIf

  ; Get other interfaces
  GetShellInterfaces()

  ; Get current icon view
  Local $view = GetIconView() ;returns array [view,size]

  ; Determine the new view
  Local $iView, $iSize, $iNewView, $iNewSize
  $iView = $view[0] ; Icon view
  $iSize = $view[1] ; Icon size
  If $iView = 8 Then
       $iNewView = 1
       $iNewSize = 48
  Else
      $iNewView = $iView + 1
      If $iNewView = 5 Or 7 Then
        $iNewView += 1 ;skip from 5 to 6, or from 7 to 8
      EndIf
  EndIf
  Switch $iNewView
  Case 2 To 4
    $iNewSize = 16
  Case 6
    $iNewSize = 48
  Case 8
    $iNewSize = 32
  EndSwitch

  ;MsgBox( 0, "NewView", $iNewView )
  SetIconView( $iNewView, $iNewSize ) ; Set details view
  Sleep( 1000 )                     ; Wait
  SetIconView( $iView, $iSize )     ; Restore old view
EndFunc
jiggunjer
  • 1,905
  • 1
  • 19
  • 18