2016-07-06 47 views
0

我想在Windows资源管理器中创建脚本循环视图(Windows 7库不允许记住每个文件夹的视图设置)。如何获取并设置Windows资源管理器视图设置

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

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

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

回答

0

发现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 
0

您可以尝试以下操作。它启动一个运行定时器子程序的持久性脚本,查找Save-As类型窗口,当它遇到一个时,它将发现窗口中的某些键击。请注意,发送密钥将明确取决于您使用的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,

+0

顺便说一句,你应该能够很容易适应这种按需运行(即与快捷方式) - 只是消除持久性和计时器,给它一个快捷键触发,并使其成为直接转到:'转到页, MaxAll',你应该拥有它。 – PGilm

+2

我理解你的脚本,但不幸的是它不是我所需要的。要正确地循环任何资源管理器窗口的视图设置,我需要检测当前状态。我想我需要一些dllcall。 – jiggunjer

+0

IDK,不是Win7总是以相同的状态启动资源管理器窗口? “周期”是什么意思?如果你需要从起始状态进入任何特定状态,我的代码可以让你到达那里。如果您只需要快捷方式来更改视图(图标,图块,列表,详细信息等),则可以使用快捷方式(请参阅我的代码中的注释)。如果你想要一个AHK快捷方式,无论你在哪个视图中进入下一个视图,这都更加棘手,我承认,并且可能需要保留一个变量来跟踪视图状态。当然,沿着这些路线的东西并不难。 – PGilm

相关问题