Sources PureBasic
Sources PureBasicConsultez toutes les sources
Nombre d'auteurs : 41, nombre de sources : 88, dernière mise à jour : 13 août 2011
Procedure
callback(hWnd, uMsg, wParam, lParam)
Protected
result, *
nmt.NMTOOLBAR, rc.RECT
result =
#PB_ProcessPureBasicEvents
Select
uMsg
Case
#WM_NOTIFY
*
nmt =
lParam
If
*
nmt\hdr\code =
#TBN_DROPDOWN
;User has clicked our toolbar button's drop down arrow.
;Get screen co-ordinates of the button.
SendMessage_(*
nmt\hdr\hwndFrom, #TB_GETRECT
, *
nmt\iItem, rc)
MapWindowPoints_(*
nmt\hdr\hwndFrom, 0
, rc, 2
)
;Display pop-up menu.
DisplayPopupMenu(0
, WindowID(0
), rc\left, rc\bottom)
EndIf
EndSelect
ProcedureReturn
result
EndProcedure
If
OpenWindow(0
, 0
, 0
, 150
, 25
, "ToolBar"
, #PB_Window_SystemMenu
|
#PB_Window_ScreenCentered
)
;Create a pop-up menu.
If
CreatePopupMenu(0
)
MenuItem(100
, "Cut"
)
MenuItem(101
, "Copy"
)
MenuItem(102
, "Paste"
)
EndIf
;Create our toolbar.
hTb =
CreateToolBar(0
, WindowID(0
))
If
hTb
ToolBarStandardButton(0
, #PB_ToolBarIcon_New
)
ToolBarStandardButton(1
, #PB_ToolBarIcon_Open
)
ToolBarStandardButton(2
, #PB_ToolBarIcon_Save
)
;Add a drop down button.
fStyle =
SendMessage_(hTb,#TB_GETEXTENDEDSTYLE
,0
,0
)
SendMessage_(hTb, #TB_SETEXTENDEDSTYLE
, 0
, fSTyle |
#TBSTYLE_EX_DRAWDDARROWS
)
With
btn.TBBUTTON
\iBitmap =
#PB_ToolBarIcon_Print
+
1
\idCommand =
3
\fsState =
#TBSTATE_ENABLED
\fsStyle =
$8
|
#BTNS_SHOWTEXT
|
#TBSTYLE_AUTOSIZE
\dwData =
0
\iString =
-
1
SendMessage_(hTb, #TB_ADDBUTTONS
,1
, btn)
EndWith
EndIf
SetWindowCallback(@callback())
Repeat
Event =
WaitWindowEvent()
If
Event =
#PB_Event_Menu
Debug
"Menu ID: "
+
Str(EventMenu())
EndIf
Until
Event =
#PB_Event_CloseWindow
EndIf
PureBasic dispose en natif de la commande ToolBarToolTip() pour ajouter un texte flottant sur un bouton de la barre d'outils. Ce code vous montre comment personnaliser ce texte.
Procedure
ToolBar_ToolTip(ID_Window.l,ID_Toolbar.l)
Protected
ToolInfo.ToolInfo
Global
Tooltip.l
#TTF_TRANSPARENT
=
$100
Tooltip =
CreateWindowEx_ (0
, "tooltips_class32"
, ""
, 0
, #WS_POPUP
|
#TTS_ALWAYSTIP
, 0
, 0
, 0
, 0
, 0
, 0
, 0
)
SendMessage_ (Tooltip, #TTM_SETTIPTEXTCOLOR
, RGB (0
, 85
, 223
), 0
)
SendMessage_ (Tooltip, #TTM_SETTIPBKCOLOR
, RGB (255
, 255
, 223
), 0
)
SendMessage_ (Tooltip, #TTM_SETMAXTIPWIDTH
, 0
, 300
)
SendMessage_ (Tooltip, #TTM_SETTITLE
, #TTI_INFO
, ""
)
ToolInfo\cbSize =
SizeOf (ToolInfo)
ToolInfo\uFlags =
#TTF_IDISHWND
|
#TTF_SUBCLASS
|
#TTF_TRANSPARENT
ToolInfo\hWnd =
WindowID (ID_Window)
ToolInfo\uId =
ToolBarID (ID_Toolbar)
ToolInfo\hInst =
0
ToolInfo\lpszText =
0
SendMessage_ (Tooltip, #TTM_ADDTOOL
, 0
, @ToolInfo)
SendMessage_ (Tooltip, #TTM_SETDELAYTIME
, #TTDT_AUTOPOP
,3000
) ;Durée de l'apparition du Tooltip
SendMessage_ (Tooltip, #TTM_SETDELAYTIME
, #TTDT_INITIAL
,1000
) ;Délai avant l'apparition du Tooltip
EndProcedure
Procedure
Modify_ToolTip(ID_Window.l,ID_Toolbar.l,Title.s,Text.s)
Protected
ToolInfo.ToolInfo
ToolInfo\cbSize =
SizeOf (ToolInfo)
ToolInfo\hwnd =
WindowID (ID_Window)
ToolInfo\uId =
ToolBarID (ID_Toolbar)
ToolInfo\lpszText =
@Text
SendMessage_ (Tooltip, #TTM_ACTIVATE
,1
,0
)
SendMessage_ (Tooltip, #TTM_SETTITLE
, #TTI_INFO
, Title)
SendMessage_ (Tooltip, #TTM_UPDATETIPTEXT
,0
,@ToolInfo)
EndProcedure
Procedure
Callback(hwnd, msg, wParam, lParam)
result=
#PB_ProcessPureBasicEvents
Select
msg
Case
#WM_NOTIFY
*
pnmhdr.NMTBHOTITEM=
lParam
If
*
pnmhdr\hdr\code =
-
713
;#TBN_HOTITEMCHANGE
Select
*
pnmhdr\idnew
Case
1
Modify_ToolTip(0
,0
, "Nouveau:"
, "Ouvre un document vierge"
)
Case
2
Modify_ToolTip(0
,0
, "Ouvrir:"
, "Charge un nouveau fichier"
)
Case
3
Modify_ToolTip(0
,0
, "Sauver:"
, "Enregistre le fichier en cours"
)
Default
SendMessage_ (Tooltip, #TTM_ACTIVATE
,0
,0
)
EndSelect
EndIf
EndSelect
ProcedureReturn
result
EndProcedure
If
OpenWindow (0
, 0
, 0
, 220
, 220
, "ToolTip"
, #PB_Window_SystemMenu
|
#PB_Window_ScreenCentered
)
SetWindowCallback (@Callback(),0
)
If
CreateToolBar (0
, WindowID (0
))
ToolBarStandardButton (1
, #PB_ToolBarIcon_New
)
ToolBarStandardButton (2
, #PB_ToolBarIcon_Open
)
ToolBarStandardButton (3
, #PB_ToolBarIcon_Save
)
ToolBarSeparator ()
ToolBarStandardButton (4
, #PB_ToolBarIcon_Print
)
ToolBarStandardButton (5
, #PB_ToolBarIcon_Find
)
ToolBarSeparator ()
EndIf
ToolBar_ToolTip(0
,0
)
Repeat
Event =
WaitWindowEvent ()
Until
Event =
#PB_Event_CloseWindow
EndIf