Sign in to follow this  
Followers 0
biase

Help on Toolbar: all clicked ID return 0

7 posts in this topic

I even tried _GuiCtrlToolbar_IsButtonPressed, but still failed.

I Just need like

If _WinAPI_LoWord($wParam) == $TRadio Then Msgbox(0, '', 'Radio')
If _WinAPI_LoWord($wParam) == $TMovie Then Msgbox(0, '', 'Movie')

This is all my code

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

Global $aStrings[5]
Global $TRadio, $TTv, $TMovie, $TAbout, $TExit
$hGUI = GUICreate("Multimedia", 623, 449, 192, 114)
$hImageList = _GUIImageList_Create(32, 32, 5)
_GUIImageList_AddIcon($hImageList, @ScriptDir & '\Iron_Radio.ico', '', True)
_GUIImageList_AddIcon($hImageList, @ScriptDir & '\Iron_Tv.ico', '', True)
_GUIImageList_AddIcon($hImageList, @ScriptDir & '\Iron_Movie.ico', '', True)
_GUIImageList_AddIcon($hImageList, @ScriptDir & '\Iron_About.ico', '', True)
_GUIImageList_AddIcon($hImageList, @ScriptDir & '\Iron_Exit.ico', '', True)
$hToolBar = _GUICtrlToolbar_Create($hGUI, 0)
_GUICtrlToolbar_SetImageList($hToolBar, $hImageList)
; Add strings
$aStrings[0] = _GUICtrlToolbar_AddString($hToolBar, "Radio")
$aStrings[1] = _GUICtrlToolbar_AddString($hToolBar, "Tv")
$aStrings[2] = _GUICtrlToolbar_AddString($hToolBar, "Movie")
$aStrings[3] = _GUICtrlToolbar_AddString($hToolBar, "About")
$aStrings[4] = _GUICtrlToolbar_AddString($hToolBar, "Exit")

_GUICtrlToolbar_AddButton($hToolBar, $TRadio, 0, $aStrings[0])
_GUICtrlToolbar_AddButton($hToolBar, $TTv, 1, $aStrings[1])
_GUICtrlToolbar_AddButton($hToolBar, $TMovie, 2, $aStrings[2])
_GUICtrlToolbar_AddButtonSep($hToolbar)
_GUICtrlToolbar_AddButton($hToolBar, $TAbout, 3, $aStrings[3])
_GUICtrlToolbar_AddButton($hToolBar, $TExit, 4, $aStrings[4])
; Register WM_COMMAND messages
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetState()
While 1
Sleep(10)
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
ConsoleWrite(_WinAPI_LoWord($wParam) & @CRLF)
EndFunc   ;==>WM_COMMAND

Share this post


Link to post
Share on other sites



bump

Share this post


Link to post
Share on other sites

Please read the forum rules on bumping topics before 24 hours is up.

Do you need to recognise when your control is clicked? If so , use either guictrlgetmsg or oneventmode.


There are 10 types of people in this world. Those that understand binary, and those that do not

Share this post


Link to post
Share on other sites

I would suggest looking at the help file for _GUICtrlToolBar_Create, the example in there should give you a good idea of how to use the toolbar buttons and how the window message should be interpreted.

1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

biase,

Did you look at the Help file examples? I think not because you are not even registering the correct message! :oops:

This works for me:

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

#include <Array.au3>

Global $iItem
Global $aStrings[5]
Global $aTitles[6] = ["Radio", "TV", "Movie", "", "About", "Exit"] ; We need the blank so the CIDs match the indices
Global Enum $idRadio = 1000, $idTV, $idMovie, $idAbout, $idExit
Global $aCID[6]

$hGUI = GUICreate("Multimedia", 623, 449, 192, 114)

$hImageList = _GUIImageList_Create(32, 32, 5)
_GUIImageList_AddIcon($hImageList, @ScriptDir & 'Iron_Radio.ico', '', True)
_GUIImageList_AddIcon($hImageList, @ScriptDir & 'Iron_TV.ico', '', True)
_GUIImageList_AddIcon($hImageList, @ScriptDir & 'Iron_Movie.ico', '', True)
_GUIImageList_AddIcon($hImageList, @ScriptDir & 'Iron_About.ico', '', True)
_GUIImageList_AddIcon($hImageList, @ScriptDir & 'Iron_Exit.ico', '', True)
$hToolBar = _GUICtrlToolbar_Create($hGUI, 0)
_GUICtrlToolbar_SetImageList($hToolBar, $hImageList)

; Add strings
$aStrings[0] = _GUICtrlToolbar_AddString($hToolBar, $aTitles[0])
$aStrings[1] = _GUICtrlToolbar_AddString($hToolBar, $aTitles[1])
$aStrings[2] = _GUICtrlToolbar_AddString($hToolBar, $aTitles[2])
$aStrings[3] = _GUICtrlToolbar_AddString($hToolBar, $aTitles[4]) ; Careful with the index numbering here
$aStrings[4] = _GUICtrlToolbar_AddString($hToolBar, $aTitles[5])

_GUICtrlToolbar_AddButton($hToolBar, $idRadio, 0, 0)
_GUICtrlToolbar_AddButton($hToolBar, $idTv,    1, 1)
_GUICtrlToolbar_AddButton($hToolBar, $idMovie, 2, 2)
_GUICtrlToolbar_AddButtonSep($hToolbar)
_GUICtrlToolbar_AddButton($hToolBar, $idAbout, 3, 3)
_GUICtrlToolbar_AddButton($hToolBar, $idExit,  4, 4)

; This dummy will fire when a button is clicked
$cDummy = GUICtrlCreateDummy()

GUISetState()

; Register WM_COMMAND messages
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cDummy
            ; The dummy was fired so read the index and show the button title
            MsgBox(0, "Clicked", $aTitles[GUICtrlRead($cDummy)])
    EndSwitch
WEnd

; WM_NOTIFY event handler
Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tNMHDR, $hwndFrom, $code, $i_idNew, $dwFlags, $i_idOld
    Local $tNMTBHOTITEM
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $code = DllStructGetData($tNMHDR, "Code")
    Switch $hwndFrom
        Case $hToolbar
            Switch $code
                Case $NM_LDOWN
                    ; A button was clicked so fire the dummy control with the index of the "hot" item
                    $iClicked = _GUICtrlToolbar_CommandToIndex($hToolbar, $iItem)
                    GUICtrlSendToDummy($cDummy, $iClicked)
                Case $TBN_HOTITEMCHANGE
                    $tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
                    $i_idOld = DllStructGetData($tNMTBHOTITEM, "idOld")
                    $i_idNew = DllStructGetData($tNMTBHOTITEM, "idNew")
                    ; Note the "hot" item
                    $iItem = $i_idNew
                    $dwFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags")
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

You may wonder why I went to all the trouble of using a dummy control rather then showing the MsgBox directly from the message handler - read the Help file page for GUIRegisterMsg to find out. :bye:

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Thanks for the reply guys...

Melba, you're correct about not referring help file, i first search on the forum for toolbar..

my bad... learned my lesson today.

Share this post


Link to post
Share on other sites

biase,

Glad we got it working. :oops:

And the Help file should always be your first port of call - we are very lucky to have such a good one. :bye:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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  
Followers 0