Jump to content
Sign in to follow this  

GUIRegisterMsg + GUICtrlSetStyle = bug ?

Recommended Posts


the function 'GUIRegisterMsg' do not work after the function 'GUICtrlSetStyle' is execute.

#include <Date.au3>
#include <Constants.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1); GUI OnEvent

Global Const $STN_DBLCLK = 1

Local $win_main = GUICreate("", 450, 30, 450, 30)
GUISetOnEvent($GUI_EVENT_CLOSE, "gui_win_tool")
Local $Label = GUICtrlCreateLabel("", 0, 0, 450, 30)
;GUICtrlSetOnEvent($Label, "gui_win_tool")


Local $begin_ticks = _Date_Time_GetTickCount()
Local $waitticks = 9000 / 1
While 1
    If _Date_Time_GetTickCount() - $begin_ticks > $waitticks Then
        GUICtrlSetStyle($Label, $SS_CENTER)

        GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
        GUICtrlSetData($Label, "double click me can not show TrayTip now! ")
        GUICtrlSetData($Label, "double click me to show TrayTip. " & @CRLF _
                 & "after " & Int(($waitticks - _Date_Time_GetTickCount() + $begin_ticks) / 1000) _
                 & " seconds, this will not work,is this a bug for GUIRegisterMsg?")


Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    ;ConsoleWrite("$hWnd=" & $hWnd & @CRLF)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $hCtrl = $lParam
    Switch $nID
        Case $Label
            Switch $nNotifyCode
                Case $STN_DBLCLK
                    TrayTip("", "dbclick at " & @HOUR & ":" & @MIN & ":" & @SEC, 1, 1)

EndFunc   ;==>MY_WM_COMMAND

Func gui_win_tool()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            ;Case $Label
            ;   TrayTip("", " some click at " & @HOUR & ":" & @MIN & ":" & @SEC, 1, 1)
EndFunc   ;==>gui_win_tool

Share this post

Link to post
Share on other sites

The default style for a label is not $SS_LEFT, it's actually a lot more styles combined. By assigning $SS_CENTER you are overriding all other styles, causing the style that is responsible for notifying you on a click to be no longer active.

Share this post

Link to post
Share on other sites


No bug!

When you set any of the styles, you overwrite any styles that already exist. In your case, using GUICtrlSetStyle($Label, $SS_CENTER) removes all the default styles that were put in place when you created the label.

From the Help file, these are $SS_NOTIFY, $SS_LEFT. See the first one? That is what fires the WM_COMMAND message - so by removing it you prevent the message from being sent! :huggles:

Replace it with this: GUICtrlSetStyle($Label, BitOr($SS_NOTIFY, $SS_CENTER)) and all will be well. :D

By the way, you do not need another GUIRegisterMsg in your loop - one per script is quite enough! :


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites


you are great, thank you very much!!!

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