Jump to content

correct use of GuiRegisterMsg(),$WM_COMMAND and $tagTBBUTTON


maqleod
 Share

Recommended Posts

ok, so I've looked in the help file under $WM_COMMAND, $tagTBBUTTON, GuiRegisterMsg() and have looked at the example _GuiCtrlToolbar_ClickButton() and I can't seem to find the way to do this. I've tried all sorts of things and most of the time I get a crash. When I searched the forum for performing actions when a toolbar button is pressed I only saw one posting with no source examples, which of course didn't help me much.

On to what I am trying to do. I just want to call a single function for each button pressed. Below is my toolbar build and what I was trying for the button press (i don't think you'll need more, but I'll post the rest if necessary, the code is almost 900 lines). I could use some pointers on how to do this right.

Global $iItem
Local Enum $idNew = 1000, $idopen, $idsave, $idsaveas, $idprint, $idcut, $idcopy, $idpaste, $idundo, $idhelp

$toolbar = _GUICtrlToolbar_Create($parent)
$imagelist = _GuiImageList_Create(16,16,0,0,9,9)
_GUIImageList_AddIcon($imagelist, "Icons\open.ico",0)
_GUIImageList_AddIcon($imagelist, "Icons\new.ico",0)
_GUIImageList_AddIcon($imagelist, "Icons\save.ico",0)
_GUIImageList_AddIcon($imagelist, "Icons\print.ico",0)
_GUIImageList_AddIcon($imagelist, "Icons\cut.ico",0)
_GUIImageList_AddIcon($imagelist, "Icons\copy.ico",0)
_GUIImageList_AddIcon($imagelist, "Icons\paste.ico",0)
_GUIImageList_AddIcon($imagelist, "Icons\undo.ico",0)
_GUIImageList_AddIcon($imagelist, "Icons\help.ico",0)
_GUICtrlToolbar_SetImageList($toolbar, $imagelist)
$opentoolbar = _GuiCtrlToolbar_AddButton($toolbar,$idopen,0)
$newtoolbar = _GuiCtrlToolbar_AddButton($toolbar,$idnew,1)
$savetoolbar = _GuiCtrlToolbar_AddButton($toolbar,$idsave,2)
$printtoolbar = _GuiCtrlToolbar_AddButton($toolbar,$idprint,3)
_GUICtrlToolbar_AddButtonSep($toolbar)
$undotoolbar = _GuiCtrlToolbar_AddButton($toolbar,$idundo,4)
$cuttoolbar = _GuiCtrlToolbar_AddButton($toolbar,$idcut,5)
$copytoolbar = _GuiCtrlToolbar_AddButton($toolbar,$idcopy,6)
$pastetoolbar = _GuiCtrlToolbar_AddButton($toolbar,$idpaste,7)
_GUICtrlToolbar_AddButtonSep($toolbar)
$helptoolbar = _GuiCtrlToolbar_AddButton($toolbar,$idhelp,8)

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")


Func _WM_COMMAND($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tNMHDR, $event, $hwndFrom
    $tNMHDR = DllStructCreate($tagTBBUTTON, $lParam)
    $hwndFrom = DllStructGetData($tNMHDR, "Command")
    Switch $hwndFrom
        Case $toolbar
            Switch $event
                Case $NM_LDOWN
                    MsgBox(64,"",$hwndFrom)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND
[u]You can download my projects at:[/u] Pulsar Software
Link to comment
Share on other sites

ok, I figured out something, though I don't know if it is the best way to do this, it at least works:

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tNMHDR, $event, $hwndFrom, $code
    Local $tNMTOOLBAR
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $code = DllStructGetData($tNMHDR, "Code")
    Switch $hwndFrom
        Case $toolbar
            Switch $code
                Case $NM_LDOWN
                    if $iItem = 1000 then
                        New()
                    EndIf
                    if $iItem = 1001 then
                        Open()
                    EndIf
                    if $iItem = 1002 then
                        Save()
                    EndIf
                    if $iItem = 1004 then
                        Print()
                    EndIf
                    if $iItem = 1005 then
                        Copy()
                    EndIf
                    if $iItem = 1006 then
                        Paste()
                    EndIf
                    if $iItem = 1007 then
                        Undo()
                    EndIf
                    if $iItem = 1008 then
                        Cut()
                    EndIf
                    if $iItem = 1009 then
                        ;Help()
                    EndIf
                Case $TBN_HOTITEMCHANGE
                    $tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
                    $i_idOld = DllStructGetData($tNMTBHOTITEM, "idOld")
                    $i_idNew = DllStructGetData($tNMTBHOTITEM, "idNew")
                    $iItem = $i_idNew
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY
[u]You can download my projects at:[/u] Pulsar Software
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...