 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Fri Nov 30, 2007 3:45 am Post subject: |
|
|
| lexikos wrote: | | If you comment out these two lines...it should flicker less than it would with GuiControl, but still occasionally "blink." | In my Vista PC the original does not flicker, but if I comment out those two lines it does once in every two or three seconds. |
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1786
|
Posted: Fri Nov 30, 2007 4:04 am Post subject: |
|
|
ha! lexikos' code works! this control is awesome. thank you! ill post all the new examples and some new 1s tomorrow. You have your times of brilliance Lex  |
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1786
|
Posted: Fri Nov 30, 2007 4:46 am Post subject: |
|
|
I encourage everyone to try this example with version 1.10 of the function:
| Code: | #Persistent
SetWorkingDir %A_ScriptDir% ; Ensure working directory is used so that icon location is know
#Include tic-MakeICOBars-1.10.ahk
OnMessage(0x200, "WM_MOUSEMOVE")
SoundGet, Volume
StorePerc := Volume
Height := 50
MakeICOBars(Volume . "|" . Height, "ff0000|0000ff", "Vol.ico")
Gui, 1: +LastFound
Gui1 := WinExist()
Gui, 1: Add, Picture, x10 y10 w256 h256 vVolControl hwndhPic, Vol.ico
Gui, 1: Show, x200 y200 w275 h275, Volume Control
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
{
Loop
{
Sleep, 25
GetKeyState, LButtonState, LButton
If LButtonState = U
Return
MouseGetPos, HX, HY, HWin, HControl
If (HY < CH+CY) && (HY > CY)
{
If (HX > CX) && (HX < CX+(CW//2))
{
MakeICOBars(Round(100*((CH-(HY-CY))/ CH)) . "|" . Height, "ff0000|0000ff", "Vol.ico")
hicon := DllCall("LoadImage", "uInt", 0, "Str", "Vol.ico", "uInt", 2, "Int", 256, "Int", 256, "uInt", 0x10)
SendMessage, 0x170, hicon,,, ahk_id %hPic%
If ErrorLevel
DllCall("DestroyIcon","uint",ErrorLevel)
StorePerc := Round(100*((CH-(HY-CY))/ CH))
SoundSet, % Round(100*((CH-(HY-CY))/ CH)) ;%
}
If (HX < CX+CW) && (HX > CX+(CW//2))
{
MakeICOBars(StorePerc . "|" . Round(100*((CH-(HY-CY))/ CH)), "ff0000|0000ff", "Vol.ico")
hicon := DllCall("LoadImage", "uInt", 0, "Str", "Vol.ico", "uInt", 2, "Int", 256, "Int", 256, "uInt", 0x10)
SendMessage, 0x170, hicon,,, ahk_id %hPic%
If ErrorLevel
DllCall("DestroyIcon","uint",ErrorLevel)
Height := Round(100*((CH-(HY-CY))/ CH))
}
}
}
}
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)
} |
left bar is master vol, and right is nothing but a moving bar. nice new control for people to play with  |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7299 Location: Australia
|
Posted: Fri Nov 30, 2007 4:56 am Post subject: |
|
|
| Laszlo wrote: | | lexikos wrote: | | If you comment out these two lines...it should flicker less than it would with GuiControl, but still occasionally "blink." | In my Vista PC the original does not flicker, but if I comment out those two lines it does once in every two or three seconds. | That's exactly what I meant. (I'm also on Vista.) |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4511 Location: Belgrade
|
Posted: Fri Nov 30, 2007 8:33 am Post subject: |
|
|
2tic
I will just leave to you to see how to return hIcon. Your suggestion is kind of limiting as then you can't set icon by "hIcon var" name, which may present the problem in some applications (although not very likely). The better way is to use something that is forbiden in file name, for instance >. So if you pass >var here, you can return hIcon in var. Just don't get away without this - you already have an icon, its just a matter of fiew lines to return its handle and makes this function more programming friendly.
Now, with hIcon aded to interface, this feels like final version.
| Laszlo wrote: | | It is like a built in language feature |
You are right. _________________
 |
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1786
|
Posted: Fri Nov 30, 2007 8:12 pm Post subject: |
|
|
| 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  |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Fri Nov 30, 2007 9:42 pm Post subject: |
|
|
| Cool! No award. It is not useless at all. It can serve as the GUI for a graphic sound equalizer, where bass, midrange and treble frequencies are color coded. It can be used for tuning parameters of a control system or manually finding best approximations for complicated functions. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7299 Location: Australia
|
Posted: Sat Dec 01, 2007 12:19 am Post subject: |
|
|
| tic wrote: | | 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. | I suppose you could use CreateIcon, passing it pointers to the mask (lpbANDbits) and colour (lpbXORbits) bitmap data (no icon header...) |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|