AutoHotkey Community

It is currently May 25th, 2012, 10:05 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 53 posts ]  Go to page Previous  1, 2, 3, 4
Author Message
 Post subject:
PostPosted: November 30th, 2007, 4:45 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 30th, 2007, 5:04 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1832
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 :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 30th, 2007, 5:46 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1832
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 :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 30th, 2007, 5:56 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
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.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 30th, 2007, 9:33 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 30th, 2007, 9:12 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1832
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? :D

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 :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 30th, 2007, 10:42 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 1st, 2007, 1:19 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
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...)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 53 posts ]  Go to page Previous  1, 2, 3, 4

All times are UTC [ DST ]


Who is online

Users browsing this forum: IsNull and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group