Jump to content

[HELP] Problem with control Layering and WM_COMMAND


jmon
 Share

Recommended Posts

Hello,

How come in this example, when I click on label 2, I get the notification for Label 1?

I have 2 controls overlapping, and I cannot disable them.

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $GUI, $LABEL1, $LABEL2
$GUI = GUICreate("Test", 800, 600)
$LABEL1 = GUICtrlCreateLabel("Label 1", 40, 40, 700, 520)
GUICtrlSetBkColor(-1, 0xFF0000)
$LABEL2 = GUICtrlCreateLabel("Label 2", 100, 100, 600, 400)
GUICtrlSetBkColor(-1, 0x00FF00)

GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    Sleep(50)
WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $hWndFrom
        Case GUICtrlGetHandle($LABEL1)
            MsgBox(0, "Click received", "Label 1 was clicked")
        Case GUICtrlGetHandle($LABEL2)
            MsgBox(0, "Click received", "Label 2 was clicked")
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Thanks in advance for your help.

Link to comment
Share on other sites

Here a workaround:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $GUI, $LABEL1, $LABEL2
$GUI = GUICreate("Test", 800, 600)
$LABEL1 = GUICtrlCreateLabel("Label 1", 40, 40, 700, 520)
GUICtrlSetBkColor(-1, 0xFF0000)
$LABEL2 = GUICtrlCreateLabel("Label 2", 100, 100, 600, 400)
GUICtrlSetBkColor(-1, 0x00FF00)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            $aM = GUIGetCursorInfo($GUI)
            Switch $aM[4]
                Case $LABEL1
                    MsgBox(0, "Click received", "Label 1 was clicked")
                Case $LABEL2
                    MsgBox(0, "Click received", "Label 2 was clicked")
            EndSwitch
    EndSwitch
;~     Sleep(50)
WEnd

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Here a workaround:

Thanks UEZ. This workaround works. Still I find the behavior of WM_COMMAND weird... I don't understand why my example doesn't work.

I'll use your trick in the meantime.

Whici one you want to disable it? Or you want both to be clickable?

I don't want to disable them, I just want to receive the notification when I click on the labels.

Actually the reason I am asking this, is because I need it in my I want to receive the notification when I click on the event, but I always receive the notification of the day, not the event...

Edited by jmon
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

×
×
  • Create New...