Windows 10 Explorer View change

Post your working scripts, libraries and tools for AHK v1.1 and older
ludamo
Posts: 44
Joined: 25 Mar 2015, 02:21

Windows 10 Explorer View change

05 Dec 2016, 22:45

Windows 10 Explorer View change using inbuilt Status Bar icons. Win 10, ImageSearch, QTTabBar.

After migrating to Windows 10 I was keen to learn the new Explorer but don't really like the Ribbon and was disappointed that there were only two icons on the far right of the Status Bar and not my favourite, which is List view. I wrote some code so that R-clicking on these icons would give me a shortcut to two other favourite views. When I started using QTTabBar I had to revise the original code (as it had worked by getting the position in the window (bottom RH corner) of the icons) to something else which would detect the icons, no matter how many times and wherever they were repeated. After some time I found that using ImageSearch and looking for the top left 12x12 pixels of the icons, in both hover and pressed form worked well. 27px and 28px are the width and height of the full icon on the Status Bar.

I used Software: Zoom+ to copy the screen image to clipboard and then pasted into Greenfish Icon Editor Pro to edit and save top left 12x12px of the icons.
To do this on your own Win 10 system I think you will have to make your own icon files - varying on theme / resolution etc. Make two files for each icon, one for hover and one for pressed. That is 4 image files total.

Code: Select all

#IfWinActive, ahk_class CabinetWClass						; Win 10 Explorer changing View settings
*~RButton::
	MouseGetPos, mX, mY, hWnd, ctrlNN, 1					; determine where mouse is clicked
	; CoordMode, Pixel, Screen							; may be needed
	; CoordMode, Mouse, Screen							; may be needed
	; search around where Mouse is clicked for each image
	ImageSearch, CS2_X, CS2_Y, mX-27, mY-28, mX+12, mY+12, *w0 *h0 explorer-view-2h.ico		; hover icon for large thumbnails (Ctrl+Shift+2)
	If not CS2_X
		ImageSearch, CS2_X, CS2_Y, mX-27, mY-28, mX+12, mY+12, *w0 *h0 explorer-view-2p.ico	; pressed icon for large thumbnails (Ctrl+Shift+2)
		
	If CS2_X
	{	Tooltip, Change View to Extra Large Icons (Ctrl+Shift+1)						; can be changed to personal favourite etc
		KeyWait, RButton
		Send ^+1	; correct window frame is already focused due to R Click
	}
	Else
	{	ImageSearch, CS6_X, CS6_Y, mX-27, mY-28, mX+12, mY+12, *w0 *h0 explorer-view-6h.ico		; hover icon for details view (Ctrl+Shift+6)
		If not CS6_X
			ImageSearch, CS6_X, CS6_Y, mX-27, mY-28, mX+12, mY+12, *w0 *h0 explorer-view-6p.ico	; pressed icon for details view (Ctrl+Shift+6)
		If CS6_X
		{	Tooltip, Change to List View (Ctrl+Shift+5)								; can be changed to personal favourite etc
			KeyWait, RButton
			Send ^+5	; correct window frame is already focused due to R Click
		}
	}	

	Sleep, 3000
	Tooltip
	Return
ludamo
Posts: 44
Joined: 25 Mar 2015, 02:21

Re: Windows 10 Explorer View change

12 Mar 2017, 00:50

After stumbling upon the "ShellView" SHELLDLL_DefView window messages following R-click menu in Win 10 Explorer - detected using Microsoft® Spy ++ x64 (free with Visual Studio® 15 Community Edition) as follows:

Extra large icons = 28749 = 0x0704D
Large icons = 28751 = 0x0704F
Medium icons = 28750 = 0x0704E
Small icons = 28752 = 0x07050
List = 28753 = 0x07051
Details = 28747 = 0x0704B
Tiles = 28748 = 0x0704C
Content = 28754 = 0x07052

I was able to modify the code to send a message instead of sending the Hotkey (which may have focus issues).

Code: Select all

#IfWinActive, ahk_class CabinetWClass						; Win 10 Explorer changing View settings
~RButton::
	MouseGetPos, mX, mY, hWnd, ctrlNN, 1					; determine where mouse is clicked
	; CoordMode, Pixel, Screen							; may be needed
	; CoordMode, Mouse, Screen							; may be needed
	; search around where Mouse is clicked for each image
	If InStr(ctrlNN, "DirectUIHWND")
	{	
		ControlGet, hWndP, Hwnd,, %ctrlNN%, ahk_id %hWnd%						; This "DirectUIHWND" window is an ANCESTOR / PARENT window
		If not Address  														; Fast-mode is okay because it will be called only from this thread
		Address := RegisterCallback("EnumChildProc", "Fast")						; fn to detect "ShellView" SHELLDLL_DefView (message) CHILD Window
		rtn := DllCall("EnumChildWindows", "UInt", hWndP, "Ptr", Address, "UInt", 0)
		
		ImageSearch, CS2_X, CS2_Y, mX-27, mY-28, mX+12, mY+12, *w0 *h0 explorer-view-2h.ico		; hover icon for large thumbnails (Ctrl+Shift+2)
		If not CS2_X
			ImageSearch, CS2_X, CS2_Y, mX-27, mY-28, mX+12, mY+12, *w0 *h0 explorer-view-2p.ico	; pressed icon for large thumbnails (Ctrl+Shift+2)
		
		If CS2_X
		{	Tooltip, Change View to Extra Large Icons (Ctrl+Shift+1)						; can be changed to personal favourite etc
			; Send +{Tab}														; focuses pane								
			; KeyWait, RButton
			; Send ^+1
			SendMessage, 0x0111, 0x704D, 0, , ahk_id %_ShellView%						; 0x0111=WM_COMMAND
		}
		Else
		{	ImageSearch, CS6_X, CS6_Y, mX-27, mY-28, mX+12, mY+12, *w0 *h0 explorer-view-6h.ico		; hover icon for details view (Ctrl+Shift+6)
			If not CS6_X
				ImageSearch, CS6_X, CS6_Y, mX-27, mY-28, mX+12, mY+12, *w0 *h0 explorer-view-6p.ico	; pressed icon for details view (Ctrl+Shift+6)
			If CS6_X
			{	Tooltip, Change to List View (Ctrl+Shift+5)								; can be changed to personal favourite etc
				; Send +{Tab}													; focuses pane
				; KeyWait, RButton
				; Send ^+5	
				SendMessage, 0x0111, 0x7051, 0, , ahk_id %_ShellView%					; 0x0111=WM_COMMAND
			}
		}	
	}
	Sleep, 3000
	Tooltip
	Return
	
	EnumChildProc(hWndC, lParam)
	{	; detect Child "ShellView" SHELLDLL_DefView Window
    		global _ShellView
	
		; WinGetTitle, title, ahk_id %hWndC%
    		WinGetClass, class, ahk_id %hWndC%
    		If (class = "SHELLDLL_DefView")
    		{
			_ShellView := hWndC
			Return False							; Tell EnumWindows() to stop
		}
    		Return True  								; Tell EnumWindows() to continue until "ShellView" SHELLDLL_DefView is detected
	}
ludamo
Posts: 44
Joined: 25 Mar 2015, 02:21

Re: Windows 10 Explorer View change

18 Aug 2018, 05:27

A big thanks to Sean, Jethrow and Jeeswg and anyone else who has contributed to the Accessibility functions, especially the AccViewer Basic.ahk.
Using it I have been able to dispense with the need for ImageSearch and constructing icons. Though it doesn't seem to run any faster. Using this on Win 10 Pro Ver 1803.

Code: Select all


#NoEnv
SendMode Input    							; Recommended for new scripts due to its superior speed and reliability.
h := DllCall("LoadLibrary","Str","oleacc.dll","Ptr")
CoordMode, Mouse, Screen

global pECWProc := RegisterCallback("EnumChildWndProc", "Fast")		; function to detect certain child windows
global class, pClassName
VarSetCapacity(class, 256, 0)									; used in EnumChildWndProc()
VarSetCapacity(pClassName, 256, 0)								; used in EnumChildWndProc()
Return

#IfWinActive, ahk_class CabinetWClass								; Win 10 Explorer changing View settings
{															; Microsoft Active Accessibility Client Functions
~RButton::													; MS AAC QPC: 80-154 mSec; ImageSearch QPC: 90-140 mSecs
If MouseGetParent("DUIViewWndClassName")
{	
	StrPut("SHELLDLL_DefView", &pClassName, 17)						; have to send String Address to Function as lParam
	rtn := DllCall("EnumChildWindows", "uint", hCtrl, "ptr", pECWProc, "uint", &pClassName)
															; hCtrl global from MouseGetParent
	ComObjError(False)
	oAcc := AccObjectFromPoint(ChildId,mX,mY)						; mX, mY globals from MouseGetParent
	AccName := oAcc.AccName(ChildId)

	If ( AccName = "Large Icons")
	{	SendMessage, 0x0111, 0x704D, 0, , ahk_id %hChildWnd%			; 0x0111=WM_COMMAND
		Tooltip, Extra Large Icons (Ctrl+Shift+1)						; global hChildWnd from EnumChildWndProc (EnumChildWindows)
	}
	Else If ( AccName = "Details")
	{	SendMessage, 0x0111, 0x7051, 0, , ahk_id %hChildWnd%
		Tooltip, List View (Ctrl+Shift+5)
	}
	TipClose()
	oAcc := ""
	ComObjError(True)
}
	Return
}

MouseGetParent(ParentClassName)
{	global hWnd, hCtrl, lpClassName, mX, mY
	Thread, Priority, 8
	MouseGetPos, mX, mY, hWnd, hCtrl, 2				; stores control's hWnd rather than ClassNN
	hCtrlP:= DllCall("GetParent", "uint", hCtrl)				; looking for DirectUIHWND with Parent SHELLDLL_DefView i.e. "ListView" OR
	VarSetCapacity( lpClassName, 256, 0 )				; looking for DirectUIHWND with Parent DUIViewWndClassName i.e. "StatusBar"
	DllCall("GetClassName", "uint", hCtrlP, "str", lpClassName, "int", 255 ) ; gets Class without NN (similar to WinGetClass)
	If (lpClassName = ParentClassName) {
		Return 1
	}
}

AccObjectFromPoint(ByRef _idChild_ = "", x = "", y = "")
{
    if (DllCall("oleacc\AccessibleObjectFromPoint"
              , "Int64", x == ""||y==""
                         ? 0 * DllCall("GetCursorPos","Int64*",pt) + pt
                         : x & 0xFFFFFFFF | y << 32
              , "Ptr*", pacc
              , "Ptr", VarSetCapacity(varChild, 8 + 2 * A_PtrSize, 0) * 0 + &varChild) = 0) {
        _idChild_:=NumGet(varChild,8,"UInt")
        ; return ComObjEnwrap(9,pacc,1)
        return ComObject(9,pacc,1), ObjAddRef(DispPtr)
    }
}

EnumChildWndProc(hWndC, lParam)
{	; detect Child lParam Window
    global class, hChildWnd
	DllCall("GetClassName", "uint", hWndC, "str", class, "int", 255) 	; QPC 0.015 - 0.03 mSecs, gets Class without NN (similar to WinGetClass)
    If (class = StrGet(lParam))
    {	
		hChildWnd := hWndC
		Return False	; Tell EnumChildWindows() to stop
	}
    Return True  		; Tell EnumChildWindows() to continue looking for lParam
}

TipClose(period=-3000, priority=0, TTn=1)						; period e.g. -2000 to -5000
{	
	ListLines, Off
	SetTimer, _TipClose, %period%, %priority%
	ListLines, On
	Return
	
_TipClose:
	TrayTip
	ToolTip,,,, %TTn%
	Return
}


Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: hiahkforum and 155 guests