Code : Tout sélectionner
; Open window.
If OpenWindow(0, 200, 200, 200, 120, #PB_Window_SystemMenu, "Clipboard and menu")
; Create popup menu that will be display.
If CreatePopupMenu(0)
MenuItem(1, "Cut")
MenuItem(2, "Copy")
MenuItem(3, "Paste")
EndIf
; Create Gadget list, and Editor.
If CreateGadgetList(WindowID())
EditorGadget(7, 10, 10, 100, 100)
EndIf
; Main
Repeat
; Select event from window.
Select WaitWindowEvent()
; If it's left button mouse.
Case #WM_RButtonDown
; Get cursor position.
GetCursorPos_(@pt.POINT)
x = pt\x
y = pt\y
ScreenToClient_(WindowID(0),@pt.POINT)
; If mouse is over editor.
If ChildWindowFromPoint_( WindowID(0), pt\x, pt\y)=GadgetID(7)
; Create empty buffers.
SStart.l = 0
SEnd.l = 0
; Receive informations from selection.
SendMessage_(GadgetID(7), #EM_GETSEL, @SStart, @SEnd)
; If numbers are the same (no selection).
If SEnd = SStart
; Disable Cut and Copy .
DisableMenuItem(1, 1)
DisableMenuItem(2, 1)
; Else,
Else
; Enable Cut and Copy.
DisableMenuItem(1, 0)
DisableMenuItem(2, 0)
EndIf
; If clipbord is empty or don't contain text.
If GetClipboardText() = ""
; Disable Paste
DisableMenuItem(3, 1)
; Else,
Else
; Enable Paste.
DisableMenuItem(3, 0)
EndIf
; Finally, display popupmenu.
DisplayPopupMenu(0,WindowID(), x, y) ; On affiche le menu contextuel
EndIf
; If event is from menu.
Case #PB_EventMenu
; Get item ID.
Select EventMenuID()
; If it's item 1 (Cut)
Case 1
; Cut text into clipboard.
SendMessage_(GadgetID(7), #WM_CUT, 0, 0)
; If it's item 2 (Copy)
Case 2
; Copy text into clipboard.
SendMessage_(GadgetID(7), #WM_COPY, 0, 0)
; If it's item 3 (paste)
Case 3
; Get text from clipbboard
Texte$ = GetClipboardText()
; Replace selection if exists or put it at position.
SendMessage_(GadgetID(7), #EM_REPLACESEL, #False, @Texte$)
EndSelect
; If user has clicked on X.
Case #PB_EventCloseWindow
; quit = 1
quit = 1
EndSelect
; Until user cliked on X (quit = 1).
Until quit = 1
EndIf
; EOP => End Of Program ;).
End
Edit : mis à jour, c'est bien maintenant, il est plus simple
