Hi.
What the original script does: fit the image to a height and width limit size, to create a preview of the image.
I lost one of the variations I worked on last night (the one that cropped the image). And trying to recreate it today (with the script below adding "original script" with the mixed "add a white border" part) now outputs the full image, but the border with the size of the original image, not respecting that The width and height limit for the preview should be adapted.
I "read" and understand part of the Gdpi code (by logic, not by knowledge), but I don't know what the variable "G" does (The variable in which the process performed on the graph in Gdpi is stored in memory?) It can there be two G variables (G and G1) or is that wrong?
Complete script. To see previous images, which work both in Total Commander x32 and x64, as well as on the desktop or Explorer (adapted to a single monitor and do not go off screen, pending changes 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
#Requires AutoHotkey v1.1.33
SetBatchLines, -1
CoordMode, Mouse, Screen
maxStr:=200 ;, maxW:=1500, maxH:=1500
;maxStr:=200, maxW:=500, maxH:=500
XSize:= A_ScreenWidth
YSize:= A_ScreenHeight
Global NoW
NoW:=""
if !FileExist("Config.ini")
{
IniWrite, 500, Config.ini, Preview_TCM, maxW
IniWrite, 500, Config.ini, Preview_TCM, maxH
;IniWrite, Window7, Config.ini, Preview_TCM, NoW
}
If !maxW
{
IniRead, maxW, Config.ini, Preview_TCM, maxW
}
If !maxH
{
IniRead, maxH, Config.ini, Preview_TCM, maxH
}
gosub, init
SetTimer, preview, 50
return
preview:
Current := GetFileUnderMouse()
if (Displayed != Current.Path)
{
Displayed := Current.Path
Ext := Current.Ext
if Ext in ahk,txt,ini
{
UpdateLayeredWindow(hPreview, hdc, , , , , 0)
File := FileOpen(Current.Path, "r")
btt(File.Read(maxStr),,,,"Style5")
File.Close()
}
else if Ext in jpg,jpeg,png,bmp,tif
{
btt()
gosub, displaypic
}
else
{
btt()
UpdateLayeredWindow(hPreview, hdc, , , , , 0)
}
}
return
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
Gui, -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs +HwndhPreview
Gui, Show, NA
pToken := Gdip_Startup()
OnExit, GdipExit
hbm := CreateDIBSection(maxW, maxH)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetInterpolationMode(G, 0)
return
displaypic:
pBitmap := Gdip_CreateBitmapFromFile(Current.Path)
Width := Gdip_GetImageWidth(pBitmap)
Height := Gdip_GetImageHeight(pBitmap)
ratio := Round(Width/Height)
if (ratio>=1)
{
dw:=Round(maxW)
dh:=Round(dw/ratio)
}
else
{
dh:=Round(MaxH)
dw:=Round(ratio*dh)
}
w:=dw+10
h:=dh+10
pBitmap1 := Gdip_CreateBitmap(w, h)
G1 := Gdip_GraphicsFromImage(pBitmap1)
pBrush := Gdip_BrushCreateSolid(0xffffffff)
Gdip_FillRectangle(G, pBrush, 0, 0, w, h)
Gdip_DeleteBrush(pBrush)
Gdip_DrawImage(G, pBitmap, 5, 5, dw, dh, 0, 0, dw, dh)
;Gdip_DrawImage(G, pBitmap, 0, 0, dw, dh)
Gdip_DisposeImage(pBitmap)
MouseGetPos, OutputVarX, OutputVarY
NewPos:=0
PosY:= OutputVarY-dh
If PosY < 0
{
;StringTrimLeft, NPosY, PosY, 1
;OutPutVarY:= OutPutVarY+NPosY
NewPos:=1
}
PosX:= OutputVarx+dw
If PosX > %XSize%
{
NPosX:= PosX-XSize
OutPutVarX:= OutPutVarX-NPosX
;NewPos:=1
}
If NewPos=0
{
UpdateLayeredWindow(hPreview, hdc, OutputVarX+16, (OutputVarY-dh)-16, dw, dh)
;UpdateLayeredWindow(hPreview, hdc, OutputVarX+16, (OutputVarY-dh)-6, dw, dh)
}
If NewPos=1
{
UpdateLayeredWindow(hPreview, hdc, OutputVarX+16, OutputVarY+16, dw, dh)
}
return
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::
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:”
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)
}
^!s::
Xpos:= Floor((A_ScreenWidth/2)-450)
Ypos:= Floor((A_ScreenHeight/2)-200)
;Gui, Search:+HwndGuiID
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
{
MaxW:=500
}
Else MaxW:=FmaxW
IniWrite, %MaxW%, Config.ini, Preview_TCM, maxW
MaxW:=FmaxW
If !FmaxH
{
MaxH:=500
}
Else MaxH:=FmaxH
IniWrite, %MaxH%, Config.ini, Preview_TCM, maxH
Gui, Size: Destroy
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
#Include <NonNull>
#Include <Gdip_All>