Date: 02-16-2022
Return to Index
created by gbSnippets
'Often the lParam/wParam message arguments are pointers to a structure
'where the structure varies with the message involved. Here's how to
'use structures, depending on whether the structure is sent with the
'message or returned by the message.
'Primary Code:
'When a structure is sent with a message:
Local P as CharRange 'define a variable as the stucture type
P.cpMin = 2 : P.cpMax = 17 'set the structure values
Control Send hDlg, %ID_TextBox, %EM_ExSetSel, 0, VarPTR(P) 'use a pointer to the structure in the message
'Note the use of VARPTR to create the pointer. To pass pointers to string variables, use the STRPTR function.
'Compilable Example: (Jose Includes)
'This demonstrates how to use a pointer to pass a CharRange structure within the
'lParam argument of a %EM_ExSetSel message, which selects text in the RichEdit control.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "RichEdit.inc"
#Include "CommCtrl.inc"
Global hDlg as DWord, hRichEdit as DWord
%ID_RichEdit = 500 : %IDC_Button = 501
Function PBMain() As Long
Dialog New Pixels, 0, "Pointer Test Code",300,300,220,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Push to select text", 30,10,180,20
LoadLibrary("riched32.dll")
Call InitCommonControls
Control Add "RichEdit", hDlg, %ID_RichEdit, "This is sample text", 20, 40, 180, 100, _
%WS_Child Or %WS_Visible Or %ES_MultiLine Or %WS_VScroll Or %ES_AutoHScroll _
Or %WS_HScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %ES_NoHideSel Or %WS_TabStop, _
%WS_Ex_ClientEdge
Control Handle hDlg, %ID_RichEdit To hRichEdit
SendMessage hRichEdit, %EM_SETEVENTMASK, 0, %ENM_SELCHANGE Or %ENM_CHANGE Or %ENM_LINK
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = %IDC_Button AND CB.Ctlmsg = %BN_Clicked Then
Local P as CharRange
P.cpMin = 2 : P.cpMax = 17
Control Send hDlg, %ID_RichEdit, %EM_ExSetSel, 0, VarPTR(P)
End If
End Function
'gbs_00079
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm