I share what I have so far from the script. All the more complex work is from @Hellbent modifying @tuzi script (link above). My part is to have adapted it for Total Commander and to have created routine code.
I wanted to have created a DropDownList (or DDL) to select the color, but I found a GUI with slide controls to select a color, credit to @joedf
viewtopic.php?t=65.
Code: Select all
; Mouse over to the file to preview the content without clicking. Support ahk,txt,ini,jpg,jpeg,png,bmp,tif format.
; You must enable "show file ext name" in explorer.
; 鼠标移动到文件上面,不用点击即可预览内容。支持 ahk,txt,ini,jpg,jpeg,png,bmp,tif 格式。
; 需要在 资源管理器-显示 中勾选 “文件扩展名” 选项。
;https://www.autohotkey.com/boards/viewtopic.php?t=90001
;================================================================
; Modified code to add a border to the image, created by Hellbent
; Total Commander support added by WetWare05
;https://www.autohotkey.com/boards/viewtopic.php?p=523384
;================================================================
#Requires AutoHotkey v1.1.33
SetBatchLines, -1
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
CoordMode, Mouse, Screen
maxStr:=200
XSize:= A_ScreenWidth
YSize:= A_ScreenHeight
;SetColor:= 0x99FFFF00
Global NoW, SetColor, MaxWidth, MaxHeight, Margin, XSize, YSize
NoW:=""
if !FileExist("NewConfig.ini")
{
IniWrite, 500, NewConfig.ini, Preview_TCM, MaxWidth
IniWrite, 500, NewConfig.ini, Preview_TCM, MaxHeight
IniWrite, 16, NewConfig.ini, Preview_TCM, Margin
IniWrite, 0x99FFFF00, NewConfig.ini, Preview_TCM, SetColor
;IniWrite, Window7, NewConfig.ini, Preview_TCM, NoW
}
If !MaxWidth
{
IniRead, MaxWidth, NewConfig.ini, Preview_TCM, MaxWidth
}
If !MaxHeight
{
IniRead, MaxHeight, NewConfig.ini, Preview_TCM, MaxHeight
}
If !Margin
{
IniRead, Margin, NewConfig.ini, Preview_TCM, Margin
}
If !SetColor
{
IniRead, SetColor, NewConfig.ini, Preview_TCM, SetColor
}
SetTimer, preview, 50
init:
; close system file info tip.
RegRead, ShowInfoTip, HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowInfoTip
RegWrite, REG_DWORD, HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowInfoTip, 0
pToken := Gdip_Startup()
OnExit, GdipExit
;PreviewWindow := CreatePreviewWindow( MaxWidth := 500 , MaxHeight := 500 )
PreviewWindow := CreatePreviewWindow( MaxWidth , MaxHeight )
return
CreatePreviewWindow( Width , Height ){
local Obj := {}
Gui, New, -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs +HwndhPreview
Obj.Hwnd := hPreview
Gui, Show, NA
Obj.Width := Width
Obj.Height := Height
Obj.hbm := CreateDIBSection( Obj.Width , Obj.Height )
Obj.hdc := CreateCompatibleDC()
Obj.obm := SelectObject( Obj.hdc , Obj.hbm )
Obj.G := Gdip_GraphicsFromHDC( Obj.hdc )
Gdip_SetInterpolationMode( Obj.G , 0)
return obj
}
preview:
Current := GetFileUnderMouse()
if (Displayed != Current.Path)
{
Displayed := Current.Path
Ext := Current.Ext
if Ext in ahk,txt,ini
{
UpdateLayeredWindow( PreviewWindow.Hwnd , PreviewWindow.hdc, , , , , 0) ;<<<--
File := FileOpen(Current.Path, "r")
btt(File.Read(maxStr),,,,"Style5")
File.Close()
}
else if Ext in jpg,jpeg,png,bmp,tif
{
btt() ;<<--No idea what this does
ShowPreview( Current.Path , PreviewWindow ) ;<<<<<----------
}
else
{
btt()
UpdateLayeredWindow( PreviewWindow.Hwnd , PreviewWindow.hdc, , , , , 0) ;<<<--
}
}
return
ShowPreview( Path , PreviewWindow ){
pBitmap := Gdip_CreateBitmapFromFile( path )
Bwidth := Gdip_GetImageWidth( pBitmap )
Bheight := Gdip_GetImageHeight( pBitmap )
;Margin := 16
MaxWidth := PreviewWindow.Width - 2 * Margin
MaxHeight := PreviewWindow.Height - 2 * Margin
if( BWidth > MaxWidth ){
Width := MaxWidth
Height := MaxWidth * ( BHeight / BWidth )
if( Height > MaxHeight ){
Height := MaxHeight
Width := MaxHeight * ( BWidth / BHeight )
}
}else if( BHeight > MaxHeight ){
Height := MaxHeight
Width := MaxHeight * ( BWidth / BHeight )
}else{
Width := BWidth
Height := BHeight
}
Gdip_GraphicsClear( PreviewWindow.G ) ;clear the graphics to start with a fresh canvas to draw on
Brush := Gdip_BrushCreateSolid( SetColor ) ; create a brush and give it a color (AARRGGBB) 4B7CFA "0x99000000" FFFF00
GDIP_FillRectangle( PreviewWindow.G , Brush , 0 , 0 , width + 2 * Margin , height + 2 * Margin ) ;use the brush to fill a rectangle on the graphics
;GDIP_FillRectangle( PreviewWindow.G , Brush , 0 , 0 , width + 5 * Margin , height + 5 * Margin ) ;use the brush to fill a rectangle on the graphics
Gdip_DeleteBrush( Brush ) ;delete the brush to free the memory ( alt is to have a "Memory Leak" )
Gdip_DrawImage( PreviewWindow.G , pBitmap , Margin , Margin , width , height ) ;Draw the resized image on the graphics
MouseGetPos, x, y ;get the current mouse position
UpdateLayeredWindow( PreviewWindow.Hwnd , PreviewWindow.hdc , x + 16 , y + 16 , PreviewWindow.Width , PreviewWindow.Height , Alpha := 230) ;draw the graphics onto the window and reposition it at an offset of the cursor.
Gdip_DisposeImage( pBitmap ) ;delete the bitmap to free memory.
}
GdipExit:
RegWrite, REG_DWORD, HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowInfoTip, %ShowInfoTip%
Gdip_DisposeImage(pBitmap)
Gdip_DeleteGraphics(G)
SelectObject(hdc, obm)
DeleteDC(hdc)
DeleteObject(hbm)
Gdip_Shutdown(pToken)
ExitApp
return
^p::
NotifyTrayClick_201:
Pause , Toggle
Return
; https://www.autohotkey.com/boards/viewtopic.php?t=51788
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=69925
GetFileUnderMouse()
{
static Windows:=ComObjCreate("Shell.Application").Windows
MouseGetPos, , , hwnd, CtrlClass
WinGetClass, WinClass, ahk_id %hwnd%
try if WinActive("ahk_exe TOTALCMD.exe") or WinActive("ahk_exe TOTALCMD64.exe")
{
If (WinActive("ahk_exe TOTALCMD.exe") || State=2)
{
Gosub, Find_Control
}
If (WinActive("ahk_exe TOTALCMD64.exe") || State=1)
{
Gosub, Find_Control64
}
If !NoW
{
If WinActive("ahk_exe TOTALCMD.exe")
{
Gosub, Find_Control
}
If WinActive("ahk_exe TOTALCMD64.exe")
{
Gosub, Find_Control64
}
}
;GetKeyState, state, Ctrl
;if (state = "D")
;{
ret:= UIA_Interface()
ControlGetText sPath, % NoW
stringRight, RLast, sPath, 1
sPath:=StrReplace(sPath,">","")
Element := ret.ElementFromPoint()
itemName := Element.GetCurrentPropertyValue(30005)
if (itemName == "")
itemName := "No 'Name'"
RegExMatch(itemName, "^[^\t]*", Reg)
FullPath:= sPath Reg
SplitPath, FullPath, , , OutExtension, OutNameNoExt
ret := {}
ret.Path := sPath "\" Reg
ret.Ext := OutExtension
ret.Name := OutNameNoExt
return, ret
}
;}
Else
try if (WinClass = "CabinetWClass" && CtrlClass = "DirectUIHWND2")
{
oAcc := Acc_ObjectFromPoint()
Name := Acc_Parent(oAcc).accValue(0)
NonNull(Name, oAcc.accValue(0))
if (Name="")
return
for window in Windows
if (window.hwnd = hwnd)
{
FolderPath := RegExReplace(window.Document.Folder.Self.Path, "(\w+?\:)\\$", "$1") ; “d:\” 转换为 “d:” — “d:\” convertido a “d:”
SplitPath, Name, , , OutExtension, OutNameNoExt
ret := {}
ret.Path := FolderPath "\" Name
ret.Ext := OutExtension
ret.Name := OutNameNoExt
return, ret
}
}
else if (WinClass = "Progman" || WinClass = "WorkerW")
{
oAcc := Acc_ObjectFromPoint(ChildID)
Name := ChildID ? oAcc.accName(ChildID) : ""
if (Name="")
return
SplitPath, Name, , , OutExtension, OutNameNoExt
ret := {}
ret.Path := A_Desktop "\" Name
ret.Ext := OutExtension
ret.Name := OutNameNoExt
return, ret
}
}
Acc_Init() {
Static h
If Not h
h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
}
Acc_ObjectFromPoint(ByRef _idChild_ = "", x = "", y = "") {
Acc_Init()
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
Return ComObjEnwrap(9,pacc,1), _idChild_:=NumGet(varChild,8,"UInt")
}
Acc_Parent(Acc) {
try parent:=Acc.accParent
return parent?Acc_Query(parent):
}
Acc_Query(Acc) { ; thanks Lexikos - www.autohotkey.com/forum/viewtopic.php?t=81731&p=509530#509530
try return ComObj(9, ComObjQuery(Acc,"{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
}
NotifyTrayClick(P*) { ; v0.41 by SKAN on D39E/D39N @ tiny.cc/notifytrayclick
Static Msg, Fun:="NotifyTrayClick", NM:=OnMessage(0x404,Func(Fun),-1), Chk,T:=-250,Clk:=1
If ( (NM := Format(Fun . "_{:03X}", Msg := P[2])) && P.Count()<4 )
Return ( T := Max(-5000, 0-(P[1] ? Abs(P[1]) : 250)) )
Critical
If ( ( Msg<0x201 || Msg>0x209 ) || ( IsFunc(NM) || Islabel(NM) )=0 )
Return
Chk := (Fun . "_" . (Msg<=0x203 ? "203" : Msg<=0x206 ? "206" : Msg<=0x209 ? "209" : ""))
SetTimer, %NM%, % (Msg==0x203 || Msg==0x206 || Msg==0x209)
? (-1, Clk:=2) : ( Clk=2 ? ("Off", Clk:=1) : ( IsFunc(Chk) || IsLabel(Chk) ? T : -1) )
Return True
}
^!s::
Xpos:= Floor((A_ScreenWidth/2)-450)
Ypos:= Floor((A_ScreenHeight/2)-200)
Gui, Size: Add, Button, x225 y16 w65 h20 GNewSize, OK
Gui, Size: Add, Button, x225 y46 w65 h20 gCancel, Cancel
Gui, Size: Font, S9 Bold, Verdana
Gui, Size: Add, Text, x10 y16 w90 h20, Max. Width:
Gui, Size: Add, edit, x100 y16 w100 h20 vFmaxW
Gui, Size: Add, Text, x10 y46 w90 h20, Max. High:
Gui, Size: Add, edit, x100 y46 w100 h20 vFmaxH
Gui, Size: Show, x%xpos% y%ypos% h80 w300, Size_P
Return
Cancel:
Gui, Size: Destroy
Return
NewSize:
Gui, Size: Submit
If !FmaxW
{
MaxWidth:=500
}
Else
{
MaxWidth:=FmaxW
IniWrite, %MaxWidth%, NewConfig.ini, Preview_TCM, MaxWidth
}
If !FmaxH
{
MaxHeight:=500
}
Else
{
MaxHeight:=FmaxH
IniWrite, %MaxHeight%, NewConfig.ini, Preview_TCM, MaxHeight
}
Gui, Size: Destroy
Gosub, Init
Return
;^F8::
Find_Control:
Now:=""
Loop, 30
{
NewWin:= "TMyPanel" A_Index
ControlGetText PPath, % NewWin
;Ello:= % NewWin . " " . PPath
StringRight, RLast, PPath, 1
If RLast=>
{
NoW:= NewWin
State=1
Break
}
}
Return
;^F9::
Find_Control64:
Loop, 30
{
NewWin:= "Window" A_Index
ControlGetText PPath, % NewWin
;Ello:= % NewWin . " " . PPath
StringRight, RLast, PPath, 1
If RLast=>
{
NoW:= NewWin
State=2
Break
}
}
Return
;
; AutoHotkey Version: 1.1.12.00
; Language: English
; Dev Platform: Windows 7 Home Premium x64
; Author: Joe DF | http://joedf.co.nr | [email protected]
; Date: August 20th, 2013
;
; Script Function:
; Color Dialog Example script.
;
;<<<<<<<< HEADER END >>>>>>>>>
;Set starting default value to RGB(44,197,89), Just a random colour
RGBval:=RGB(Rval:=44,Gval:=197,Bval:=89)
^!F8::
;Create Color Dialog GUI
Gui, Add, Text, x0 y10 w40 h20 +Right, Red
Gui, Add, Text, x0 y30 w40 h20 +Right, Green
Gui, Add, Text, x0 y50 w40 h20 +Right, Blue
Gui, Add, Slider, x40 y10 w190 h20 AltSubmit +NoTicks +Range0-255 vsR gSliderSub, %Rval%
Gui, Add, Slider, x40 y30 w190 h20 AltSubmit +NoTicks +Range0-255 vsG gSliderSub, %Gval%
Gui, Add, Slider, x40 y50 w190 h20 AltSubmit +NoTicks +Range0-255 vsB gSliderSub, %Bval%
Gui, Add, Edit, x230 y10 w45 h20 gEditSub veR +Limit3 +Number, %Rval%
Gui, Add, UpDown, Range0-255 vuR gUpDownSub, %Rval%
Gui, Add, Edit, x230 y30 w45 h20 gEditSub veG +Limit3 +Number, %Gval%
Gui, Add, UpDown, Range0-255 vuG gUpDownSub, %Gval%
Gui, Add, Edit, x230 y50 w45 h20 gEditSub veB +Limit3 +Number, %Bval%
Gui, Add, UpDown, Range0-255 vuB gUpDownSub, %Bval%
Gui, Add, Progress, x285 y10 w60 h60 +Border Background%RGBval% vpC
Gui, Add, Text, x285 y10 w60 h60 +Border vtP cWhite +BackgroundTrans, Preview
Gui, Add, Button, x120 y80 w110 h20 vbS gButtonSub, Select Color ;Copy to Clipboard
Gui, Show, w351 h105, Simple Color Dialog
return
EditSub:
;Get Values
GuiControlGet,Rval,,eR
GuiControlGet,Gval,,eG
GuiControlGet,Bval,,eB
;Set preview
gosub set
;Make Everything else aware
GuiControl,,uR,%Rval%
GuiControl,,uG,%Gval%
GuiControl,,uB,%Bval%
GuiControl,,sR,%Rval%
GuiControl,,sG,%Gval%
GuiControl,,sB,%Bval%
return
UpDownSub:
;Get Values
GuiControlGet,Rval,,uR
GuiControlGet,Gval,,uG
GuiControlGet,Bval,,uB
;Set preview
gosub set
;Make Everything else aware
GuiControl,,eR,%Rval%
GuiControl,,eG,%Gval%
GuiControl,,eB,%Bval%
GuiControl,,sR,%Rval%
GuiControl,,sG,%Gval%
GuiControl,,sB,%Bval%
return
SliderSub:
;Get Values
GuiControlGet,Rval,,sR
GuiControlGet,Gval,,sG
GuiControlGet,Bval,,sB
;Set preview
gosub set
;Make Everything else aware
GuiControl,,eR,%Rval%
GuiControl,,eG,%Gval%
GuiControl,,eB,%Bval%
GuiControl,,uR,%Rval%
GuiControl,,uG,%Gval%
GuiControl,,uB,%Bval%
return
set:
;Convert values to Hex
RGBval:=RGB(Rval,Gval,Bval)
;Display Tooltip
ToolTip Red: %Rval%`nGreen: %Gval%`nBlue: %Bval%`nHex: %RGBval%
;Make tooltip disappear after 375 ms (3/8th of a second)
SetTimer, RemoveToolTip, 375
;Apply colour to preview
GuiControl,+Background%RGBval%,pC
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off ;Turn timer off
ToolTip ;Turn off tooltip
return
ButtonSub:
;Remove '0x' prefix to hex color code, saving it directly to the clipboard
;StringReplace,Clipboard,RGBval,0x99
StringReplace,SetColor,RGBval,0x
SetColor:="0x99" SetColor
;MsgBox, % SetColor . " " . RGBval
;Display Last selected values... (these values can later be used), and Notify the user
;MsgBox,64,Simple Color Dialog,RGB: (%Rval%, %Gval%, %Bval%)`nHex: %RGBval%`nCopied to Clipboard!
;Skip Directly GuiClose
Gui, Destroy
Return
;GuiClose:
;Exit This Example script
; ExitApp
;Function to convert Decimal RGB to Hexadecimal RBG, Note: '0' (zero) padding is unnecessary
RGB(r, g, b) {
;Shift Numbers
var:=(r << 16) + (g << 8) + b
;Save current A_FormatInteger
OldFormat := A_FormatInteger
;Set Hex A_FormatInteger mode
SetFormat, Integer, Hex
;Force decimal number to Hex number
var += 0
;set original A_FormatInteger mode
SetFormat, Integer, %OldFormat%
return var
}
#Include <NonNull>
#Include <Gdip_All>