Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Type PasteType
s As WString * 100
x As Long
y As Long
End Type
%M = 30
%IDM_Paste = 500
%IDM_Clear = 501
%IDM_Cut = 502
%IDM_Sep = 503
%IDM_Copy = 504
Global s() As PasteType, hDlg,hContext As Dword, pt As Point
Function PBMain() As Long
Dialog New Pixels, 0, "Cut/Copy/Paste on Dialog",300,300,250,100, %WS_OverlappedWindow To hDlg
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local hDC As Dword, PS As PaintStruct, i,x,y As Long, temp As WString
Select Case Cb.Msg
Case %WM_InitDialog
CreateContextMenu
ReDim s(0)
ReDim s(2) '<--- demo purposes only. comment out.
s(1).s = "Hello Ross" : s(1).x = 10 : s(1).y = 10 '<--- demo purposes only. comment out.
s(2).s = "Goodbye Ross" : s(2).x = 140 : s(2).y = 60 '<--- demo purposes only. comment out.
Case %WM_Command
Select Case Cb.Ctl
Case %IDM_Cut
'find text within +/- 10 pixels of mouse (using upper/left of text
For i = 1 To UBound(s)
If pt.x < s(i).x + %M And pt.x > s(i).x - %M _
And pt.y < s(i).y + %M And pt.y > s(i).y - %M Then
Array Delete s(i)
ReDim Preserve s(UBound(s)-1)
Dialog ReDraw hDlg
Exit For
End If
Next i
Case %IDM_Copy
'find text within +/- 10 pixels of mouse (using upper/left of text
For i = 1 To UBound(s)
If pt.x < s(i).x + %M And pt.x > s(i).x - %M _
And pt.y < s(i).y + %M And pt.y > s(i).y - %M Then
Clipboard Reset
Clipboard Set Text s(i).s
Dialog ReDraw hDlg
Exit For
End If
Next i
Case %IDM_Paste
'add clipboard to array s()
Clipboard Get Text To temp
If Len(temp) Then
'add new element to array
ReDim Preserve s(UBound(s)+1)
'get text from clipboard
Clipboard Get Text To s(UBound(s)).s
'get coordinates of mouse
s(UBound(s)).x = pt.x
s(UBound(s)).y = pt.y
Dialog ReDraw hDlg
Else
Beep
End If
Case %IDM_Clear
'clear clipboard and array s()
Clipboard Reset
Erase s()
Dialog ReDraw hDlg
End Select
Case %WM_ContextMenu
pt.x = Lo(Integer,Cb.LParam) : pt.y = Hi(Integer, Cb.LParam)
TrackPopupMenu hContext, %TPM_LeftAlign, pt.x, pt.y, 0, Cb.Hndl, ByVal 0
ScreenToClient hDlg, pt
Case %WM_Paint
'draw on dialog
hDC = BeginPaint(hDlg, PS)
For i = 1 To UBound(s)
temp = Trim$(s(i).s)
textout hdc, s(i).x,s(i).y, ByVal StrPtr(temp), Len(temp)
Next i
EndPaint hDlg, PS
End Select
End Function
Sub CreateContextMenu
Menu New PopUp To hContext
Menu Add String, hContext, "Cut", %IDM_Cut, %MF_Enabled
Menu Add String, hContext, "Copy", %IDM_Copy, %MF_Enabled
Menu Add String, hContext, "Paste", %IDM_Paste, %MF_Enabled
Menu Add String, hContext, "-", %IDM_Sep, %MF_Enabled
Menu Add String, hContext, "Clear", %IDM_Clear, %MF_Enabled
End Sub
'gbs_01198
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm