Jump to content

GUIRegisterMsg issue


Recommended Posts

Hi to all, i've an issue with the command GUIRegisterMsg()

For example i've this script :

#include <ButtonConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiToolbar.au3>
#include <ComboConstants.au3>
#include <GUIComboBox.au3>
Global Enum $idNew = 1000, $idOpen, $idSave
Global $fComboChange = False

$Form1 = GUICreate("Form1", 277, 259, 192, 124)
$Label1 = GUICtrlCreateLabel("Write your text here:", 8, 40, 99, 17)
$Combo1 = _GUICtrlComboBox_Create($Form1, "", 120, 40, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$ToolBar1 = _GUICtrlToolbar_Create($Form1, 0)
$hDummy = GUICtrlCreateDummy()
GUISetState(@SW_SHOW)

_GUICtrlToolbar_AddBitmap ($Toolbar1, 1, -1, $IDB_STD_LARGE_COLOR)
_GUICtrlToolbar_AddButton ($ToolBar1 , $idNew, $STD_FILENEW)
_GUICtrlToolbar_AddButton ($ToolBar1, $idOpen, $STD_FILEOPEN)
_GUICtrlToolbar_AddButton ($ToolBar1, $idSave, $STD_FILESAVE)

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
GUIRegisterMsg($WM_COMMAND, "My_WM_COMMAND")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hDummy
            ; Read the code sent to the Dummy control
            $iCmdID = GUICtrlRead($hDummy)
            Switch $iCmdID
                Case 1000
                    MsgBox (0,"","New Button pressed!")
                Case 1001
                    MsgBox (0,"","Open Button pressed!")
                Case 1002
                    MsgBox (0,"","Save Button pressed!")
            EndSwitch
            
    EndSwitch

    If $fComboChange Then
        $fComboChange = False
        $sText = _GUICtrlComboBox_GetEditText($Combo1)
        If $sText <> "" Then
            TrayTip ("The new text is: ",$sText,5)
        EndIf
    EndIf
WEnd

Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $sText, $iItem
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF)
    $iCode = BitShift($iwParam, 16)

    Switch $hWndFrom
        Case $Combo1
            Switch $iCode
                Case $CBN_EDITCHANGE
                    $fComboChange = True
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND

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

    ; Check if CmdID is toolbar button
    Local $iCmdID = _WinAPI_LoWord($wParam)
    Switch $iCmdID
        Case $idNew To $idSave
            ; Send the CmdID to the Dummy control
            GUICtrlSendToDummy($hDummy, $iCmdID)
    EndSwitch

EndFunc

I've a Toolbar here, i use the My_WM_COMMAND function to know the pressed button...

I've a combo box, i use it to put a text...i've a function that warn me if a "string" is write in the combo and if that change.

Now if i try to registered this function toghether (_WM_COMMAND and My_WM_COMMAND) they dont work, if i try to register only one function the function work good.

There are a metod to run the two functions together?

Hi! <3

Edited by StungStang
Link to comment
Share on other sites

  • Moderators

StungStang,

You can only have one handler per message - as you have discovered. But you can have several "functions" within the same handler - like this. :)

#include <ButtonConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiToolbar.au3>
#include <ComboConstants.au3>
#include <GUIComboBox.au3>
Global Enum $idNew = 1000, $idOpen, $idSave
Global $fComboChange = False

$Form1 = GUICreate("Form1", 277, 259, 192, 124)
$Label1 = GUICtrlCreateLabel("Write your text here:", 8, 40, 99, 17)
$Combo1 = _GUICtrlComboBox_Create($Form1, "", 120, 40, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$ToolBar1 = _GUICtrlToolbar_Create($Form1, 0)
$hDummy = GUICtrlCreateDummy()
GUISetState(@SW_SHOW)

_GUICtrlToolbar_AddBitmap ($Toolbar1, 1, -1, $IDB_STD_LARGE_COLOR)
_GUICtrlToolbar_AddButton ($ToolBar1 , $idNew, $STD_FILENEW)
_GUICtrlToolbar_AddButton ($ToolBar1, $idOpen, $STD_FILEOPEN)
_GUICtrlToolbar_AddButton ($ToolBar1, $idSave, $STD_FILESAVE)

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hDummy
            ; Read the code sent to the Dummy control
            $iCmdID = GUICtrlRead($hDummy)
            Switch $iCmdID
                Case 1000
                    MsgBox (0,"","New Button pressed!")
                Case 1001
                    MsgBox (0,"","Open Button pressed!")
                Case 1002
                    MsgBox (0,"","Save Button pressed!")
            EndSwitch

    EndSwitch

    If $fComboChange Then
        $fComboChange = False
        $sText = _GUICtrlComboBox_GetEditText($Combo1)
        If $sText <> "" Then
            TrayTip ("The new text is: ",$sText,5)
        EndIf
    EndIf
WEnd

Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)

    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF)
    $iCode = BitShift($iwParam, 16)

    Switch $hWndFrom
        Case $Combo1
            Switch $iCode
                Case $CBN_EDITCHANGE
                    $fComboChange = True
            EndSwitch
    EndSwitch

    ; Check if CmdID is toolbar button
    Local $iCmdID = _WinAPI_LoWord($iwParam)
    Switch $iCmdID
        Case $idNew To $idSave
            ; Send the CmdID to the Dummy control
            GUICtrlSendToDummy($hDummy, $iCmdID)
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>_WM_COMMAND

All clear? :)

M23

P.S. You do not need to declare function parameters as Local variables - they already are by default. :P

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 spoiler to see my UDFs:

Spoiler

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

 

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