Jump to content
Sign in to follow this  
Mungo

Simple button and icon toolbar with hover effect - problem

Recommended Posts

Mungo

I tried to come up with a simple toolbar which displays the plain icons (without a button frame) but also shows a button effect when hovered or clicked on.

My approach was to create a button, add an icon and hide the icon button again. Then place the icon without the button on top of it. When the mouse is moved over the icon I hide the icon (which leaves button displayed) giving me the hover effect for hover and clicks (using GUIGetCursorInfo() to get the icon ID).

It seem to work ... but sometimes the hover effect does not show as expected especially when the mouse is moved slowly to the edge of the icon. While the icon ID is being read and action triggered (see Mouse OVER text) the icon itself is not being hidden (and button displayed).

I found that the effect is more likely to occur when the GUI is freshly loaded.

Can anyone reproduce this effect? I wonder what may causes this effect or is anything wrong in my coding?

Any hint and support would be appreciated!

Many thanks

#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

f_toolbar()

Func f_toolbar()
    Local $id_button_1_a, $id_button_2_a, $id_button_3_a
    Local $id_button_1_b, $id_button_2_b, $id_button_3_b
    Local $id_button_close
    Local $h_toolbar_gui, $msg_pop, $id_output_lbl

    ; -- Declare and set mouse over variables
    Local $last_tool_b_id = 0       ; ID of last button/icon visited
    Local $a_cursor_b_info          ; GUIGetCursorInfo() array

    Local $win_w = 400              ; GUI width
    Local $win_h = 400              ; GUI height
    Local $icon_file = @SystemDir & "\shell32.dll"

    ; -- Create the GUI -------------------------------------------------------------------------------------------------------
    $h_toolbar_gui = GUICreate("Toolbar hover - Test ...", $win_w, $win_h)

    ; -- A frame for the toolbar
    GUICtrlCreateLabel("", 3, 3, $win_w-3, 44, $SS_ETCHEDFRAME )
    GUICtrlSetState(-1, $GUI_DISABLE)

    ; -- The Toolbar
    ; -- 1. Toolbar button -----------------------------------------------------------------------------------------------------
    $id_button_1_a = GUICtrlCreateButton("1", 4, 4, 40, 40, $BS_ICON)                                                           ; Create BUTTON
    GUICtrlSetImage(-1, $icon_file, -71, 1)                                                                                     ; Add ICON to button
    GUICtrlSetState(-1, $GUI_HIDE)                                                                                              ; Hide ICON BUTTON again
    $id_button_1_b = GUICtrlCreateIcon($icon_file, -71, 4, 4, 40, 40, $BS_CENTER)                                               ; Create ICON to display

    ; -- 2. Toolbar button -----------------------------------------------------------------------------------------------------
    $id_button_2_a = GUICtrlCreateButton("2", 44, 4, 40, 40, $BS_ICON)                                                          ; Create BUTTON
    GUICtrlSetImage(-1, $icon_file, -5, 1)                                                                                      ; Add ICON to button
    GUICtrlSetState(-1, $GUI_HIDE)                                                                                              ; Hide ICON BUTTON again
    $id_button_2_b = GUICtrlCreateIcon($icon_file, -5, 44, 4, 40, 40, $BS_CENTER)                                               ; Create ICON to display

    ; -- 3. Toolbar button -----------------------------------------------------------------------------------------------------
    $id_button_3_a = GUICtrlCreateButton("3", 84, 4, 40, 40, $BS_ICON)
    GUICtrlSetImage(-1, $icon_file, -28, 1)                                                                                     ; Add ICON to button
    GUICtrlSetState(-1, $GUI_HIDE)                                                                                              ; Hide ICON BUTTON again
    $id_button_3_b = GUICtrlCreateIcon($icon_file, -28, 84, 4, 40, 40, $BS_CENTER)                                              ; Create ICON to display

    ; -- Lable CTRL for feedback
    $id_output_lbl = GUICtrlCreateLabel("Move mouse over toolbar ...", 4, 100, $win_w-8, 16)                                    ; Lable for feedback
    GUICtrlSetBkColor($id_output_lbl, 0xFFFFFF)

    ; -- The Close button
    $id_button_close = GUICtrlCreateButton("Close", $win_w/2-40, $win_h-40, 80, 24, $BS_DEFPUSHBUTTON)

    GUISetState(@SW_SHOW)

    While 1
        $msg_pop = GUIGetMsg()
        Select
            Case $msg_pop = $GUI_EVENT_CLOSE
                ExitLoop

            Case $msg_pop = $id_button_close
                ExitLoop

            Case $msg_pop = $id_button_1_a Or $msg_pop = $id_button_1_b
                GUICtrlSetState($id_button_1_a, $GUI_SHOW)                                                                      ; Show BUTTON
                MsgBox(32, "DEBUG", "Button 1 pressed ...", 0, $h_toolbar_gui)

            Case $msg_pop = $id_button_2_a Or $msg_pop = $id_button_2_b
                GUICtrlSetState($id_button_2_a, $GUI_SHOW)                                                                      ; Show BUTTON
                MsgBox(32, "DEBUG", "Button 2 pressed ...", 0, $h_toolbar_gui)

            Case $msg_pop = $id_button_3_a Or $msg_pop = $id_button_3_b
                GUICtrlSetState($id_button_3_a, $GUI_SHOW)                                                                      ; Show BUTTON
                MsgBox(32, "DEBUG", "Button 3 pressed ...", 0, $h_toolbar_gui)

            Case Else
                $a_cursor_b_info = GUIGetCursorInfo($h_toolbar_gui)  ; - $aArray[4] = ID of the control that the mouse cursor is hovering over (or 0 if none)

                Select
                    ; -- Button 1 - Cursor -------------------------------------------------------------------------------------
                    Case  $a_cursor_b_info[4] = $id_button_1_b And $last_tool_b_id <> $id_button_1_b And $last_tool_b_id = 0    ; MOUSE OVER
                        GUICtrlSetState($id_button_1_a, $GUI_SHOW)                                                              ; Show BUTTON
                        GUICtrlSetData($id_output_lbl, "Mouse OVER - Ctrl ID:" & @TAB & $a_cursor_b_info[4])
                        GUICtrlSetBkColor($id_output_lbl, 0xFFFF00)
                        $last_tool_b_id = $id_button_1_b
                        ; -- DEBUG -----------------------------------------------------------------
                         ConsoleWrite("> ... " &  "$last_tool_b_id - Ctrl ID:" & @TAB & $last_tool_b_id & @CRLF)
                        ; -- DEBUG -----------------------------------------------------------------

                    Case $a_cursor_b_info[4] <> $id_button_1_b And $last_tool_b_id = $id_button_1_b                             ; NO MOUSE OVER
                        GUICtrlSetState($id_button_1_a, $GUI_HIDE)                                                              ; Hide BUTTON
                        $a_cursor_b_info[4] = 0
                        GUICtrlSetData($id_output_lbl, "Mouse AWAY - Ctrl ID:" & @TAB & $a_cursor_b_info[4])
                        GUICtrlSetBkColor($id_output_lbl,  0x99CCFF)
                        $last_tool_b_id = 0
                        ; -- DEBUG -----------------------------------------------------------------
                         ConsoleWrite("> ... " &  "$last_tool_b_id - Ctrl ID:" & @TAB & $last_tool_b_id & @CRLF)
                        ; -- DEBUG -----------------------------------------------------------------

                    ; -- Button 2 - Cursor -------------------------------------------------------------------------------------
                    Case  $a_cursor_b_info[4] = $id_button_2_b And $last_tool_b_id <> $id_button_2_b And $last_tool_b_id = 0    ; MOUSE OVER
                        GUICtrlSetState($id_button_2_a, $GUI_SHOW)                                                              ; Show BUTTON
                        GUICtrlSetData($id_output_lbl, "Mouse OVER - Ctrl ID:" & @TAB & $a_cursor_b_info[4])
                        GUICtrlSetBkColor($id_output_lbl, 0xFFFF00)
                        $last_tool_b_id = $id_button_2_b
                        ; -- DEBUG -----------------------------------------------------------------
                         ConsoleWrite("> ... " &  "$last_tool_b_id - Ctrl ID:" & @TAB & $last_tool_b_id & @CRLF)
                        ; -- DEBUG -----------------------------------------------------------------

                    Case $a_cursor_b_info[4] <> $id_button_2_b And $last_tool_b_id = $id_button_2_b                             ; NO MOUSE OVER
                        GUICtrlSetState($id_button_2_a, $GUI_HIDE)                                                              ; Hide BUTTON
                        $a_cursor_b_info[4] = 0
                        GUICtrlSetData($id_output_lbl, "Mouse AWAY - Ctrl ID:" & @TAB & $a_cursor_b_info[4])
                        GUICtrlSetBkColor($id_output_lbl,  0x99CCFF)
                        $last_tool_b_id = 0
                        ; -- DEBUG -----------------------------------------------------------------
                         ConsoleWrite("> ... " &  "$last_tool_b_id - Ctrl ID:" & @TAB & $last_tool_b_id & @CRLF)
                        ; -- DEBUG -----------------------------------------------------------------

                    ; -- Button 3 - Cursor -------------------------------------------------------------------------------------
                    Case  $a_cursor_b_info[4] = $id_button_3_b And $last_tool_b_id <> $id_button_3_b And $last_tool_b_id = 0    ; MOUSE OVER
                        GUICtrlSetState($id_button_3_a, $GUI_SHOW)                                                              ; Show BUTTON
                        GUICtrlSetData($id_output_lbl, "Mouse OVER - Ctrl ID:" & @TAB & $a_cursor_b_info[4])
                        GUICtrlSetBkColor($id_output_lbl, 0xFFFF00)
                        $last_tool_b_id = $id_button_3_b
                        ; -- DEBUG -----------------------------------------------------------------
                         ConsoleWrite("> ... " &  "$last_tool_b_id - Ctrl ID:" & @TAB & $last_tool_b_id & @CRLF)
                        ; -- DEBUG -----------------------------------------------------------------

                    Case $a_cursor_b_info[4] <> $id_button_3_b And $last_tool_b_id = $id_button_3_b                             ; NO MOUSE OVER
                        GUICtrlSetState($id_button_3_a, $GUI_HIDE)                                                              ; Hide BUTTON
                        $a_cursor_b_info[4] = 0
                        GUICtrlSetData($id_output_lbl, "Mouse AWAY - Ctrl ID:" & @TAB & $a_cursor_b_info[4])
                        GUICtrlSetBkColor($id_output_lbl,  0x99CCFF)
                        $last_tool_b_id = 0
                        ; -- DEBUG -----------------------------------------------------------------
                         ConsoleWrite("> ... " &  "$last_tool_b_id - Ctrl ID:" & @TAB & $last_tool_b_id & @CRLF)
                        ; -- DEBUG -----------------------------------------------------------------

                EndSelect
        EndSelect
    WEnd

    GUIDelete()
EndFunc   ;==> f_toolbar()
Edited by Mungo

Share this post


Link to post
Share on other sites
Yashied
Mungo

Thanks Yashied,

Yes, I try to get my head around the powerful _GUICtrlToolbar_... and _GUICtrlRebar_...  functions ... However, still try to understand why my example behaves the way it does ... icon not hiding despite action triggered ?

Well, I try keep learning all the time.  :sweating:

Cheers :shifty:

Share this post


Link to post
Share on other sites
Yashied

The problem in overlapping controls.

 

#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

f_toolbar()

Func f_toolbar()
    Local $id_button_1_a, $id_button_2_a, $id_button_3_a
    Local $id_button_1_b, $id_button_2_b, $id_button_3_b
    Local $id_button_close
    Local $h_toolbar_gui, $msg_pop, $id_output_lbl

    ; -- Declare and set mouse over variables
    Local $last_tool_b_id = 0       ; ID of last button/icon visited
    Local $a_cursor_b_info          ; GUIGetCursorInfo() array

    Local $win_w = 400              ; GUI width
    Local $win_h = 400              ; GUI height
    Local $icon_file = @SystemDir & "\shell32.dll"

    ; -- Create the GUI -------------------------------------------------------------------------------------------------------
    $h_toolbar_gui = GUICreate("Toolbar hover - Test ...", $win_w, $win_h)

    ; -- A frame for the toolbar
    GUICtrlCreateLabel("", 3, 3, $win_w-3, 44, $SS_ETCHEDFRAME )
    GUICtrlSetState(-1, $GUI_DISABLE)

    ; -- The Toolbar
    ; -- 1. Toolbar button -----------------------------------------------------------------------------------------------------
    $id_button_1_a = GUICtrlCreateButton("1", 4, 4, 40, 40, $BS_ICON)                                                           ; Create BUTTON
    GUICtrlSetImage(-1, $icon_file, -71, 1)                                                                                     ; Add ICON to button
    GUICtrlSetState(-1, $GUI_HIDE)                                                                                              ; Hide ICON BUTTON again
    $id_button_1_b = GUICtrlCreateIcon($icon_file, -71, 4, 4, 40, 40, $BS_CENTER)                                               ; Create ICON to display

    ; -- 2. Toolbar button -----------------------------------------------------------------------------------------------------
    $id_button_2_a = GUICtrlCreateButton("2", 44, 4, 40, 40, $BS_ICON)                                                          ; Create BUTTON
    GUICtrlSetImage(-1, $icon_file, -5, 1)                                                                                      ; Add ICON to button
    GUICtrlSetState(-1, $GUI_HIDE)                                                                                              ; Hide ICON BUTTON again
    $id_button_2_b = GUICtrlCreateIcon($icon_file, -5, 44, 4, 40, 40, $BS_CENTER)                                               ; Create ICON to display

    ; -- 3. Toolbar button -----------------------------------------------------------------------------------------------------
    $id_button_3_a = GUICtrlCreateButton("3", 84, 4, 40, 40, $BS_ICON)
    GUICtrlSetImage(-1, $icon_file, -28, 1)                                                                                     ; Add ICON to button
    GUICtrlSetState(-1, $GUI_HIDE)                                                                                              ; Hide ICON BUTTON again
    $id_button_3_b = GUICtrlCreateIcon($icon_file, -28, 84, 4, 40, 40, $BS_CENTER)                                              ; Create ICON to display

    ; -- Lable CTRL for feedback
    $id_output_lbl = GUICtrlCreateLabel("Move mouse over toolbar ...", 4, 100, $win_w-8, 16)                                    ; Lable for feedback
    GUICtrlSetBkColor($id_output_lbl, 0xFFFFFF)

    ; -- The Close button
    $id_button_close = GUICtrlCreateButton("Close", $win_w/2-40, $win_h-40, 80, 24, $BS_DEFPUSHBUTTON)

    GUISetState(@SW_SHOW)

    While 1
        $msg_pop = GUIGetMsg()
        Select
            Case $msg_pop = $GUI_EVENT_CLOSE
                ExitLoop

            Case $msg_pop = $id_button_close
                ExitLoop

            Case $msg_pop = $id_button_1_a Or $msg_pop = $id_button_1_b
                GUICtrlSetState($id_button_1_a, $GUI_SHOW)
                MsgBox(32, "DEBUG", "Button 1 pressed ...", 0, $h_toolbar_gui)

            Case $msg_pop = $id_button_2_a Or $msg_pop = $id_button_2_b
                GUICtrlSetState($id_button_2_a, $GUI_SHOW)
                MsgBox(32, "DEBUG", "Button 2 pressed ...", 0, $h_toolbar_gui)

            Case $msg_pop = $id_button_3_a Or $msg_pop = $id_button_3_b
                GUICtrlSetState($id_button_3_a, $GUI_SHOW)
                MsgBox(32, "DEBUG", "Button 3 pressed ...", 0, $h_toolbar_gui)

            Case Else
                $a_cursor_b_info = GUIGetCursorInfo($h_toolbar_gui)  ; - $aArray[4] = ID of the control that the mouse cursor is hovering over (or 0 if none)

                Select
                    ; -- Button 1 - Cursor -------------------------------------------------------------------------------------
                    Case  $a_cursor_b_info[4] = $id_button_1_b And $last_tool_b_id = 0                                          ; MOUSE OVER
                        GUICtrlSetState($id_button_1_a, $GUI_SHOW)
                        GUICtrlSetState($id_button_1_b, $GUI_HIDE)
                        GUICtrlSetData($id_output_lbl, "Mouse OVER - Ctrl ID:" & @TAB & $a_cursor_b_info[4])
                        GUICtrlSetBkColor($id_output_lbl, 0xFFFF00)
                        _Swap($id_button_1_a, $id_button_1_b)
                        $last_tool_b_id = $id_button_1_b
                        ; -- DEBUG -----------------------------------------------------------------
                         ConsoleWrite("> ... " &  "$last_tool_b_id - Ctrl ID:" & @TAB & $last_tool_b_id & @CRLF)
                        ; -- DEBUG -----------------------------------------------------------------

                    Case $a_cursor_b_info[4] <> $id_button_1_b And $last_tool_b_id = $id_button_1_b                             ; NO MOUSE OVER
                        GUICtrlSetState($id_button_1_a, $GUI_SHOW)
                        GUICtrlSetState($id_button_1_b, $GUI_HIDE)
                        $a_cursor_b_info[4] = 0
                        GUICtrlSetData($id_output_lbl, "Mouse AWAY - Ctrl ID:" & @TAB & $a_cursor_b_info[4])
                        GUICtrlSetBkColor($id_output_lbl,  0x99CCFF)
                        _Swap($id_button_1_a, $id_button_1_b)
                        $last_tool_b_id = 0
                        ; -- DEBUG -----------------------------------------------------------------
                         ConsoleWrite("> ... " &  "$last_tool_b_id - Ctrl ID:" & @TAB & $last_tool_b_id & @CRLF)
                        ; -- DEBUG -----------------------------------------------------------------

                    ; -- Button 2 - Cursor -------------------------------------------------------------------------------------
                    Case  $a_cursor_b_info[4] = $id_button_2_b And $last_tool_b_id = 0                                          ; MOUSE OVER
                        GUICtrlSetState($id_button_2_a, $GUI_SHOW)
                        GUICtrlSetState($id_button_2_b, $GUI_HIDE)
                        GUICtrlSetData($id_output_lbl, "Mouse OVER - Ctrl ID:" & @TAB & $a_cursor_b_info[4])
                        GUICtrlSetBkColor($id_output_lbl, 0xFFFF00)
                        _Swap($id_button_2_a, $id_button_2_b)
                        $last_tool_b_id = $id_button_2_b
                        ; -- DEBUG -----------------------------------------------------------------
                         ConsoleWrite("> ... " &  "$last_tool_b_id - Ctrl ID:" & @TAB & $last_tool_b_id & @CRLF)
                        ; -- DEBUG -----------------------------------------------------------------

                    Case $a_cursor_b_info[4] <> $id_button_2_b And $last_tool_b_id = $id_button_2_b                             ; NO MOUSE OVER
                        GUICtrlSetState($id_button_2_a, $GUI_SHOW)
                        GUICtrlSetState($id_button_2_b, $GUI_HIDE)
                        $a_cursor_b_info[4] = 0
                        GUICtrlSetData($id_output_lbl, "Mouse AWAY - Ctrl ID:" & @TAB & $a_cursor_b_info[4])
                        GUICtrlSetBkColor($id_output_lbl,  0x99CCFF)
                        _Swap($id_button_2_a, $id_button_2_b)
                        $last_tool_b_id = 0
                        ; -- DEBUG -----------------------------------------------------------------
                         ConsoleWrite("> ... " &  "$last_tool_b_id - Ctrl ID:" & @TAB & $last_tool_b_id & @CRLF)
                        ; -- DEBUG -----------------------------------------------------------------

                    ; -- Button 3 - Cursor -------------------------------------------------------------------------------------
                    Case  $a_cursor_b_info[4] = $id_button_3_b And $last_tool_b_id = 0                                          ; MOUSE OVER
                        GUICtrlSetState($id_button_3_a, $GUI_SHOW)
                        GUICtrlSetState($id_button_3_b, $GUI_HIDE)
                        GUICtrlSetData($id_output_lbl, "Mouse OVER - Ctrl ID:" & @TAB & $a_cursor_b_info[4])
                        GUICtrlSetBkColor($id_output_lbl, 0xFFFF00)
                        _Swap($id_button_3_a, $id_button_3_b)
                        $last_tool_b_id = $id_button_3_b
                        ; -- DEBUG -----------------------------------------------------------------
                         ConsoleWrite("> ... " &  "$last_tool_b_id - Ctrl ID:" & @TAB & $last_tool_b_id & @CRLF)
                        ; -- DEBUG -----------------------------------------------------------------

                    Case $a_cursor_b_info[4] <> $id_button_3_b And $last_tool_b_id = $id_button_3_b                             ; NO MOUSE OVER
                        GUICtrlSetState($id_button_3_a, $GUI_SHOW)
                        GUICtrlSetState($id_button_3_b, $GUI_HIDE)
                        $a_cursor_b_info[4] = 0
                        GUICtrlSetData($id_output_lbl, "Mouse AWAY - Ctrl ID:" & @TAB & $a_cursor_b_info[4])
                        GUICtrlSetBkColor($id_output_lbl,  0x99CCFF)
                        _Swap($id_button_3_a, $id_button_3_b)
                        $last_tool_b_id = 0
                        ; -- DEBUG -----------------------------------------------------------------
                         ConsoleWrite("> ... " &  "$last_tool_b_id - Ctrl ID:" & @TAB & $last_tool_b_id & @CRLF)
                        ; -- DEBUG -----------------------------------------------------------------

                EndSelect
        EndSelect
    WEnd

    GUIDelete()
EndFunc   ;==> f_toolbar()

Func _Swap(ByRef $iNum1, ByRef $iNum2)
    Local $Temp = $iNum1
    $iNum1 = $iNum2
    $iNum2 = $Temp
EndFunc   ;==>_Swap

Here is a complete example of using Toolbar control.

 

#Include <GUIConstantsEx.au3>
#Include <GUIImageList.au3>
#Include <GUIToolbar.au3>
#Include <StaticConstants.au3>
#Include <ToolbarConstants.au3>
#Include <WindowsConstants.au3>
#Include <WinAPIEx.au3>

$hForm = GUICreate('MyGUI', 332, 332)

$hTool = GUICreate('', 332, 64, 0, 0, $WS_CHILD, 0, $hForm)
$Dummy = GUICtrlCreateDummy()

$hToolbar = _GUICtrlToolbar_Create($hTool, BitOR($BTNS_BUTTON, $BTNS_SHOWTEXT, $TBSTYLE_FLAT, $TBSTYLE_TOOLTIPS), $TBSTYLE_EX_DOUBLEBUFFER)

$hImageList = _GUIImageList_Create(32, 32, 5, 1, 5)
Dim $Icon[5] = [19, 205, 298, 300, 304]
For $i = 0 To 4
    $hIcon = _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', $Icon[$i], 32, 32)
    _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon)
    _WinAPI_DestroyIcon($hIcon)
Next

_GUICtrlToolbar_SetImageList($hToolbar, $hImageList)

_GUICtrlToolbar_AddString($hToolbar, 'Button 1')
_GUICtrlToolbar_AddString($hToolbar, 'Button 2')
_GUICtrlToolbar_AddString($hToolbar, 'Button 3')
_GUICtrlToolbar_AddString($hToolbar, 'Button 4')
_GUICtrlToolbar_AddString($hToolbar, 'Button 5')

_GUICtrlToolbar_AddButton($hToolbar, 10000, 0, 0)
_GUICtrlToolbar_AddButton($hToolbar, 10001, 1, 1)
_GUICtrlToolbar_AddButtonSep($hToolbar, 5)
_GUICtrlToolbar_AddButton($hToolbar, 10002, 2, 2)
_GUICtrlToolbar_AddButton($hToolbar, 10003, 3, 3)
_GUICtrlToolbar_AddButton($hToolbar, 10004, 4, 4)

_GUICtrlToolbar_SetButtonSize($hToolbar, 64, 64)
_GUICtrlToolbar_SetMetrics($hToolbar, 0, 0, 1, 0)
_GUICtrlToolbar_SetIndent($hToolbar, 1)

_SendMessage($hToolbar, $TB_AUTOSIZE)

GUISwitch($hForm)

; Main GUI controls...

GUICtrlCreateLabel('', 0, 64, 335, 2, $SS_ETCHEDHORZ)

GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')

GUISetState(@SW_SHOWNOACTIVATE, $hTool)
GUISetState(@SW_SHOW, $hForm)

While 1
    Switch GUIGetMsg()
        Case 0
            ContinueLoop
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Dummy
            $ID = GUICtrlRead($Dummy)
            Switch $ID
                Case 10000 ; Button 1
                    MsgBox(64, 'Toolbar', 'Button 1 has been pressed!', 0, $hForm)
                Case 10001 ; Button 2
                    MsgBox(64, 'Toolbar', 'Button 2 has been pressed!', 0, $hForm)
                Case 10002 ; Button 3
                    MsgBox(64, 'Toolbar', 'Button 3 has been pressed!', 0, $hForm)
                Case 10003 ; Button 4
                    MsgBox(64, 'Toolbar', 'Button 4 has been pressed!', 0, $hForm)
                Case 10004 ; Button 5
                    MsgBox(64, 'Toolbar', 'Button 5 has been pressed!', 0, $hForm)
                Case Else

            EndSwitch
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    Local $ID = BitAND($wParam, 0xFFFF)

    Switch $hWnd
        Case $hTool
            Switch $ID
                Case 10000 To 10004 ; Button 1 - Button 5
                    GUICtrlSendToDummy($Dummy, $ID)
                Case Else

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    Local $tNMIA = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $hTarget = DllStructGetData($tNMIA, 'hWndFrom')
    Local $ID = DllStructGetData($tNMIA, 'Code')

    Switch $hWnd
        Case $hTool
            Switch $hTarget
                Case $hToolbar
                    Switch $ID
                        Case $TBN_GETINFOTIPW

;~                          Local $tNMTBGIT = DllStructCreate($tagNMTBGETINFOTIP, $lParam)
                            Local $tNMTBGIT = DllStructCreate($tagNMHDR & ';ptr Text;int TextMax;int Item;lparam lParam;', $lParam)
                            Local $Item = DllStructGetData($tNMTBGIT, 'Item')
                            Local $Text = ''

                            Switch $Item
                                Case 10000 ; Button 1
                                    $Text = 'Tooltip 1'
                                Case 10001 ; Button 2
                                    $Text = 'Tooltip 2'
                                Case 10002 ; Button 3
                                    $Text = 'Tooltip 3'
                                Case 10003 ; Button 4
                                    $Text = 'Tooltip 4'
                                Case 10004 ; Button 5
                                    $Text = 'Tooltip 5'
                                Case Else

                            EndSwitch
                            If $Text Then
                                DllStructSetData(DllStructCreate('wchar[' & DllStructGetData($tNMTBGIT, 'TextMax') & ']', DllStructGetData($tNMTBGIT, 'Text')), 1, $Text)
                            EndIf
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

In addition, you can use my Skin UDF.

 

#Include <GDIPlus.au3>
#Include <GUIConstantsEx.au3>
#Include <Skin.au3>

_GDIPlus_Startup()

$hForm = GUICreate('MyGUI', 401, 160)
GUISetBkColor(0xF0F0F0)
$Button1 = _Skin_AddButton(12, 119, 29, 29, _LoadBitmap('down_normal.bmp'), _LoadBitmap('down_over.bmp'), _LoadBitmap('down_push.bmp'))
$Button2 = _Skin_AddButton(46, 119, 29, 29, _LoadBitmap('up_normal.bmp'), _LoadBitmap('up_over.bmp'), _LoadBitmap('up_push.bmp'))
$Button3 = _Skin_AddButton(87, 124, 29, 29, _LoadBitmap('down_normal_small.bmp'), _LoadBitmap('down_over_small.bmp'), _LoadBitmap('down_push_small.bmp'))
$Button4 = _Skin_AddButton(111, 124, 29, 29, _LoadBitmap('up_normal_small.bmp'), _LoadBitmap('up_over_small.bmp'), _LoadBitmap('up_push_small.bmp'))
$Button5 = _Skin_AddButton(323, 14, 64, 64, _LoadBitmap('cd_normal.bmp'), _LoadBitmap('cd_over_push.bmp'), _LoadBitmap('cd_over_push.bmp'))
GUISetState()

While 1
    _Skin_Helper($hForm)
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button1
            ConsoleWrite('#1' & @CR)
        Case $Button2
            ConsoleWrite('#2' & @CR)
        Case $Button3
            ConsoleWrite('#3' & @CR)
        Case $Button4
            ConsoleWrite('#4' & @CR)
        Case $Button5
            ConsoleWrite('#5' & @CR)
    EndSwitch
WEnd

GUIDelete()

_Skin_Destroy()

Func _LoadBitmap($sPath)

    Local $hBitmap, $hImage

    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile($sPath)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    Return $hBitmap
EndFunc   ;==>_LoadBitmap
  • Like 3

Share this post


Link to post
Share on other sites
SmOke_N

 

In addition, you can use my Skin UDF.

 

 

Nicely done


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Mungo

Yashied,

Thanks for the hint and addition to my coding - fixed the problem and learned and understood something new again ;)

Great examples for both the GuiToolbar as well as Skin UDFs. I probably will use both of them in different areas of my project.

I already started to work through the GuiToolbar examples before but had problems piecing things together and got stuck. However, with getting your examples I gave it another shot and it looks much more promising now.

Your example is nice and complete and it is much easier for me to comprehend now how it works (thumbs UP !). I just started and I am still working on it - and some questions undoubtedly will still arise  :graduated:

Cheers

Edited by Mungo

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      First, I want to apologize with you for the title not very clear, but I thought a little bit on which title to set at the thread, and this is the one that came in mind.
      Now, let me explain what I'm trying to understand.

      I am making an application ( with n clients ), with an SQLite Database, which has a Main form, and n sub-forms... 
      Since these sub-forms are called several times, because they are used to add or update records to the Database, I put the code that generates the GUI of these sub-forms in Functions.
      There are two sub-forms which are "treated" as two main forms, since even them have n sub-forms, which perform various tasks.
      Where am I stucked?

      For the Main form I created a Status Bar, in order to display messages ( add/delete/update/search results ), and it works perfectly with all the forms which don't have other sub-forms.
      For the two forms, which indeed have n sub-forms, I created two separated Status Bars, which are (re)created everytime I call the function that then displays the form.
      Practically, I can't set icons to these two Status Bars, and I don't know why.
      I'm really sorry that I don't feel clear enough, so, here you are an example of what I am saying.
      I recreated exactly what my script does:
      #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $frmSubForm, _ $txtSubFormField, _ $sbSubFormStatusBar, _ $objSB_IconError = _WinAPI_LoadShell32Icon(109), _ $objSB_IconInformation = _WinAPI_LoadShell32Icon(277) #Region ### START Koda GUI section ### Form= $frmMainForm = GUICreate("Main Form", 300, 300, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") $sbMainStatusBar = _GUICtrlStatusBar_Create($frmMainForm) $btnCreateSubForm = GUICtrlCreateButton("Create Sub Form", 105, 110, 75, 41, BitOR($BS_CENTER,$BS_VCENTER,$BS_MULTILINE)) GUICtrlSetOnEvent(-1, "GenerateSubForm") GUICtrlSetFont(-1, 10, 400, 0, "Arial") _GUICtrlStatusBar_SetSimple($sbMainStatusBar) _GUICtrlStatusBar_SetText($sbMainStatusBar, "") GUISetState(@SW_SHOW, $frmMainForm) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func ExitApplication() Exit EndFunc Func GenerateSubForm() #Region ### START Koda GUI section ### Form= $frmSubForm = GUICreate("Sub-Form", 300, 300, -1, -1, -1, -1, $frmMainForm) GUISetOnEvent($GUI_EVENT_CLOSE, "DeleteSubForm") $txtSubFormField = GUICtrlCreateInput("", 0, 0, 100, 20) $btnCheckSubFormField = GUICtrlCreateButton("Check Field", 105, 110, 75, 41, BitOR($BS_CENTER,$BS_VCENTER,$BS_MULTILINE)) GUICtrlSetOnEvent(-1, "CheckSubFormField") GUICtrlSetFont(-1, 10, 400, 0, "Arial") $sbSubFormStatusBar = _GUICtrlStatusBar_Create($frmSubForm) _GUICtrlStatusBar_SetSimple($sbSubFormStatusBar) _GUICtrlStatusBar_SetText($sbSubFormStatusBar, "") GUISetState(@SW_SHOW, $frmSubForm) GUISetState(@SW_DISABLE, $frmMainForm) #EndRegion ### END Koda GUI section ### EndFunc Func DeleteSubForm() ; Declared Globally => $frmSubForm GUIDelete($frmSubForm) GUISetState(@SW_ENABLE, $frmMainForm) EndFunc Func WriteToStatusBar($sbStatusBar, $objSB_Icon, $strText) _GUICtrlStatusBar_SetIcon($sbStatusBar, 0, $objSB_Icon) _GUICtrlStatusBar_SetText($sbStatusBar, $strText) ConsoleWrite("Icon Handle: " & $objSB_Icon & @CRLF) EndFunc Func CheckSubFormField() ; Declared Globally => $txtSubFormField If GUICtrlRead($txtSubFormField) = "" Then ; Declared Globally => $sbStatusBar WriteToStatusBar($sbSubFormStatusBar, $objSB_IconError, "Field NOK.") Else WriteToStatusBar($sbSubFormStatusBar, $objSB_IconInformation, "Field OK.") EndIf EndFunc The text is set, but icon is not.
      Could someone please tell me why?
      Thanks everyone in advance  

      Best Regards.
    • Pike
      By Pike
      Hello Everyone,
      New Guy here. This is a two-part question, hopefully easy enough though. I know it's ugly coding, this is because I have only a couple hours worth of coding experience and could really use some help.
      1) When I single click the button I want one action (like playing a sound clip) and when I double click the button I want a different action (such as opening dialogue box to ask for soundclip directory address). At the bottom of the script I made a comment which one I would like single click versus double click.
      2) I can not get the FileOpenDialogue to save the file address to the config.ini file at the 'One' position on the .ini.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <AutoItConstants.au3> #include <Sound.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Global $OneID _Main() Func _Main() GUICreate("Form1", 156, 86, 281, 276) $OneID = GUICtrlCreateButton("Button", 15, 17, 122, 37) GUICtrlSetOnEvent($OneID, "OnOne") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState() While 1 While 1 Sleep(1000) WEnd WEnd EndFunc ;---------------Functions------------- While 1 Sleep(100) WEnd Func OnOne() ; ******************Single Click for this action**************** $OneID = IniRead("config.ini", "Config", "One", $OneID) If $OneID = True Then SoundPlay($OneID, @HotKeyPressed) Else ; *******Double Click for this action*****And Help Saving File Address to config.ini 'One'*********** $OneID = FileOpenDialog("Select file", @WorkingDir, "All (*.*)") IniWrite("config.ini", "Config", "One", $OneID) $OneID = InputBox("Enter Information", "Short Name for File?", "") IniWrite("config.ini", "Config", "NameOne", $OneID) EndIf EndFunc Any help would be greatly appreciated, and if you need anymore clarity as to what exactly I'm trying to do, please do not hesitate to ask. Thanks so much!
      Pike
    • kcvinu
      By kcvinu
      Hi all,
      I have a button created with _GUICtrlButton_Create function. I know that this function returns a handle of button instead of an ID. So i have obtain control ID by calling _WinAPI_GetDlgCtrlID function. After that i have tried the GUICtrlSetBkColor function. But it didnt worked. Any suggestions will be appreciated. Thanks in advance. 
      Note : - The window which carries this button is not created with native gui create function. Instead, it is created with CreateWindowEx api function.
    • Robdog1955
      By Robdog1955
      I'm trying to click a button on a web page. I have added a couple of MsgBox lines to allow me to watch what happens on the page. As you can see the first half of my script enters data into text boxes on the page. I have no problem there. I just cannot click on the region buttons. The "set focus" line causes an outline to appear around the EU button and the "click button" line causes the "Pick a Region" text to disappear. Here is the code I have so far.
      #include <IE.au3> Local $oIE = _IECreate("http://questchecker.com/") Local $iQuestID = "123456" Local $sCharacterName = "CharacterName" Local $colForms = _IEFormGetCollection($oIE) $iCount = 0 For $oForm In $colForms $oFormElements = _IEFormElementGetCollection($oForm) For $oFormElement In $oFormElements $iCount = $iCount + 1 Local $sTagName = StringLower($oFormElement.tagName) Local $sElementType = $oFormElement.type Local $sElementName = $oFormElement.name Switch $iCount Case 6 _IEFormElementSetValue($oFormElement, "MyRealm", 0) ; realm Case 7 _IEFormElementSetValue($oFormElement, $sCharacterName, 0) Case 8 _IEFormElementSetValue($oFormElement, $iQuestID, 0) EndSwitch Next Next Local $oButtons = _IEGetObjByName($oIE, "questForm") For $oButton In $oButtons If _IEFormElementGetValue($oButton) = "US" Then MsgBox(0, "", "Click Okay to set focus") _IEAction($oButton, "focus") MsgBox(0, "", "Click Okay to click button") _IEAction($oButton, "click") ExitLoop EndIf Next MsgBox(0, "", "Click Okay to quit") _IEQuit($oIE) Exit  
    • buymeapc
      By buymeapc
      Hi all,
      I'm trying to create a listview with subitem icons and I achieved this by simply rearranging the order of the columns, so that the first column is in the middle, thus appearing as a subitem with an icon - this method prevents the "icon clipping" that happens when using subitem icons in a listview. My issue is that when I select a row that does not have an icon, the space where the icon would be is white. Is there a way to make this transparent, so it looks like the entire row is selected?
      Here's an example - click the second listview item/row to see a blank space where the icon would be.
      #include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> _Main() Func _Main() Local $hGui, $listview, $hImage Local $iLV_EXStyle_NoChecks = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER, $LVS_EX_HEADERDRAGDROP) $hGui = GUICreate("Listview Test With Icons", 400, 300) $listview = GUICtrlCreateListView("Col 1|Col 2|Col 3", 2, 2, 394, 268, BitOR($LVS_REPORT, $LVS_SHAREIMAGELISTS)) _GUICtrlListView_SetExtendedListViewStyle($listview, $iLV_EXStyle_NoChecks) GUISetState() ; Create the image list $hImage = _GUIImageList_Create(16, 16, 5, 3) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 165) _GUICtrlListView_SetImageList($listview, $hImage, 1) ; Set the order so the first column is moved to the middle, ; acting like a subitem with an icon _GUICtrlListView_SetColumnOrder($listview, "1|0|2") ; Add the items GUICtrlCreateListViewItem("Item1|Item2|Item3", $listview) GUICtrlCreateListViewItem("Item4|Item5|Item6", $listview) ; Set an icon for just the first item _GUICtrlListView_SetItemImage($listview, 0, 0) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main  
×