【问题标题】:How to get and set Windows Explorer view settings如何获取和设置 Windows 资源管理器视图设置
【发布时间】:2016-07-06 09:28:10
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: windows-7 autohotkey autoit


    【解决方案1】:

    您可以尝试以下方法。它启动一个持久脚本,该脚本运行一个计时器子例程来寻找另存为类型的窗口,当它遇到一个时,它会向找到的窗口发送某些键击。请注意,要发送的密钥绝对取决于您使用的 Win 版本——我在使用标准 Win 7 快捷方式时遇到了问题,因此使用了一个笨拙的解决方法。从代码中的 cmets 中应该可以清楚地看到我在做什么,这应该可以让你按照自己的方式去做你需要做的事情。

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

    【讨论】:

    • 顺便说一句,您应该能够轻松地将其调整为按需运行(即使用快捷方式) - 只需消除持久性和计时器,给它一个快捷方式触发器并使其成为直接 GoTo:@ 987654323@,你应该拥有它。
    • 我理解你的脚本,但不幸的是它不是我需要的。要正确循环任何资源管理器窗口的视图设置,我需要检测当前状态。我想我需要一些 dllcall。
    • IDK,Win7不总是以相同的状态启动资源管理器窗口吗? “循环”是什么意思?如果您需要从起始状态进入任何特定状态,我的代码可以让您到达那里。如果您只需要一个快捷方式来更改视图(图标、图块、列表、详细信息等),则内置快捷方式(请参阅我的代码中的 cmets)。如果您想要一个 AHK 快捷方式,可以从您所在的任何视图转到下一个视图,我承认这比较棘手,并且可能涉及保留一个变量来跟踪视图状态。当然,类似的事情并不难。
    • 也可以在这里查看(很多好的信息):superuser.com/questions/185124/…
    • Win7 会记住状态,除非在使用库时。我的文档库的默认视图是详细信息,但我希望一些子文件夹是图块,其他是列表等。所以在浏览我的库时,我的解决方案是有一个热键,我可以按几次,直到我得到正确的查看(循环通过 8 个状态)。
    【解决方案2】:

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

    因为它适用于 Windows 7,所以我跳过了缩略图和拇指条视图——我认为它们适用于 Vista。 Vista也不支持内容视图。

    我搜索了 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
    

    【讨论】:

      猜你喜欢
      • 2012-05-27
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-06
      • 2018-06-17
      • 1970-01-01
      • 2011-11-20
      相关资源
      最近更新 更多