Jump to content

GroupBox click


Miloud
 Share

Recommended Posts

Hi,

I want, please, to know how to get msg when the user click on the boundaries of a GroupBox.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Dialog", 357, 203, 259, 217)
$Group1 = GUICtrlCreateGroup("group1", 8, 8, 129, 185)
GUICtrlSetBkColor(-1, 0xA0A0A4)
$Input1 = GUICtrlCreateInput("Input1", 24, 48, 97, 21)
$Button3 = GUICtrlCreateButton("Button3", 32, 88, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Group2", 280, 16, 67, 25)
$Button2 = GUICtrlCreateButton("Group3", 280, 48, 67, 25)
$Group2 = GUICtrlCreateGroup("group2", 144, 8, 129, 185)
GUICtrlSetBkColor(-1, 0xA0A0A4)
$Input2 = GUICtrlCreateInput("Input2", 160, 48, 97, 21)
$Button4 = GUICtrlCreateButton("Button4", 168, 88, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button1
            GUICtrlSetBkColor($Group1, 0x3A6EA5)
            GUICtrlSetBkColor($Group2, 0xA0A0A4)
         Case $Button2
            GUICtrlSetBkColor($Group1, 0xA0A0A4)
            GUICtrlSetBkColor($Group2, 0x3A6EA5)
    EndSwitch
WEnd

I.e. how to change the Group1 & 2 background colors when the user click on them (not on the Buttons?

Link to comment
Share on other sites

Here's one way to do it. You can remove the WM_MOUSEMOVE if you just want it to color the group control when you click in the group control. If you like it coloring the group control if the mouse is in that control then remove the WM_LBUTTONDOWN.

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

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Dialog", 280, 203, 259, 217)
$Group1 = GUICtrlCreateGroup("group1", 8, 8, 129, 185)
GUICtrlSetBkColor(-1, 0xA0A0A4)
$Input1 = GUICtrlCreateInput("Input1", 24, 48, 97, 21)
$Button3 = GUICtrlCreateButton("Button1", 32, 88, 75, 25)
$Group2 = GUICtrlCreateGroup("group2", 144, 8, 129, 185)
GUICtrlSetBkColor(-1, 0xA0A0A4)
$Input2 = GUICtrlCreateInput("Input2", 160, 48, 97, 21)
$Button4 = GUICtrlCreateButton("Button2", 168, 88, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_MOUSEMOVE, WM_MOUSEMOVE)
GUIRegisterMsg($WM_LBUTTONDOWN, WM_LBUTTONDOWN)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_LBUTTONDOWN($hWndFrom, $iMsg, $wParam, $lParam)
    Local $cursor_info = GUIGetCursorInfo($hWndFrom)
    If (@error) Then Return $GUI_RUNDEFMSG

    Switch ($hWndFrom)
        Case $Form2
            Switch ($cursor_info[4])
                Case $Group1
                    GUICtrlSetBkColor($Group1, 0x3A6EA5)
                    GUICtrlSetBkColor($Group2, 0xA0A0A4)
                Case $Group2
                    GUICtrlSetBkColor($Group1, 0xA0A0A4)
                    GUICtrlSetBkColor($Group2, 0x3A6EA5)
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_LBUTTONDOWN

Func WM_MOUSEMOVE($hWndFrom, $iMsg, $wParam, $lParam)
    Local Static $set_color_for = 0
    Local $cursor_info = GUIGetCursorInfo($hWndFrom)
    If (@error) Then Return $GUI_RUNDEFMSG

    Switch ($hWndFrom)
        Case $Form2
            Switch ($cursor_info[4])
                Case $Group1
                    If ($set_color_for = $Group2 Or Not $set_color_for) Then
                        GUICtrlSetBkColor($Group1, 0x3A6EA5)
                        GUICtrlSetBkColor($Group2, 0xA0A0A4)
                        $set_color_for = $Group1
                    EndIf
                Case $Group2
                    If ($set_color_for = $Group1 Or Not $set_color_for) Then
                        GUICtrlSetBkColor($Group1, 0xA0A0A4)
                        GUICtrlSetBkColor($Group2, 0x3A6EA5)
                        $set_color_for = $Group2
                    EndIf
                Case Else
                    If ($set_color_for = $Group1) Then
                        GUICtrlSetBkColor($Group1, 0xA0A0A4)
                    ElseIf ($set_color_for = $Group2) Then
                        GUICtrlSetBkColor($Group2, 0xA0A0A4)
                    EndIf
                    $set_color_for = 0
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_MOUSEMOVE

 

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...