Created
February 18, 2014 19:58
-
-
Save budRich/9078766 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Filleluring | |
Filemanager | |
by: budRich | |
*/ | |
#Persistent | |
#SingleInstance, Force | |
OnExit, Avslut | |
global ini := [] | |
global pToken := Gdip_Startup() | |
ReadIni() | |
MenuCreate() | |
return | |
+#E::Gui("S") | |
^F12::Reload | |
MenuCreate() | |
{ | |
global | |
Menu, FileMenu, Add, &Open`tCtrl+O, MenuFileOpen ; See remarks below about Ctrl+O. | |
Menu, FileMenu, Add, E&xit, MenuHandler | |
Menu, HelpMenu, Add, &About, MenuHandler | |
Menu, MyMenuBar, Add, &File, :FileMenu ; Attach the two sub-menus that were created above. | |
Menu, MyMenuBar, Add, &Help, :HelpMenu | |
} | |
ReadIni() | |
{ | |
if !FileExist("settings.ini") | |
IniDefault() | |
else | |
Loop, Read, settings.ini | |
{ | |
StringSplit,i,A_LoopReadLine, =,%A_Space%%A_Tab% | |
ini[i1] := i2 | |
} | |
} | |
IniDefault() | |
{ | |
ini.guiW := 800 | |
ini.guiH := 640 | |
ini.guiMrgn := 5 | |
ini.lstItemH := 20 | |
ini.lstBgColor := "2B2B2B" | |
ini.lstFontSize := 14 | |
ini.lstFontColor := "EEEEEE" | |
ini.lstFont := "Segoe UI" | |
ini.lstW := 750 | |
ini.mwX := ini.guiMrgn | |
ini.mwY := 80 | |
ini.mwH := 400 | |
ini.mwW := 800 | |
} | |
Skumming(o) | |
{ | |
hFont := Fnt_CreateFont(ini.lstFont,"s" ini.lstFontSize) | |
lstItemSize := Fnt_GetFontHeight(hFont) | |
; Create a 400x400 pixel gdi+ bitmap | |
pBitmap := Gdip_CreateBitmap(ini.lstW, lstItemSize) | |
; Get a pointer to the graphics of the bitmap, for use with drawing functions | |
G := Gdip_GraphicsFromImage(pBitmap) | |
; Set the smoothing mode to antialias = 4 to make shapes appear smoother (only used for vector drawing and filling) | |
Gdip_SetSmoothingMode(G, 4) | |
pBrush := Gdip_BrushCreateSolid(0xffff00ff) | |
;pBrush := Gdip_BrushCreateSolid(0xff + ini.BgColor) | |
; Fill the graphics of the bitmap with a rectangle using the brush created | |
; Filling from coordinates (250,80) a rectangle of 300x200 | |
Gdip_FillRectangle(G, pBrush, 0, 0, ini.lstW, lstItemSize) | |
; Delete the brush as it is no longer needed and wastes memory | |
Gdip_DeleteBrush(pBrush) | |
; We can specify the font to use. Here we use Arial as most systems should have this installed | |
Font := ini.LstFont | |
; Next we can check that the user actually has the font that we wish them to use | |
; If they do not then we can do something about it. I choose to give a wraning and exit! | |
;Gdip_FontFamilyCreate(Font) | |
; There are a lot of things to cover with the function Gdip_TextToGraphics | |
; The 1st parameter is the graphics we wish to use (our canvas) | |
; The 2nd parameter is the text we wish to write. It can include new lines `n | |
; The 3rd parameter, the options are where all the action takes place... | |
; You can write literal x and y coordinates such as x20 y50 which would place the text at that position in pixels | |
; or you can include the last 2 parameters (Width and Height of the Graphics we will use) and then you can use x10p | |
; which will place the text at 10% of the width and y30p which is 30% of the height | |
; The same percentage marker may be used for width and height also, so w80p makes the bounding box of the rectangle the text | |
; will be written to 80% of the width of the graphics. If either is missed (as I have missed height) then the height of the bounding | |
; box will be made to be the height of the graphics, so 100% | |
; Any of the following words may be used also: Regular,Bold,Italic,BoldItalic,Underline,Strikeout to perform their associated action | |
; To justify the text any of the following may be used: Near,Left,Centre,Center,Far,Right with different spelling of words for convenience | |
; The rendering hint (the quality of the antialiasing of the text) can be specified with r, whose values may be: | |
; SystemDefault = 0 | |
; SingleBitPerPixelGridFit = 1 | |
; SingleBitPerPixel = 2 | |
; AntiAliasGridFit = 3 | |
; AntiAlias = 4 | |
; The size can simply be specified with s | |
; The colour and opacity can be specified for the text also by specifying the ARGB as demonstrated with other functions such as the brush | |
; So cffff0000 would make a fully opaque red brush, so it is: cARGB (the literal letter c, follwed by the ARGB) | |
; The 4th parameter is the name of the font you wish to use | |
; As mentioned previously, you don not need to specify the last 2 parameters, the width and height, unless | |
; you are planning on using the p option with the x,y,w,h to use the percentage | |
Options := "x2 y2 Bold cff" ini.lstFontColor " s" ini.lstFontSize | |
Gdip_TextToGraphics(G, o.name, Options, Font, 300, lstItemSize) | |
h := Gdip_CreateHBITMAPFromBitmap(pBitmap) | |
; The bitmap can be deleted | |
Gdip_DisposeImage(pBitmap) | |
; The graphics may now be deleted | |
Gdip_DeleteGraphics(G) | |
return, h | |
} | |
Gui(m="T") | |
{ global | |
WS_CLIPCHILDREN := 0x2000000 | |
Gui, -Resize +%WS_CLIPCHILDREN% | |
Gui, Margin,% ini.guiMrgn | |
Gui, Menu, MyMenuBar | |
Gui, Add, Edit,% "w" ini.guiW " hwndhEdAdr gEdAdr", %A_ScriptDir% | |
Gui, Add, Edit,% "xp y+" ini.guiMrgn " wp hwndhEdFil gEdFil", | |
Gui, Show,% "x100 y100 h" ini.guiH, FilleLuring | |
WinWait, FilleLuring | |
idFille := WinExist() | |
MainWindow("list",A_ScriptDir) | |
} | |
MainWindow(m="list",f="") | |
{ | |
if (m="list") | |
MW_LIST(f) | |
} | |
OFromFolder(fld) | |
{ | |
o := [] | |
Loop, %fld%\*.* | |
{ | |
o2 := {name: A_LoopFileName | |
, ext: A_LoopFileExt | |
, pth: A_LoopFileFullPath | |
, dir: A_LoopFileDir | |
, timeA: A_LoopFileTimeAccessed | |
, timeM: A_LoopFileTimeModified | |
, timeC: A_LoopFileTimeCreated | |
, sizeKB: A_LoopFileSizeKB | |
, size: A_LoopFileSize | |
, sizeMB: A_LoopFileSizeMB} | |
o.Insert(o2) | |
} | |
Return, o | |
} | |
MW_LIST(fld,fil="") | |
{ | |
global | |
WS_POPUP := 0x80000000 | |
WS_CAPTION := 0xC00000 | |
WS_THICKFRAME := 0x40000 | |
WS_EX_CLIENTEDGE := 0x200 | |
; Styles we want to add to the console window: | |
WS_CHILD := 0x40000000 | |
; Flags for SetWindowPos: | |
SWP_NOACTIVATE := 0x10 | |
SWP_SHOWWINDOW := 0x40 | |
SWP_NOSENDCHANGING := 0x400 | |
hw := A_DetectHiddenWindows | |
hFont := Fnt_CreateFont(ini.lstFont,"s" ini.lstFontSize) | |
lstItemSize := Fnt_GetFontHeight(hFont) | |
oLst := OFromFolder(fld) | |
Gui, MW:Default | |
Gui, Margin, 0 | |
Gui, Destroy | |
Gui, +0x200000 ; +resize ; WS_VSCROLL | |
Gui, Color,% ini.lstBgColor | |
Gui, Add, Text,% "w" ini.lstW " h" lstItemSize " x0 y0 0x20E vbw hwndbwh gPicLic", | |
For k in oLst | |
{ | |
vPic := "pc" k | |
hPic := "px" k | |
Gui, Add, Text,% "wp hp xp y+0 0x20E v" vPic " hwnd" hPic " gPicLic", | |
} | |
Gui, Show,% "hide", MWF | |
DetectHiddenWindows, On | |
WinWait, MWF | |
idMWF := WinExist() | |
WinSet, Style, % -(WS_POPUP|WS_CAPTION|WS_THICKFRAME) | |
WinSet, Style, +%WS_CHILD% | |
WinSet, ExStyle, -%WS_EX_CLIENTEDGE% | |
DllCall("SetParent", "uint", idMWF, "uint", idFille) | |
DllCall("SetWindowPos", "uint", idMWF, "uint", 0 | |
, "int", ini.mwX, "int", ini.mwY, "int", ini.mwW, "int", ini.mwH | |
, "uint", SWP_NOACTIVATE|SWP_SHOWWINDOW|SWP_NOSENDCHANGING) | |
UpdateScrollBars("MW", ini.mwW, ini.mwH) | |
DetectHiddenWindows, %hw% | |
For k in oLst | |
{ | |
h := Skumming(oLst[k]) | |
SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), h,,% "ahk_id " px%k% | |
} | |
} | |
PicLic: | |
EdAdr: | |
EdFil: | |
MenuHandler: | |
MenuFileOpen: | |
return | |
gdiBitmap( img,byref WxH ) { ; Sean www.autohotkey.com/forum/viewtopic.php?p=147029#147029 | |
FileGetSize, nSize, %img% | |
IfEqual,nsize,0, Return,0 | |
if (A_IsUnicode) | |
FileRead, Buffer, *c *p1200 %img% | |
else | |
FileRead, Buffer, %img% | |
hData := DllCall("GlobalAlloc", UInt,2, UInt, nSize ) | |
pData := DllCall("GlobalLock", UInt,hData ) | |
DllCall( "RtlMoveMemory", UInt,pData, UInt,&Buffer, UInt,nSize ) | |
DllCall( "GlobalUnlock", UInt,hData ) | |
DllCall( "ole32\CreateStreamOnHGlobal", UInt,hData, Int,True, UIntP,pStream ) | |
DllCall( "gdiplus\GdipCreateBitmapFromStream", UInt,pStream, UIntP,pBitmap ) | |
DllCall( "gdiplus\GdipCreateHBITMAPFromBitmap", UInt,pBitmap, UIntP,hBitmap, UInt,8 ) | |
DllCall( "gdiplus\GdipGetImageWidth" , "Uint", pBitmap, "UintP", nW) | |
DllCall( "gdiplus\GdipGetImageHeight", "Uint", pBitmap, "UintP", nH), WxH := nW "x" nH | |
DllCall( "gdiplus\GdipDisposeImage", UInt,pBitmap ) | |
Return hBitmap | |
} | |
BestFitRect(d1,d2,s="x") { ; Oberon www.autohotkey.com/forum/viewtopic.php?p=189202#189202 | |
Loop, 2 | |
StringSplit, d%A_Index%x, d%A_Index%, %s% | |
f := d1x1 - d2x1 > d1x2 - d2x2 ? d2x1 / d1x1 : d2x2 / d1x2 | |
Return, Floor(d1x1 * f) . s . Floor(d1x2 * f) | |
} | |
SetProcessWorkingSetSize(PID=0) { ; heresy www.autohotkey.com/forum/viewtopic.php?t=32876 | |
h := DllCall( "OpenProcess", UInt,0x001F0FFF, Int,0, Int,PID ) | |
DllCall( "SetProcessWorkingSetSize", UInt,h, Int,-1, Int,-1 ) | |
DllCall( "CloseHandle", UInt,h ) | |
} | |
UpdateScrollBars(GuiNum, GuiWidth, GuiHeight) ; Lexikos www.autohotkey.com/board/topic/26033-scrollable-gui-proof-of-concept/#entry168174 | |
{ | |
static SIF_RANGE=0x1, SIF_PAGE=0x2, SIF_DISABLENOSCROLL=0x8, SB_HORZ=0, SB_VERT=1 | |
Gui, %GuiNum%:Default | |
Gui, +LastFound | |
; Calculate scrolling area. | |
Left := Top := 9999 | |
Right := Bottom := 0 | |
WinGet, ControlList, ControlList | |
Loop, Parse, ControlList, `n | |
{ | |
GuiControlGet, c, Pos, %A_LoopField% | |
if (cX < Left) | |
Left := cX | |
if (cY < Top) | |
Top := cY | |
if (cX + cW > Right) | |
Right := cX + cW | |
if (cY + cH > Bottom) | |
Bottom := cY + cH | |
} | |
Left -= 8 | |
Top -= 8 | |
Right += 8 | |
Bottom += 8 | |
ScrollWidth := Right-Left | |
ScrollHeight := Bottom-Top | |
; Initialize SCROLLINFO. | |
VarSetCapacity(si, 28, 0) | |
NumPut(28, si) ; cbSize | |
NumPut(SIF_RANGE | SIF_PAGE, si, 4) ; fMask | |
; Update horizontal scroll bar. | |
NumPut(ScrollWidth, si, 12) ; nMax | |
NumPut(GuiWidth, si, 16) ; nPage | |
DllCall("SetScrollInfo", "uint", WinExist(), "uint", SB_HORZ, "uint", &si, "int", 1) | |
; Update vertical scroll bar. | |
; NumPut(SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL, si, 4) ; fMask | |
NumPut(ScrollHeight, si, 12) ; nMax | |
NumPut(GuiHeight, si, 16) ; nPage | |
DllCall("SetScrollInfo", "uint", WinExist(), "uint", SB_VERT, "uint", &si, "int", 1) | |
if (Left < 0 && Right < GuiWidth) | |
x := Abs(Left) > GuiWidth-Right ? GuiWidth-Right : Abs(Left) | |
if (Top < 0 && Bottom < GuiHeight) | |
y := Abs(Top) > GuiHeight-Bottom ? GuiHeight-Bottom : Abs(Top) | |
if (x || y) | |
DllCall("ScrollWindow", "uint", WinExist(), "int", x, "int", y, "uint", 0, "uint", 0) | |
} | |
OnScroll(wParam, lParam, msg, hwnd) | |
{ | |
static SIF_ALL=0x17, SCROLL_STEP=75 | |
bar := msg=0x115 ; SB_HORZ=0, SB_VERT=1 | |
VarSetCapacity(si, 28, 0) | |
NumPut(28, si) ; cbSize | |
NumPut(SIF_ALL, si, 4) ; fMask | |
if !DllCall("GetScrollInfo", "uint", hwnd, "int", bar, "uint", &si) | |
return | |
VarSetCapacity(rect, 16) | |
DllCall("GetClientRect", "uint", hwnd, "uint", &rect) | |
new_pos := NumGet(si, 20, "int") ; nPos | |
action := wParam & 0xFFFF | |
if action = 0 ; SB_LINEUP | |
new_pos -= SCROLL_STEP | |
else if action = 1 ; SB_LINEDOWN | |
new_pos += SCROLL_STEP | |
else if action = 2 ; SB_PAGEUP | |
new_pos -= NumGet(rect, 12, "int") - SCROLL_STEP | |
else if action = 3 ; SB_PAGEDOWN | |
new_pos += NumGet(rect, 12, "int") - SCROLL_STEP | |
else if (action = 5 || action = 4) ; SB_THUMBTRACK || SB_THUMBPOSITION | |
new_pos := wParam>>16 | |
else if action = 6 ; SB_TOP | |
new_pos := NumGet(si, 8, "int") ; nMin | |
else if action = 7 ; SB_BOTTOM | |
new_pos := NumGet(si, 12, "int") ; nMax | |
else | |
return | |
min := NumGet(si, 8, "int") ; nMin | |
max := NumGet(si, 12, "int") - NumGet(si, 16, "int") ; nMax-nPage | |
new_pos := new_pos > max ? max : new_pos | |
new_pos := new_pos < min ? min : new_pos | |
old_pos := NumGet(si, 20, "int") ; nPos | |
x := y := 0 | |
if bar = 0 ; SB_HORZ | |
x := old_pos-new_pos | |
else | |
y := old_pos-new_pos | |
; Scroll contents of window and invalidate uncovered area. | |
DllCall("ScrollWindow", "uint", hwnd, "int", x, "int", y, "uint", 0, "uint", 0) | |
; Update scroll bar. | |
NumPut(new_pos, si, 20, "int") ; nPos | |
DllCall("SetScrollInfo", "uint", hwnd, "int", bar, "uint", &si, "int", 1) | |
} | |
; http://ahkscript.org/boards/viewtopic.php?t=1979&p=11360#p11367 | |
GetFontProperties(HFONT) { | |
; LOGFONT -> http://msdn.microsoft.com/en-us/library/dd145037%28v=vs.85%29.aspx | |
VarSetCapacity(LF, (4 * 5) + 8 + 64) ; LOGFONT Unicode | |
Size := DllCall("Gdi32.dll\GetObject", "Ptr", HFONT, "Int", Size, "Ptr", 0) | |
DllCall("Gdi32.dll\GetObject", "Ptr", HFONT, "Int", Size, "Ptr", &LF) | |
Font := {} | |
Font.Height := Round(Abs(NumGet(LF, 0, "Int")) * 72 / A_ScreenDPI, 1) | |
Font.Width := Round(Abs(NumGet(LF, 4, "Int")) * 72 / A_ScreenDPI, 1) | |
Font.Escapement := NumGet(LF, 8, "Int") | |
Font.Orientation := NumGet(LF, 12, "Int") | |
Font.Weight := NumGet(LF, 16, "Int") | |
Font.Italic := NumGet(LF, 20, "UChar") | |
Font.Underline := NumGet(LF, 21, "UChar") | |
Font.StrikeOut := NumGet(LF, 22, "UChar") | |
Font.CharSet := NumGet(LF, 23, "UChar") | |
Font.OutPrecision := NumGet(LF, 24, "UChar") | |
Font.ClipPrecision := NumGet(LF, 25, "UChar") | |
Font.Quality := NumGet(LF, 26, "UChar") | |
Font.PitchAndFamily := NumGet(LF, 27, "UChar") | |
Font.FaceName := StrGet(&LF + 28, 32) | |
Return Font | |
} | |
GuiClose: | |
Avslut: | |
; ...and gdi+ may now be shutdown | |
Gdip_Shutdown(pToken) | |
ExitApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment