Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
#Include "Win32API.inc"
Enum Equates Singular
IDC_TextBoxA = 600
IDC_TextBoxB
IDM_Cut
IDM_Paste
IDM_Copy
IDM_Delete
End Enum
Function PBMain() As Long
Local i As Long, hDlg As Dword
CreateSuperClass
Dialog New Pixels, 0, "TextBox Subclassing",300,300,300,100, %WS_OverlappedWindow To hDlg
Control Add "SuperEdit", hDlg, %IDC_TextBoxA, "Sample Data A", 20,20,120,20, %WS_Child Or %WS_Visible Or %WS_TabStop Or %ES_MultiLine Or %ES_WantReturn, %WS_Ex_ClientEdge
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local i As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDM_Cut : SendMessage GetFocus, %WM_CUT, 0, 0
Case %IDM_Copy : SendMessage GetFocus, %WM_COPY, 0, 0
Case %IDM_Paste : SendMessage GetFocus, %WM_PASTE, 0, 0
Case %IDM_Delete : SendMessage GetFocus, %WM_CLEAR, 0, 0
End Select
End Select
End Function
CallBack Function SuperEditProc()
Local x,y As Long
Static hContext, OldProc As Dword
If Cb.Hndl = 0 Then OldProc = Cb.WParam: Exit Function
Select Case Cb.Msg
Case %WM_Create
Menu New PopUp To hContext
Menu Add String, hContext, "Copy", %IDM_Copy, %MF_Enabled
Menu Add String, hContext, "Cut", %IDM_Cut, %MF_Enabled
Menu Add String, hContext, "Paste", %IDM_Paste, %MF_Enabled
Menu Add String, hContext, "Delete", %IDM_Delete, %MF_Enabled
Case %WM_ContextMenu
SetFocus Cb.WParam
x = Lo(Integer,Cb.LParam) : y = Hi(Integer, Cb.LParam) 'WM_ContextMenu returns xy coordinates of mouse
TrackPopupMenu hContext, %TPM_LeftAlign, x, y, 0, GetParent(Cb.Hndl), ByVal 0 'put context menu where mouse is
Function = 0 : Exit Function
End Select
Function = CallWindowProc(OldProc, Cb.Hndl, Cb.Msg, Cb.WParam, Cb.LParam)
End Function
Function CreateSuperClass() As Long
Local wc As WNDCLASSEX, OldClassName, NewClassName As String
OldClassName = "Edit"
NewClassName = "SuperEdit"
wc.cbSize = SizeOf(wc)
If GetClassInfoEx(ByVal 0&, ByVal StrPtr(OldClassName), wc) Then
CallWindowProc CodePtr(SuperEditProc), 0, 0, wc.lpfnWndProc, 0 ' pass Winproc pointer to newproc
wc.hInstance = GetModuleHandle(ByVal 0&)
wc.lpszClassName = StrPtr(NewClassName)
wc.lpfnWndProc = CodePtr(SuperEditProc)
Function = RegisterClassEx(wc)
End If
End Function
'gbs_01224
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm