Quote:
I will just leave to you to see how to return hIcon.
heh. Thanks
At the moment I am just loading it through loadimage, but i would like to know if it is possible without completely rewriting the code to get hIcon without writing to file.
It has some quirks in which Ill likely fix and release as an example with the next release, but heres something quite fun. Try dragging and resizing heights. Everyone should really try this. Quite a cool new control. (Drag left and right for "slideshow" and up and down to resize bars) It freezes sometimes and I havent got it to revert the white hover when you leave the control, but its just an example (it doesnt freeze often if you dont move too fast. ill fix that when i have made other changes to the actual function)
Code:
#Persistent
SetWorkingDir %A_ScriptDir% ; Ensure working directory is used so that icon location is know
#Include tic-MakeICOBars-1.10.ahk
#SingleInstance Force
OnMessage(0x200, "WM_MOUSEMOVE")
SoundGet, Volume
StorePerc := Volume
Height1 := 25
Colour1 := "ff0000"
MakeICOBars(Height1, Colour1, "Vol.ico")
ColourPos := 1
Loop, 15
{
SetFormat, Integer, D
ColourPos++
Random, Height%ColourPos%, 5, 85
Loop, 3
{
SetFormat, Integer, H
Random, Colour, 0x1, 0xFF
StringTrimLeft, Colour, Colour, 2
If StrLen(Colour) = 1
Colour := "0" . Colour
Colour%ColourPos% .= Colour
}
SetFormat, Integer, D
MakeICOBars("+" . Height%ColourPos%, Colour%ColourPos%, "Vol.ico")
}
SetFormat, Integer, D
Loop, 16
{
Colours .= Colour%A_Index% . "|"
Heights .= Height%A_Index% . "|"
}
StringTrimRight, Colours, Colours, 1
StringTrimRight, Heights, Heights, 1
Gui, 1: +LastFound
Gui1 := WinExist()
Gui, 1: Add, Picture, x10 y10 w512 h512 vVolControl hwndhPic, Vol.ico
Gui, 1: Show, AutoSize, Shifter
ControlGetPos, CX, CY, CW, CH, Static1
WindowProcNew := RegisterCallback("WindowProc")
WindowProcOld := DllCall("SetWindowLong", "uint", hPic, "int", -4, "int", WindowProcNew, "uint")
Return
WM_MOUSEMOVE()
{
Global
MouseGetPos, HX, HY, HWin, HControl
If HControl = Static1
{
Sleep, 25
GetKeyState, LButtonState, LButton
If LButtonState = U
{
MouseGetPos, HX, HY, HWin, HControl
If (HY < CH+CY) && (HY > CY) && (HX > CX) && (HX < CW+CX)
{
Bar := 1+((Hx-CX)//32)
If Bar = %StoreBarColour%
Return
StringReplace, Colours, Colours, ffffff, %OldColour%, All
StringSplit, Colour, Colours, |
Colours =
Loop, 16
{
If A_Index = %Bar%
Colours .= "ffffff|"
Else
Colours .= Colour%A_Index% . "|"
}
StringTrimRight, Colours, Colours, 1
StoreBarColour := Bar
OldColour := Colour%Bar%
StringSplit, Colour, Colours, |
GoSub, MakeIcon
;Tooltip, %Heights%`n%Colours%
Return
}
}
StoreBar =
Drag =
Loop
{
Sleep, 50
GetKeyState, LButtonState, LButton
If LButtonState = U
Return
MouseGetPos, HX, HY, HWin, HControl
If (HY < CH+CY) && (HY > CY) && (HX > CX) && (HX < CW+CX)
{
Heights =
Bar := 1+((Hx-CX)//32)
Loop, 16
{
If (A_Index = %Bar%) && (!Drag)
{
If StrLen(Round(100*(CH-(HY-CY))/ CH)) = 1
Heights .= "0" . Round(100*(CH-(HY-CY))/ CH) . "|"
Else
Heights .= Round(100*(CH-(HY-CY))/ CH) . "|"
}
Else
{
If StrLen(Height%A_Index%) = 1
Heights .= "0" . Height%A_Index% . "|"
Else
Heights .= Height%A_Index% . "|"
}
}
StringTrimRight, Heights, Heights, 1
If (StoreBar) && (Bar != %StoreBar%)
{
Drag = 1
If Bar > %StoreBar%
{
ShiftHeight =
ShiftColours =
Num := 16
Loop, % Bar-StoreBar ;%
{
If StrLen(Height%Num%) = 1
Height%Num% := "0" . Height%Num%
ShiftHeight .= "|" . Height%Num%
ShiftColours .= "|" . Colour%Num%
Num--
}
StringTrimLeft, ShiftHeight, ShiftHeight, 1
StringTrimLeft, ShiftColours, ShiftColours, 1
StringTrimRight, Heights, Heights, % 3*(Bar-StoreBar) ;%
StringTrimRight, Colours, Colours, % 7*(Bar-StoreBar) ;%
Heights := ShiftHeight . "|" . Heights
Colours := ShiftColours . "|" . Colours
StringSplit, Height, Heights, |
StringSplit, Colour, Colours, |
}
If Bar < %StoreBar%
{
Drag = 1
ShiftHeight =
ShiftColours =
Loop, % StoreBar-Bar ;%
{
If StrLen(Height%A_Index%) = 1
Height%A_Index% := "0" . Height%A_Index%
ShiftHeight .= Height%A_Index% . "|"
ShiftColours .= Colour%A_Index% . "|"
}
StringTrimRight, ShiftHeight, ShiftHeight, 1
StringTrimRight, ShiftColours, ShiftColours, 1
StringTrimLeft, Heights, Heights, % 3*(StoreBar-Bar) ;%
StringTrimLeft, Colours, Colours, % 7*(StoreBar-Bar) ;%
Heights := Heights . "|" . ShiftHeight
Colours := Colours . "|" . ShiftColours
StringSplit, Height, Heights, |
StringSplit, Colour, Colours, |
}
}
GoSub, MakeIcon
Height%Bar% := Round(100*(CH-(HY-CY))/ CH)
StoreBar := Bar
}
}
Return
}
MakeIcon:
E := MakeICOBars(Heights, Colours, "Vol.ico")
If E
MsgBox, %E%
hicon := DllCall("LoadImage", "uInt", 0, "Str", "Vol.ico", "uInt", 2, "Int", 512, "Int", 512, "uInt", 0x10)
SendMessage, 0x170, hicon,,, ahk_id %hPic%
If ErrorLevel
DllCall("DestroyIcon","uint",ErrorLevel)
Return
}
Esc::ExitApp
WindowProc(hwnd, uMsg, wParam, lParam)
{
global WindowProcOld
Critical 500 ; Must ensure AutoHotkey doesn't check for messages.
if (uMsg = 0x14)
return 1
if (uMsg = 0xF)
{
WinGetPos,,, w, h, ahk_id %hwnd%
VarSetCapacity(ps,64,0)
DllCall("BeginPaint","uint",hwnd,"uint",&ps)
hdc := NumGet(ps,0)
if hicon := CallWindowProc(WindowProcOld, hwnd, 0x171,0,0) ; STM_GETICON
{
; Get a brush to be used as the background.
hbr := DllCall("GetSysColorBrush","int",15)
; DrawIconEx draws the background and icon into a temporary buffer,
; then draws the buffer onto the window. (It draws directly onto the
; window if hbr is not a valid brush handle.)
DllCall("DrawIconEx","uint",hdc,"int",0,"int",0,"uint",hicon
,"int",w,"int",h,"uint",0,"uint",hbr,"uint",0x3)
}
DllCall("EndPaint","uint",hwnd,"uint",&ps)
return 0
}
res := CallWindowProc(WindowProcOld, hwnd, uMsg, wParam, lParam)
return res
}
CallWindowProc(wndProc, hwnd, uMsg, wParam, lParam) {
return DllCall("CallWindowProc","uint",wndProc,"uint",hwnd,"uint",uMsg,"uint",wParam,"uint",lParam)
}
Do I win the award for most unnecessarily elaborate and most useless code?
Edit: I see why theres an error now. The last number is being sent as blank. will be easy to fix
Edit2: Fixed.....I think
