如何获取和设置Windows资源管理器视图设置

时间:2016-07-06 09:28:11

标签: windows-7 autohotkey autoit

我正在尝试在Windows资源管理器中创建脚本循环视图(Windows 7库不允许记住每个文件夹的视图设置)。

我发现postMessageWM_COMMAND消息(代码0x111),但似乎无法使用它来影响资源管理器视图。发送时没有任何反应:

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

其中%parent%是窗口的句柄。论坛上的示例适用于Windows XP,它似乎有所不同。如何获取和设置视图设置?

2 个答案:

答案 0 :(得分:0)

您可以尝试以下操作。它启动一个持久脚本,运行一个查找Save-As类型窗口的timer子例程,当遇到一个时,它会向找到的窗口发送某些键击。请注意,发送威胁肯定依赖于您使用的Win版本 - 我在使用标准的Win 7快捷方式时遇到了麻烦,因此使用了kludgey解决方法。应该从代码中的注释中清楚地知道我在做什么,这应该可以帮助您完成所需的工作。

#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,

答案 1 :(得分:0)

找到适用于我的AutoIt UDF。它被称为automating windows explorer。我在下面的代码基于论坛示例编写,它显示了一个获取视图并通过递增现有状态来更改它的工作示例。

由于它适用于Windows 7,我跳过缩略图和拇指按钮视图 - 我认为这些是针对Vista的。 Vista也不支持内容视图。

我用Google搜索了Windows常量名称和值。我通过试验/查看自己的结果找到了正确的视图大小。

#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