如何获取和设置 Windows 资源管理器视图设置 [英] How to get and set Windows Explorer view settings
问题描述
我正在尝试在 Windows 资源管理器中创建脚本循环视图(Windows 7 库不允许记住每个文件夹的视图设置).
I'm trying to make a script cycle views in Windows Explorer (Windows 7 libraries don't allow remembering view settings per folder).
我发现 postMessage
带有 WM_COMMAND
消息(代码 0x111
),但似乎无法使用它来影响资源管理器视图.我发送时什么也没有发生:
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%
其中 %parent%
是窗口的句柄.论坛上的示例适用于 Windows XP,它的工作方式似乎有所不同.如何获取和设置视图设置?
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?
推荐答案
找到适合我的 AutoIt UDF.它被称为 自动化 Windows 资源管理器.下面的代码是我根据论坛示例编写的,它显示了一个通过增加现有状态来获取视图和更改视图的工作示例.
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.
因为它是针对 Windows 7 的,所以我跳过了缩略图和拇指条视图——我认为这些是针对 Vista 的.Vista也不支持内容视图.
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.
我用谷歌搜索了 Windows 常量的名称和值.我通过试验/查看我自己的结果找到了正确的视图大小.
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
这篇关于如何获取和设置 Windows 资源管理器视图设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!