Hi.
Added in the configuration Gui the possibility to change the level of transparency (0=transparent 256=opaque) and the width of the border. Now the GUI of the color selection appears with the current color (I don't know if this utility works well, since if you slide all the controls to the left, the result is not a black border, but a non-existent one, for black you have to bring the controls—together—a third of the way down the slider).
Changed so that image previews don't go off screen (on single screen computers; pending review for multiple monitors).
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
Global NoW, SetColor, StateC, MaxWidth, MaxHeight, Margin, XSize, YSize, StateC, Mode, Transp, NameControl, ChangeN
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, 230, NewConfig.ini, Preview_TCM, Transp
IniWrite, Window7, NewConfig.ini, Preview_TCM, NameControl
}
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
}
If !Transp
{
IniRead, Transp, NewConfig.ini, Preview_TCM, Transp
}
If !NameControl
{
IniRead, NameControl, NewConfig.ini, Preview_TCM, NameControl
}
TempMaxH:= MaxHeight
TempMaxW:= MaxWidth
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 , 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()
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 )
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_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
Over=0
NewPos=""
xOffSet:=16
yOffSet:=16
If Margin => 15
{
yOffSet:=35
}
If Margin > 30
{
yOffSet:=70
}
Py:= y
TempY:= y - Height
If TempY < 0
{
Over:=1
NewPos:=1
}
Marg:=margin*4 ;5
xt:= x+Width
If xt > %XSize%
{
NPosX:= xt-XSize
x:= (x-NPosX)-marg
If Over=0
{
y:= y-50
}
}
If NewPos=1
{
UpdateLayeredWindow( PreviewWindow.Hwnd , PreviewWindow.hdc , x + xOffSet , y + yOffSet , PreviewWindow.Width , PreviewWindow.Height , Alpha := Transp ) ;draw the graphics onto the window and reposition it at an offset of the cursor.
}
Else
UpdateLayeredWindow( PreviewWindow.Hwnd , PreviewWindow.hdc , x + xOffSet , y-Height - yOffSet , PreviewWindow.Width , PreviewWindow.Height , Alpha := Transp )
;UpdateLayeredWindow( PreviewWindow.Hwnd , PreviewWindow.hdc , x + 16 , y + 16 , PreviewWindow.Width , PreviewWindow.Height , Alpha := Transp ) ;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
}
;
; AutoHotkey Version: 1.1.12.00
; Language: English
; Dev Platform: Windows 7 Home Premium x64
; Author: Joe DF | http://joedf.co.nr | joedf@users.sourceforge.net
; 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::
stringRight, RSix, SetColor, 6
TColor:="0x" RSix
R:= (TColor&0xFF0000)>>16, G:= (TColor&0x00FF00)>>8, B:= TColor&0xFF
RGBval:=RGB(Rval:= R, Gval:= G, Bval:= B)
;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
^!s::
Xpos:= Floor((A_ScreenWidth/2)-450)
Ypos:= Floor((A_ScreenHeight/2)-200)
Gui, Size: +HwndGuiID +AlwaysOnTop
Gui, Size: Add, Button, x300 y16 w65 h20 GNewSize, OK
Gui, Size: Add, Button, x300 y46 w65 h20 gCancel, Cancel
Gui, Size: Font, S9 Bold, Verdana
Gui, Size: Add, Text, x5 y16 w90 h20, Max. Width:
Gui, Size: Add, edit, x95 y16 w60 h20 vFmaxW, %TempMaxW%
Gui, Size: Add, Text, x5 y46 w90 h20, Max. High:
Gui, Size: Add, edit, x95 y46 w60 h20 vFmaxH, %TempMaxH%
Gui, Size: Add, Text, x170 y16 w70 h20, Transp.:
Gui, Size: Add, edit, x230 y16 w60 h20 vFtrans , %Transp%
Gui, Size: Add, Text, x170 y46 w70 h20, Margin :
Gui, Size: Add, edit, x230 y46 w60 h20 vFmarg , %margin%
Gui, Size: Show, x%xpos% y%ypos% h80 w370, Image Preview Configuration
Return
#If WinActive("ahk_id " GuiID)
Enter::
NumPadEnter::
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
}
If !Ftrans or Ftrans>256
{
Transp:=Transp
}
Else
{
Transp:=Ftrans
IniWrite, %Ftrans%, NewConfig.ini, Preview_TCM, Transp
}
If !Fmarg
{
Margin:=16
}
Else
{
Margin:=Fmarg
IniWrite, %Fmarg%, NewConfig.ini, Preview_TCM, Margin
}
Gui, Size: Destroy
Gosub, Init
Return
Cancel:
Gui, Size: Destroy
Return
;^F8::
Find_Control:
Now:=""
Loop, 30
{
NewWin:= "TMyPanel" A_Index
ControlGetText PPath, % NewWin
StringRight, RLast, PPath, 1
If RLast=>
{
NoW:= NewWin
State=1
Break
}
}
Return
;^F9::
Find_Control64:
Now:=""
Loop, 30
{
NewWin:= "Window" A_Index
ControlGetText PPath, % NewWin
StringRight, RLast, PPath, 1
If RLast=>
{
NoW:= NewWin
State=2
Break
}
}
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>