2016-07-06 133 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

相關問題