Jump to content

_ButtonHover() UDF


Valuater
 Share

Recommended Posts

Excuse me but I cannot create topics, then I will use this

Please test this script, very simple and ugly code, but...

Suggestions and bug reports are welcome. :)

;Quick buttons by !=
;NEED IMAGEMAGICK (GPL) CONVERT.EXE, VCOMP90.DLL, MICROSOFT.VC90.OPENMP.MANIFEST IN SCRIPT FOLDER OR %PATH% ENVIROMENT VARIABLE (included)
;Name of file is temporary
;Coords are horizontal pos, vertical pos, horizontal size and vertical size
;Font names with no spaces, use - in names.
;Todo bold, italic, etc.
;Background optios are normal, radial or plasma
;Always use $BS_BITMAP in button style
;Uses _MouseHover.au3 Author: marfdaman (Marvin)


#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <Misc.au3>
#include <Array.au3>
#include-once

$dll = DllOpen("user32.dll")

Local $HoverArray[1], $ControlID, $Global_I = 0, $__ControlID, $HoverActive = 0, $Temp_Found = 0, $szTemp_Array[2]
Local $ImgFolder = "GuiImgs\";Use \ at end
;Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui
$Main_Gui = GUICreate("Quick buttons", 600, 520,-1,-1)
DirCreate($ImgFolder)
IF NOT FileExists($ImgFolder&'Back.bmp') Then RunWait('convert -size 600x520 gradient:brown-black -font "gigi" -pointsize 72 -fill white -annotate +155+160 "Quick Buttons" -alpha off '&$ImgFolder&'back.bmp', "", @SW_HIDE)
$Background = GUICtrlCreatePic($ImgFolder&'\back.bmp', 0, 0, 600, 520)
GUICtrlSetState(-1, $GUI_DISABLE)

GuiCtrlCreateLabel('Hold "CTRL" and exit to delete all images.', 50, 20, 550, 30)
GUICtrlSetBkColor( -1, $GUI_BKCOLOR_TRANSPARENT )
Guictrlsetcolor (-1, 0xFFFFFF)
GUICtrlSetFont(-1, 18, 400, 2)

GuiCtrlCreateLabel('Label flags.', 350, 165, 550, 30)
GUICtrlSetBkColor( -1, $GUI_BKCOLOR_TRANSPARENT )
Guictrlsetcolor (-1, 0xFFFFFF)
GUICtrlSetFont(-1, 18, 400, 2,"Tahoma")

$_bttype = BitOR($BS_FLAT,$BS_CENTER,$BS_BITMAP)
;file,text of button / position,size / font name,size,color / style,color1,color2 / button options

$01_B = _IM_Button("tmp%TST","20%50%100%40","Calibri%20%white","normal%gray%pink",$_bttype);Generate image and create button
_IM_Button($01_B&"_%TST","0%0%100%40","Arial%28%black","normal%green%tomato",0);Use _ at end for generate image only

$02_B = _IM_Button("tmp%GO","30%100%80%30","Garamond%18%chocolate","normal%white%yellow",$_bttype)
_IM_Button($02_B&"_%Home","30%100%80%30","Garamond%18%red","normal%black%lime",0)

$03_B = _IM_Button("tmp%Arial","40%150%80%20","Arial%14%red","normal%lime%lime",$_bttype)
_IM_Button($03_B&"_%Garamond","200%150%80%20","Garamond%14%black","normal%yellow3%yellow",0)

$04_B = _IM_Button("tmp%big","50%180%100%20","Fixedsys%16%green4","normal%white%salmon",$_bttype)
_IM_Button($04_B&"_%little","200%180%100%20","Fixedsys%18%black","normal%purple%white",0)

$05_B = _IM_Button("tmp%dry","60%210%80%25","Forte%22%blue","plasma%yellow%salmon",$_bttype)
_IM_Button($05_B&"_%wet","200%210%80%25","Forte%22%white","plasma%green%pink",0)

$06_B = _IM_Button("tmp%YOU","70%240%60%35","Georgia%12%lime","radial%orange%black",$_bttype)
_IM_Button($06_B&"_%ONLY","200%240%60%35","Georgia%18%lime","radial%orange%black",0)

$_bttype = BitOR($BS_CENTER,$BS_BITMAP)

$07_B = _IM_Button("tmp%Always","60%280%90%35","Edwardian-Script-ITC%34%white","normal%aqua%black",$_bttype)
_IM_Button($07_B&"_%Online","200%280%90%35","Edwardian-Script-ITC%36%yellow2","normal%aqua%black",0)

$08_B = _IM_Button("tmp%0001","90%320%100%40","Impact%20%black","radial%lime%black",$_bttype)
_IM_Button($08_B&"_%1000","200%320%100%40","Impact%28%white","normal%lime%black",0)

$09_B = _IM_Button("tmp%Strange","100%370%75%25","Marlett%12%brown","radial%orange%aqua",$_bttype)
_IM_Button($09_B&"_%Font","200%370%75%25","Marlett%12%brown","radial%black%brown",0)

$10_B = _IM_Button("tmp%From","110%410%70%30","Papyrus%18%black","radial%orange%pink",$_bttype)
_IM_Button($10_B&"_%Egypt","200%410%70%30","Papyrus%18%lime","radial%black%black",0)

$11_B = _IM_Button("tmp%Focus","120%450%70%30","Arial%18%black","radial%white%pink4",$_bttype)
_IM_Button($11_B&"_%Focus","200%450%70%30","Arial%20%white","radial%red%gray",0)

$12_B = _IM_Button("tmp%View","130%50%70%30","French-Script-MT%26%black","radial%salmon%blue",$_bttype)
_IM_Button($12_B&"_%All","0%50%70%30","French-Script-MT%26%white","radial%red%green",0)

$13_B = _IM_Button("tmp%1","220%70%30%30","Arial%18%white","normal%rgb(65,105,225)%rgb(255,255,240)",$_bttype)
_IM_Button($13_B&"_%2","0%50%30%30","Arial%20%black","normal%pink%green",0)

$_bttype = BitOR($BS_FLAT,$BS_CENTER,$BS_BITMAP)

$normal = _IM_Button("tmp%normal","270%50%50%50","Arial%12%white","normal%red%black",$_bttype)
_IM_Button($normal&"_%normal","0%50%50%50","Arial%16%white","normal%blue%black",0)
$radial = _IM_Button("tmp%radial","330%50%50%50","Arial%12%white","radial%red%black",$_bttype)
_IM_Button($radial&"_%radial","0%50%50%50","Arial%16%white","radial%blue%black",0)
$plasma = _IM_Button("tmp%plasma","390%50%50%50","Arial%12%white","plasma%red%black",$_bttype)
_IM_Button($plasma&"_%plasma","0%50%50%50","Arial%16%white","plasma%blue%black",0)

$14_B = _IM_Button("tmp%","230%170%30%90","Arial%18%white","normal%black%purple",$_bttype)
_IM_Button($14_B&"_%","0%50%30%90","Arial%20%black","normal%purple%black",0)

$15_B = _IM_Button("tmp%Easy","160%250%50%50","Arial%18%white","plasma%orange%purple",$_bttype)
_IM_Button($15_B&"_%Quick","0%50%50%50","Arial%20%green","plasma%yellow%green",0)

$16_B = _IM_Button("tmp%Click","210%280%100%35","Arial%18%brown","plasma%yellow%yellow",$_bttype)
_IM_Button($16_B&"_%Dont click","0%50%100%35","Arial%20%green","plasma%black%black",0)

$anyvar = _IM_Button("tmp%X","230%320%30%30","Georgia%28%white","normal%red%lime",$_bttype)
_IM_Button($anyvar&"_%Y","0%50%30%30","Georgia%36%white","normal%black%aqua",0)

$17_B = _IM_Button("tmp%unknown","190%350%90%30","verdana%18%white","radial%yellow%blue",$_bttype)
_IM_Button($17_B&"_%device","0%50%90%30","verdana%20%green","radial%black%red",0)

$18_B = _IM_Button("tmp%welcome","190%400%100%35","verdana%18%white","radial%brown%gray",$_bttype)
_IM_Button($18_B&"_%to my life","0%50%100%35","verdana%20%green","plasma%blue%pink",0)

$19_B = _IM_Button("tmp%","200%450%10%10","verdana%18%white","radial%red%red",$_bttype)
_IM_Button($19_B&"_%","0%0%10%10","verdana%20%green","radial%green%green",0)

$20_B = _IM_Button("tmp%AutoIt","320%250%200%100","verdana%48%yellow","normal%brown%blue",$_bttype)
_IM_Button($20_B&"_%Quick\n and\n easy.","0%0%200%100","verdana%24%white","normal%red%black",0)

$ExitButton = _IM_Button("tmp%Exit","280%480%75%30","verdana%20%black","radial%green%black",$_bttype)
_IM_Button($ExitButton&"_%Now","0%0%75%30","verdana%20%white","radial%red%black",0)

;Flag labels
$Label001 = FlagLabel("1", 380, 195, 8, 8)
$Label002 = FlagLabel("0", 400, 195, 8, 8)

;Check Flag labels
$ChkLbs = _IM_Button("tmp%Check","360%210%75%30","verdana%20%yellow","radial%lime%black",$_bttype)
_IM_Button($ChkLbs&"_%Labels","0%0%75%30","verdana%20%white","radial%aqua%black",0)

GuiCtrlCreateLabel('Button flags.', 360, 350, 550, 30)
GUICtrlSetBkColor( -1, $GUI_BKCOLOR_TRANSPARENT )
Guictrlsetcolor (-1, 0xFFFFFF)
GUICtrlSetFont(-1, 18, 400, 2,"Tahoma")

;flag Buttons
$_FlagButton01 = FlagButton("tmp%r","300%390%50%50","webdings%24%yellow","radial%red%black",$_bttype)
FlagButton($_FlagButton01&"_%n","0%0%50%50","webdings%24%white","radial%green%black",0)
ChngBtFlag($_FlagButton01)

$_FlagButton02 = FlagButton("tmp%p","360%390%50%50","wingdings-3%24%yellow","radial%red%black",$_bttype)
FlagButton($_FlagButton02&"_%q","0%0%50%50","wingdings-3%24%white","radial%green%black",0)

$_FlagButton03 = FlagButton("tmp%t","420%390%50%50","wingdings-3%24%yellow","radial%red%black",$_bttype)
FlagButton($_FlagButton03&"_%u","0%0%50%50","wingdings-3%24%white","radial%green%black",0)

$_FlagButton04 = FlagButton("tmp%u","480%390%50%50","wingdings%24%yellow","radial%red%black",$_bttype)
FlagButton($_FlagButton04&"_%v","0%0%50%50","wingdings%24%white","radial%green%black",0)

$_FlagButton05 = FlagButton("tmp%Q","540%390%50%50","wingdings-3%24%yellow","radial%red%black",$_bttype)
FlagButton($_FlagButton05&"_%P","0%0%50%50","wingdings-3%24%white","radial%green%black",0)
ChngBtFlag($_FlagButton05)

;check flag Button
$ChkBts = _IM_Button("tmp%Check","400%450%90%30","verdana%20%yellow","radial%purple%black",$_bttype)
_IM_Button($ChkBts&"_%Buttons","0%0%90%30","verdana%20%white","radial%khaki%black",0)
GUISetState()
;Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui-Gui

;Main loop - Main loop - Main loop - Main loop - Main loop - Main loop - Main loop - Main loop
While 1
    _ProcessHover()
    $msg = GUIGetMsg()
    Switch $msg
        ;flag labels
        Case $Label001
            ChngLbFlag($Label001)
        Case $Label002
            ChngLbFlag($Label002)

    EndSwitch
    Select
        Case $msg = $ExitButton OR $msg = $GUI_EVENT_CLOSE
            If NOT @Compiled Then
                IF _IsPressed("11", $dll) Then DirRemove ($ImgFolder,1)
            EndIf
            ExitLoop
        ;flag Buttons
        Case $msg = $_FlagButton01
            ChngBtFlag($_FlagButton01)
        Case $msg = $_FlagButton02
            ChngBtFlag($_FlagButton02)
        Case $msg = $_FlagButton03
            ChngBtFlag($_FlagButton03)
        Case $msg = $_FlagButton04
            ChngBtFlag($_FlagButton04)  
        Case $msg = $_FlagButton05
            ChngBtFlag($_FlagButton05)
            
        Case $msg = $ChkLbs
            MsgBox(8192, "Values", GUICtrlRead($Label001)&"#"&GUICtrlRead($Label002))           
        Case $msg = $ChkBts
            MsgBox(8192, "Values", GUICtrlRead($_FlagButton01)&"#"&GUICtrlRead($_FlagButton02)& _
            "#"&GUICtrlRead($_FlagButton03)&"#"&GUICtrlRead($_FlagButton04)&"#"&GUICtrlRead($_FlagButton05))
    EndSelect
WEnd
;Main loop - Main loop - Main loop - Main loop - Main loop - Main loop - Main loop - Main loop

;Functions-Functions-Functions-Functions-Functions-Functions-Functions-Functions-Functions-Functions
;################################################################################
Func _IM_Button($Names="file%txt",$PosString="0%0%50%25",$FontString="arial%20%Black",$BackString="normal%white%black",$IM_BtType=896)
    $NameArray=StringSplit ($Names,'%' ,0)
    $OnlyImage = StringInStr($NameArray[1],"_",0)
    $PosArray=StringSplit ($PosString,'%' ,0)
    $BackArray=StringSplit ($BackString,'%' ,0)
    $IM_B = 0
    IF $OnlyImage = 0 Then
        $IM_B = GUICtrlCreateButton($NameArray[1], $PosArray[1], $PosArray[2], $PosArray[3],$PosArray[4], $IM_BtType)
        _HoverAddCtrl($IM_B)
    EndIf   
        
    If NOT FileExists($ImgFolder&$NameArray[1]&'.bmp') AND NOT FileExists($ImgFolder&$IM_B&'.bmp') Then
    $Convert = 'Convert'
    $Convert &= ' -size '&$PosArray[3]&'X'&$PosArray[4]
    IF $BackArray[1] = "normal" Then $Convert &= ' gradient:'& $BackArray[2]&"-"&$BackArray[3]
    IF $BackArray[1] = "plasma" Then $Convert &= ' plasma:'& $BackArray[2]&"-"&$BackArray[3]    
    IF $BackArray[1] = "radial" Then $Convert &= ' radial-gradient:'& $BackArray[2]&"-"&$BackArray[3]
    $FontArray=StringSplit ($FontString, '%' ,0)
    $Convert &= ' -font "'&$FontArray[1]&'"'&' -pointsize '&$FontArray[2]
    $Convert &= ' -fill '&$FontArray[3]
    $Convert &= ' -gravity center '
    $Convert &= ' -annotate +0+0 "'&$NameArray[2]&'"'
    $Convert &= ' -alpha off '
    $Convert &= ' "'&$ImgFolder&$NameArray[1]&'.bmp"'
    $LetsGo = RunWait($Convert, "", @SW_HIDE)
    EndIf   
    
    IF $OnlyImage = 0 Then
        FileMove ($ImgFolder&$NameArray[1]&'.bmp', $ImgFolder&$IM_B&'.bmp' , 1)
        GUICtrlSetImage ($IM_B,$ImgFolder&$IM_B&'.bmp',0)
    EndIf

    Return $IM_B
EndFunc
;################################################################################
Func _HoverAddCtrl($___ControlID)
    _ArrayAdd($HoverArray, $___ControlID)
EndFunc
;################################################################################
Func _HoverCheck()
    $HoverData = GUIGetCursorInfo()
    If Not IsArray($HoverData) Then
    ;MsgBox(64,'dbg','Exiting..',1);Exiting on lost focus. :S
        Sleep(500)
    Else
        $Temp_Found = 0
        For $i = 1 To UBound($HoverArray)-1
            If $HoverData[4] = $HoverArray[$i] Then
                $Temp_Found = $i
            EndIf
        Next
        Select
            Case $Temp_Found = 0 And $HoverActive = 1 Or $Temp_Found <> 0 And $Temp_Found <> $Global_I And $HoverActive = 1
                $HoverActive = 0
                $Temp_Found = 0
                $szTemp_Array[0] = "LostHover"
                $szTemp_Array[1] = $HoverArray[$Global_I]
                Return $szTemp_Array
            Case $Temp_Found > 0 And $HoverActive = 0
                $Global_I = $Temp_Found
                $HoverActive = 1
                $Temp_Found = 0
                $szTemp_Array[0] = "AcquiredHover"
                $szTemp_Array[1] = $HoverArray[$Global_I]
                Return $szTemp_Array
        EndSelect
    EndIf       
EndFunc
;################################################################################
Func _ProcessHover()
    $ControlID = _HoverCheck()
    If IsArray($ControlID) Then
        If $ControlID[0] = "AcquiredHover" Then
            For $q=1 to UBound($HoverArray)-1
                Switch $ControlID[1]
                    Case $HoverArray[$q]
                        GUICtrlSetImage ($ControlID[1],$ImgFolder&$HoverArray[$q]&'_.bmp',0)
                EndSwitch
            Next
        Else
            For $q=1 to UBound($HoverArray)-1
                Switch $ControlID[1]
                    Case $HoverArray[$q]
                        GUICtrlSetImage ($ControlID[1],$ImgFolder&$HoverArray[$q]&'.bmp',0)
                EndSwitch
            Next
        EndIf
    EndIf
EndFunc
;################################################################################
Func FlagLabel($flag="0",$hpos=0, $vpos=0,$hsize=5,$Vsize=5)
    IF $flag = 0 Then 
        $tmpLb=GuiCtrlCreateLabel($flag, $hpos, $vpos, $hsize, $Vsize)
        GUICtrlSetbkColor(-1, 0xff0000)
        GUICtrlSetColor(-1, 0xff0000)
        GUICtrlSetCursor(-1, 0)
    Else
        $tmpLb=GuiCtrlCreateLabel($flag, $hpos, $vpos, $hsize, $Vsize)
        GUICtrlSetbkColor(-1, 0x00f444)
        GUICtrlSetColor(-1, 0x00f444)
        GUICtrlSetCursor(-1, 0)
    EndIf
    Return $tmpLb
EndFunc

Func ChngLbFlag($WhatLabel)
    IF GUICtrlRead($WhatLabel) = 0 Then
        GUICtrlSetbkColor($WhatLabel, 0x00f444)
        GUICtrlSetColor($WhatLabel, 0x00f444)
        GUICtrlSetData ($WhatLabel, "1")
    Else
        GUICtrlSetbkColor($WhatLabel, 0xff0000)
        GUICtrlSetColor($WhatLabel, 0xff0000)
        GUICtrlSetData ($WhatLabel, "0")
    EndIf
EndFunc
;################################################################################
Func FlagButton($Names="file%txt",$PosString="0%0%50%25",$FontString="arial%20%Black",$BackString="normal%white%black",$IM_BtType=896)
    $NameArray=StringSplit ($Names,'%' ,0)
    $OnlyImage = StringInStr($NameArray[1],"_",0)
    $PosArray=StringSplit ($PosString,'%' ,0)
    $BackArray=StringSplit ($BackString,'%' ,0)
    $IM_B = 0
    IF $OnlyImage = 0 Then
        $IM_B = GUICtrlCreateButton("0", $PosArray[1], $PosArray[2], $PosArray[3],$PosArray[4], $IM_BtType)
    EndIf   
    If NOT FileExists($ImgFolder&$NameArray[1]&'.bmp') AND NOT FileExists($ImgFolder&$IM_B&'.bmp') Then
        $Convert = 'Convert'
    $Convert &= ' -size '&$PosArray[3]&'X'&$PosArray[4]
    IF $BackArray[1] = "normal" Then $Convert &= ' gradient:'& $BackArray[2]&"-"&$BackArray[3]
    IF $BackArray[1] = "plasma" Then $Convert &= ' plasma:'& $BackArray[2]&"-"&$BackArray[3]    
    IF $BackArray[1] = "radial" Then $Convert &= ' radial-gradient:'& $BackArray[2]&"-"&$BackArray[3]
    $FontArray=StringSplit ($FontString, '%' ,0)
    $Convert &= ' -font "'&$FontArray[1]&'"'&' -pointsize '&$FontArray[2]
    $Convert &= ' -fill '&$FontArray[3]
    $Convert &= ' -gravity center '
    $Convert &= ' -annotate +0+0 "'&$NameArray[2]&'"'
    $Convert &= ' -alpha off '
    $Convert &= ' "'&$ImgFolder&$NameArray[1]&'.bmp"'
    $LetsGo = RunWait($Convert, "", @SW_HIDE)
    EndIf   
    
    IF $OnlyImage = 0 Then
        FileMove ($ImgFolder&$NameArray[1]&'.bmp', $ImgFolder&$IM_B&'.bmp' , 1)
        GUICtrlSetImage ($IM_B,$ImgFolder&$IM_B&'.bmp',0)
    EndIf

    Return $IM_B
EndFunc
;################################################################################
Func ChngBtFlag($WhatButton)
    IF GUICtrlRead($WhatButton) = 0 Then
        GUICtrlSetImage($WhatButton, $ImgFolder&$WhatButton&"_.bmp")
        GUICtrlSetData ($WhatButton, "1")
    Else
        GUICtrlSetImage($WhatButton, $ImgFolder&$WhatButton&".bmp")
        GUICtrlSetData ($WhatButton, "0")
    EndIf
EndFunc
;################################################################################

You can download all you need here: http://cid-181623e0616a791e.skydrive.live....blic/Magick.rar

Sorry about my english. :)

Link to comment
Share on other sites

  • Replies 68
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

  • 2 weeks later...

Just switched to ButtonHoverTag from ButtonHover v1.0.0.

Haven't had a chance yet to fiddle around with the new features, but do have a question.

At first OnEvent mode didn't work with the new UDF, however after reading through this post I got it working by adding [0] after the RETURN $Xbtn in the __HoverButton() function. For the rest I haven't modiefied anything in ButtonHoverTag.

Question:

How do I delete a button created with __HoverButton()?

I tried:

$Button1 = __HoverButton(...)

GuiCtrlDelete($Button1)

but this only deletes the image and not the label.

Then I saw the __HoverButtonSetState() function and thought, let's give it a try. But I get an errormessage:

C:\Documents and Settings\Administrator\My Documents\AutoIT Files\_ButtonHoverTagCSM.au3 (178) : ==> Subscript used with non-Array variable.:

GUICtrlSetState($Xbtn[0], $btn_state)

GUICtrlSetState($Xbtn^ ERROR

Thanks! Edited by Cusem
Link to comment
Share on other sites

To Valuater,

Can you please explain (on example) how can I have 2 or more DIFFERENT button STYLES in the SAME SCRIPT using this __ButtonHoverTag.au3. I tried over and over again but it didn't work, I'm still a newbie. Please help!

Thanks in advance!

Playlet

I have sent a message to wraithdu who wrote the "Tag" portion. Hopefully he will reply to you soon

8)

NEWHeader1.png

Link to comment
Share on other sites

First off; Thanks for the great work on the _ButtonHoverTag UDF!

I do have some minor issues though.

I'm using _ButtonHoverTag in conjunction with Xskin and multiple GUI's. On some GUI's the UDF detects _HoverButtons faulty.

For instance, I have a $GUI_About (which pops up after pressing the HoverButton "About" in $GUI_Main) -> Shortened code (I didn't post $GUI_Main code since it is too extensive):

Local $iOpt = Opt("GuiOnEventMode", 0)  
Local $GuiWidth = 390
Local $GuiHeight = 300
    
$GUI_About = XSkinGUICreate("About", $GuiWidth, $GuiHeight, $Skin_Folder)
    
$PIC_About  = GUICtrlCreatePic("", 50, 50, 50, 50)
_SetImage($PIC_About, @ScriptDir & "\Data\Graphics\about.png")
    
$LBL_TitleAbout = GUICtrlCreateLabel($VER, 125, 57, 205, 20)
GUICtrlSetFont($LBL_TitleAbout, 11, 500, 0, "Century Gothic")

$BTN_OKAbout = _HoverButton("OK", $GuiWidth - 130, $GuiHeight - 80, 80, 30)
$BTN_ChangeLog = _HoverButton("Changelog", $GuiWidth - 210, $GuiHeight - 80, 80, 30)
...

I don't know why, but when I mouseover the $LBL_TitleAbout (which reads a predefined constant "My Script v0.01b"), it draws HoverButtons over the $PIC_About. Could this be a conflict between the _HoverButtonTag UDF and Yashied's Icons UDF?

I also have some occasional errors with the XSkin created GUI's. Sometimes a NORMAL.BMP is drawn in some part of a border of the XSkin GUI. This error isn't consistent though. Sometimes it happens, but mostly it won't. If it does happen, mouse-overing the error doesn't help. Only redrawing the gui does.

I figure both these problems are related to the way the ControlID's are stored in the $cHoverID array. I haven't been able to create a fix, since I do not fully understand the working of _HoverButtonTag. I tried populating the $cHoverID array with handle values rather than the values returned by the functions, but since it draws the images to "temp - 1" (= $cHoverID[x] - 1) this doesn't work. I wanted to try creating a 3d array of $cHoverID with the handle of the PIC in $cHoverID[x][] and the handel of the LABEL in $cHoverID[][x], but I figure to post this in the forum first, because I figure I'll wreck the rest of the script by doing this.

Another issue I have with _HoverButtonTag is something that has been discussed in this thread already, the buttons often do not refresh when clicked. So If I click a HoverButton that popsup a new window, the state of the Hoverbutton will remain OVER.BMP (and doesn't even reach PRESSED.BMP). It will refresh to NORMAL.BMP only if I mouseover the button again, when the popup window is closed. I figure this has to do with the fact that HoverButton executes on MouseDown instead of MouseUp and I figure _HoverWaitButtonUp() is the answer to this. I don't know how to use it however. So how do I use _HoverWaitbuttonUp?

About the different button images; I didn't understand this at first, but after reading through the code figured out that you should put the value specified for the $XBTag parameter in front of the usual file names in your skin folder.

For instance:

;__HoverButton($XBtext, $XBleft, $XBtop, $XBwidth, $XBheight, $XBtag = "", $XBcolor = "")
$BTN_example_otherstyle = __HoverButton("Example Button", 10, 10, 100, 30, "OTHERSTYLE")

This button will use OTHERSTYLENORMAL.BMP, OTHERSTYLEPRESSED.BMP and OTHERSTYLEOVER.BMP instead of NORMAL.BMP, PRESSED.BMP and OVER.BMP, so make sure you put these file in the $Skin_Folder.

Don't know if this is commonly understood already (don't think so). If it is, just pretend this example was never posted, cause it makes me look stupid >_<

Link to comment
Share on other sites

  • 2 weeks later...

I have created an __HoverButtonDestroy($hwnd)

It works, but Valuater, could you verify it to make sure I'm not missing something that messes up the whole __ButtonHoverTag UDF ? Thanks!

Any word on the __HoverWaitbuttonUp example yet?

Func __HoverButtonDestroy($hwnd)
    Local $i = _ArraySearch($cHoverID, $hwnd[1])
    _ArrayDelete($cHoverID, $i)
    _ArrayDelete($cHoverTag, $i)
    GUICtrlDelete($hwnd[0])
    GUICtrlDelete($hwnd[1])
EndFunc

EDIT: It doesn't work. At some instances the script crashes at _CheckHoverAndPressed($_GUI = "") (Array has incorrect number of subscripts) at

$CtrlId = _ControlHover(0, $_GUI)
    $tempIndex = @extended
    $tempID = $cHoverID[$tempIndex]

No time to look into it right now though.

EDIT2: I added the following line to the function and now it seems to work ok. Would still like some comment since I don't fully understand the UDF and don't want this destroy function to mess up the UDF's operation.

$cHoverID[0] = 0
Edited by Cusem
Link to comment
Share on other sites

I'm back now. I've rewritten some of __ButtonHoverTag() to fix a few issues:

1) removed some unnecessary code, and added one or two things

2) big fix with return values and such

3) I think I fixed the random GUI image changing problem as well

Ok, there's a back story to #2. I fixed some problems with this UDF a while back, and didn't realize why what I fixed actually worked. Well, while browsing the BugTrac some time ago I came across a ticket by Valik mentioning to fix the documentation for the = and == operators. Turns out that == FORCES a STRING comparison of the two arguments. Most of the time this doesn't matter, but eventually you'll shoot yourself in the foot if you're not careful. What I fixed now, is that return values from the functions, especially @error returns, are all numerical. Mixing numbers and "" strings is bad juju. For example (0 == "") is false, while (0 = "") is true. In the first case a string comparison is done, while in the second a numerical comparison is done, and Number("") is 0. I digress...

__ButtonHoverTag()

**see below

Make sure your skin paths are correct in this test script:

#include <XSkin.au3>
#include <__ButtonHoverTag.au3>

Opt("GUIOnEventMode", 1) ; OnEvent mode

; global variables
$Skin_Folder = "C:\Program Files\AutoIt3\XSkin\Skins\Rezak"
$XButton_Location = "C:\Program Files\AutoIt3\XSkin\Buttons\_Rezak"
$Icon_Folder = "C:\Program Files\AutoIt3\XSkin\Skins\Default"

$nGUI = XSkinGUICreate("XSkin GUI Demo", 300, 170, $Skin_Folder, 1, 15)
$XIcon = XSkinIcon($nGUI, 2) ; exit and minimize buttons

GUICtrlCreateLabel("XSkin GUI _ButtonHoverTag Demo", 30, 45)
$Button1 = __HoverButton("Button1", 70, 80, 65, 30)
$Button2 = __HoverButton("Button2", 165, 80, 65, 30)
; __HoverButtonSetState($Button2, $GUI_DISABLE) ; for example, to disable the button

; control events
GUICtrlSetOnEvent($Button1[0], "_Button1")
GUICtrlSetOnEvent($Button2[0], "_Button2")
GUICtrlSetOnEvent($XIcon[1], "_Close")
GUICtrlSetOnEvent($XIcon[2], "_Minimize")

GUISetState(@SW_SHOW, $nGUI)

While 1
    __CheckHoverAndPressed($nGUI)
    Sleep(50)
WEnd

Func _Button1()
    If __HoverWaitButtonUp($nGUI) Then Return

    MsgBox(0, "Button1", "Clicked button 1.")
EndFunc

Func _Button2()
    If __HoverWaitButtonUp($nGUI) Then Return

    MsgBox(0, "Button2", "Clicked button 2.")
EndFunc

Func _Minimize()
    GUISetState(@SW_MINIMIZE, $nGUI)
EndFunc

Func _Close()
    Exit
EndFunc
Edited by wraithdu
Link to comment
Share on other sites

Thanks! Works great now with the HoverWaitButtonUp example.

Wouldn't it be easier to just add an __HoverButtonDelete($hwnd) function in the UDF? Makes it a lot easier for people who don't understand how __ButtonHoverTag works.

Ik have created a function to quickly change and refresh TAG's for my own script. Maybe this would also be handy to include.

Func _HoverButtonSetTag($hwnd, $tag)
    
    Local $index
    If IsArray($hwnd) Then
        $index = _ArraySearch($cHoverID, $hwnd[1])
        If @error Then Return 0
    Else
        $index = _ArraySearch($cHoverID, $hwnd + 1)
        If @error Then 
            $index = _ArraySearch($cHoverID, $hwnd)
            If @error Then Return 0
        EndIf
    EndIf
    
    
    If $cHoverTag[$index] <> $tag Then
    
        $cHoverTag[$index] = $tag
        
        Local $error = 1
        For $a = 2 To UBound($cHoverID) - 1
            If GUICtrlSetImage($cHoverID[$a] - 1, $XButton_Location & "\" & $cHoverTag[$a] & "Normal" & $XBType) = 0 Then $error -= 1
        Next
        
        Select
            Case $error = 1
                Return $error
            Case Else
                Return $error - 1
        EndSelect
    Else
        
        Return 0
    
    EndIf
    
EndFunc
Edited by Cusem
Link to comment
Share on other sites

Updated __ButtonHoverTag.au3 (version 2.0.2):

- added __HoverButtonDelete

- __HoverWaitButtonUp now behaves like standard windows dialogs - if the primary mouse button is left down but the mouse if moved off the control, it will alternate states between pressed and hovered, and will fire the event if the button is released over the control

- some other edits for better readability

__ButtonHoverTag

#Region __ButtonHoverTag; ************** note two underscores "__" ************************************
;===============================================================================
;   UDF Name: __ButtonHoverTag.au3
;
;   Version v2.0.2  August 12, 2009, built with Autoit 3.2.1.+
;
;   Author: Valuater, Robert M
;
;   Update: by wraithdu
;
;   Contributions: marfdaman(Marvin), RazerM, Quaizywabbit(AnyGUI).
;
;   Email: <Valuater [at] aol [dot] com>
;
;   Use: Mouse/Hover Over Buttons with chamge picture events
;===============================================================================


#include-once
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>

Global $cHoverID[2], $cHoverTag[2], $Global_cHID = 0, $cHoverActive = 0, $cHClicked = 0, $XButton_Location, $XBType

;===============================================================================
;
; Function Name:    __ControlHover()
; Description:      Enable Mouse/Hover Over Control Events
;                   Find if Mouse is over a known control
;                   Find if a Mouse has Clicked on a known control
;                   Add, Remove, or Verify the control within the known control list
; Parameter(s):     $cH_Mode    [default]       0 = Find if Mouse is over a known control
;                               [optional]      1 = Find if a Mouse has Clicked on a known control
;                                               2 = Add a control to the known control list
;                                               3 = Remove a control from the known control list
;                                               4 = Verify a control is in the known control list
;                   $cH_hWin    [optional]      - Window handle as returned by GUICreate()
;                               [preferred]     - Window handle to save CPU usage and speed of _ControlHover()
;                                               - and Avoid array errors for "non-active window"
;                   $cH_hCntrl  [required]      - Control ID to Add, Remove, or Verify the control within the known control list
;                               [not used]      - to find if a mouse is over or has clicked on a known control
; Requirement(s):   #include<Array.au3>
; Return Value(s):
;                   $cH_Mode 0 or 1
;                               On Success  Return = 1      @error = 0, @extended = Current known control
;                               While Success Return = ""
;                               On Failure: Return = 0      @error = 1, @extended = Last known control
;                   $cH_Mode 2, 3, or 4
;                               On Success  Return = 1      @error = 0, @extended = Function's return line number
;                   All $cH_Mode's
;                               On Error:   Return = Description of the error
;                                                           @error = -1, @extended = Function's return line number
; Author(s):        Valuater, Robert M
;
;===============================================================================
Func __ControlHover($cH_Mode = 0, $cH_hWin = -1, $cH_hCntrl = -1, $cH_tag = "")

    Local $cH_i, $cH_Data
    If Not @Compiled Then Opt("TrayIconDebug", 1) ; 1=debug line info

    Switch $cH_Mode
        Case 0, 1 ; 0 = Check if mouse is over a control, 1 = Check if mouse clicked on a control

            ; Developer did not add any controls before the function mode 0 or 1 was called
            If UBound($cHoverID) = 2 Then
                ConsoleWrite("*** _ControlHover() Error *** " & @CRLF & "No Controls were Added" & @CRLF)
                Return
            EndIf

            If $cH_hWin = -1 Then
                $cH_Data = GUIGetCursorInfo() ; Get cursor data from the active window
            ElseIf Not WinActive($cH_hWin) Then
                Return SetError(-1, 1, -1) ; Dont waist CPU if the known window is not active
            Else
                $cH_Data = GUIGetCursorInfo($cH_hWin) ; Get cursor data from the known window
            EndIf

            If Not IsArray($cH_Data) Then Return SetError(-1, 2, -1) ; A readable GUI window was not found

            For $cH_i = 2 To UBound($cHoverID) - 1 ; Search the known controls for the currently hovered control
                If $cH_Data[4] = $cHoverID[$cH_i] Then ; Mouse is over a current known control
                    If BitAND(GUICtrlGetState($cHoverID[$cH_i]), $GUI_ENABLE) Then ; ===> check control is enabled
                        Switch $cH_Mode
                            Case 0
                                ; Mode 0 - check for hover a known control
                                If $cH_i = $cHoverID[$Global_cHID] And $cHoverActive Then Return SetError(-1, -1, -1) ; Mouse is still over last known control
                                If $cHoverActive Then
                                    $cHoverActive = 0
                                    Return SetError(1, $cHoverID[$Global_cHID], 0) ; Release Active - Mouse is over a new known control
                                EndIf
                                $cHoverActive = 1
                                $cHoverID[$Global_cHID] = $cH_i ; Re-set the current control to the new known control index
                                Return SetError(0, $cHoverID[$Global_cHID], 1) ; Mouse is over the new-current known control
                            Case 1
                                ; Mode 1 - check for a Click on a known control
                                If $cH_Data[2] = 1 And Not $cHClicked Then
                                    $cHClicked = 1
                                    Return SetError(0, $cHoverID[$Global_cHID], 1) ; Mouse clicked on current control
                                ElseIf $cH_Data[2] <> 1 And $cHClicked Then
                                    $cHClicked = 0
                                    Return SetError(1, $cHoverID[$Global_cHID], 0) ; Release clicked current control
                                EndIf
                                Return SetError(-1, -1, -1) ; Mouse is still over last known control and may click again
                        EndSwitch
                    EndIf ; ===> check control is enabled
                EndIf
            Next
            ; hover control not found in the known control list
            If $cHoverActive Then
                If $cH_Mode And $cHClicked Then  ; check - Release clicked current control
                    $cHClicked = 0
                    Return SetError(1, $cHoverID[$Global_cHID], 0) ; Release clicked current control
                ElseIf $cH_Mode Then
                    Return SetError(-1, -1, -1) ; Protect the release of the active control
                Else
                    $cHoverActive = 0
                    Return SetError(1, $cHoverID[$Global_cHID], 0) ; Release Active - Mouse is over a new unknown control
                EndIf
            ElseIf $cH_Mode And $cHClicked Then
                $cHClicked = 0
                Return SetError(1, $cHoverID[$Global_cHID], 0) ; Release clicked current control
            Else
                Return SetError(-1, -1, -1)
            EndIf

        Case 2 ; Add the new control to the known control list

            If $cH_hCntrl = -1 Then Return SetError(-1, 8, -1) ; The control ID was not given
            _ArrayAdd($cHoverID, $cH_hCntrl) ; Add the control to the known control array
            If @error Then Return SetError(-1, 9, -1) ; Control not added to the known control list
            _ArrayAdd($cHoverTag, $cH_tag)
            If @error Then Return SetError(-1, 10, -1)
            Return SetError(0, 11, 1) ; ; Control was added to the known control list

        Case 3 ; Remove the control from the known control list

            If $cH_hCntrl = -1 Then Return SetError(-1, 12, -1) ; The control ID was not given
            _ArrayDelete($cHoverID, $cH_hCntrl) ; Delete the control from the known control array list
            If @error Then Return SetError(-1, 13, -1) ; Control not deleted from the known control list
            _ArrayDelete($cHoverTag, $cH_hCntrl)
            If @error Then Return SetError(-1, 14, -1)
            Return SetError(0, 15, 1) ; Control was deleted from the known control list

        Case 4 ; Verify if control is in the known control list

            If $cH_hCntrl = -1 Then Return SetError(-1, 16, -1) ; The control ID was not given
            _ArraySearch($cHoverID, $cH_hCntrl) ; Search to verify if control is in the known control list
            If @error Then Return SetError(-1, 17, -1) ; Control was not found in the known control list
            Return SetError(0, 18, 1) ; Control was found in the known control list

        Case Else
            Return SetError(-1, 19, -1) ; $cH_Mode has an incorrect value
    EndSwitch
    Return SetError(-1, 20, -1) ; Error is Unknown
EndFunc   ;==>__ControlHover

Func __HoverButton($XBtext, $XBleft, $XBtop, $XBwidth, $XBheight, $XBtag = "", $XBcolor = "")
    If Not FileExists($XButton_Location & "\") Then
        MsgBox(64, "Error", " $XButton_Location - was not found    ", 3)
        Return
    EndIf
    If FileExists($XButton_Location & "\" & $XBtag & "Normal.gif") Then
        $XBType = ".gif"
    ElseIf FileExists($XButton_Location & "\" & $XBtag & "Normal.jpg") Then
        $XBType = ".jpg"
    ElseIf FileExists($XButton_Location & "\" & $XBtag & "Normal.bmp") Then
        $XBType = ".bmp"
    Else
        MsgBox(64, "Error", " Unknown Button file type ( not - gif, jpg, or bmp )    ", 3)
        Return
    EndIf
    Local $Xbtn[2]
    $Xbtn[0] = GUICtrlCreatePic($XButton_Location & "\" & $XBtag & "Normal" & $XBType, $XBleft, $XBtop, $XBwidth, $XBheight)
    $Xbtn[1] = GUICtrlCreateLabel($XBtext, $XBleft, $XBtop, $XBwidth, $XBheight, BitOR($SS_CENTERIMAGE, $SS_CENTER))
    If $XBcolor <> "" Then GUICtrlSetColor(-1, $XBcolor)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    __ControlHover(2, -1, $Xbtn[1], $XBtag)
    Return $Xbtn ; [0] = pic, [1] = label
EndFunc   ;==>__HoverButton

Func __HoverButtonSetState($Xbtn, $btn_state = $GUI_ENABLE)
    GUICtrlSetState($Xbtn[0], $btn_state)
    GUICtrlSetState($Xbtn[1], $btn_state)
EndFunc ;===>__HoverButtonSetState

Func __HoverButtonDelete($Xbtn)
    __ControlHover(3, -1, $Xbtn[1]) ;removes control from known control arrays
    GuiCtrlDelete($Xbtn[0])
    GuiCtrlDelete($Xbtn[1])
EndFunc   ;==>__HoverButtonDelete

Func __CheckHoverAndPressed($_GUI = -1)
;~  Local $tempID2, $state2 = __ControlHover(1, $_GUI)
;~  Local $tempIndex2 = @extended
;~  If $tempIndex2 <> -1 Then
;~      $tempID2 = $cHoverID[$tempIndex2]
;~      $tempTag2 = $cHoverTag[$tempIndex2]
;~      If $state2 = 1 Then
;~          GUICtrlSetImage($tempID2 - 1, $XButton_Location & "\" & $tempTag2 & "Press" & $XBType)
;~      ElseIf $state2 = 0 Then
;~          GUICtrlSetImage($tempID2 - 1, $XButton_Location & "\" & $tempTag2 & "Over" & $XBType)
;~      EndIf
;~  EndIf
    Local $tempID, $state = __ControlHover(0, $_GUI)
    Local $tempIndex = @extended
    If $tempIndex <> -1 Then
        $tempID = $cHoverID[$tempIndex]
        $tempTag = $cHoverTag[$tempIndex]
        If $state = 1 Then ; hovered
            GUICtrlSetImage($tempID - 1, $XButton_Location & "\" & $tempTag & "Over" & $XBType)
        ElseIf $state = 0 Then ; not hovered
            GUICtrlSetImage($tempID - 1, $XButton_Location & "\" & $tempTag & "Normal" & $XBType)
        EndIf
    EndIf
EndFunc   ;==>__CheckHoverAndPressed

Func __HoverWaitButtonUp($_GUI)
    Local $tempTag, $bPress = True
    ; set current control, just in case it wasn't hovered before, such as when the click activates the window
    If __ControlHover(0, $_GUI) And ($cHoverID[$Global_cHID] >= 2) Then ; last known control ID index, first one is 2
        Local $ret = GUIGetCursorInfo($_GUI)
        If IsArray($ret) And $ret[4] = $cHoverID[$cHoverID[$Global_cHID]] Then ; info is valid, and clicked the known control
            $tempTag = $cHoverTag[$cHoverID[$Global_cHID]] ; get tag from index
            GUICtrlSetImage($cHoverID[$cHoverID[$Global_cHID]] - 1, $XButton_Location & "\" & $tempTag & "Press" & $XBType)
            While 1
                While ($ret[4] = $cHoverID[$cHoverID[$Global_cHID]]) And ($ret[2] = 1) ; over control with button pressed
                    Sleep(10)
                    $ret = GUIGetCursorInfo($_GUI)
                WEnd
                If $ret[4] <> $cHoverID[$cHoverID[$Global_cHID]] Then ; moved off control
                    If $bPress Then _ ; set normal image
                        GUICtrlSetImage($cHoverID[$cHoverID[$Global_cHID]] - 1, $XButton_Location & "\" & $tempTag & "Over" & $XBType)
                    $bPress = False
                    If $ret[2] = 0 Then Return 1 ; if not over control and released button, return failure
                ElseIf $ret[2] = 0 Then
                    ExitLoop ; released button over control, success
                EndIf
                $ret = GUIGetCursorInfo($_GUI)
                If $ret[4] = $cHoverID[$cHoverID[$Global_cHID]] Then ; mouse back over control, reset pressed image
                    GUICtrlSetImage($cHoverID[$cHoverID[$Global_cHID]] - 1, $XButton_Location & "\" & $tempTag & "Press" & $XBType)
                    $bPress = True
                EndIf
                Sleep(10) ; throttle CPU
            WEnd
        EndIf
    EndIf
    GUICtrlSetImage($cHoverID[$cHoverID[$Global_cHID]] - 1, $XButton_Location & "\" & $tempTag & "Normal" & $XBType)
    Return 0 ; success
EndFunc ;===> __HoverWaitButtonUp
#endregion
Link to comment
Share on other sites

  • 3 weeks later...

For some reason if I want to display a PNG image with the following code on a page where I use ButtonHover, ButtonHover thinks the PNG control is a HoverButton and draws a NORMAL.BMP over it.

Any idea why this is the case and how to fix it?

$PIC_info = GUICtrlCreatePic("", $mX1 + $tvW + (3 * $tvS) + 370, $mY1 + 300, 32, 32)
    _SetImage($PIC_info, $PNG_info)
Link to comment
Share on other sites

I'd love to, but it's been 4 days...

I'm pretty sure I fixed this bug in my latest posted version. Unless he/she can produce a sample to illustrate this with my current revision, I say publish it. It has some improvements that are way better than my previous release.

Edited by wraithdu
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...