Date: 02-16-2022
Return to Index
created by gbSnippets
'Compiler Comments:
'This code is written to compile with PBWin10. To compile with PBWin9,
'add this line:
#Include "CommCtrl.inc"
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "RichEdit.inc"
%IDC_RichEdit = 500
%IDC_Button = 501
Global hDlg,hRichEdit As Dword, OldProc&, CR As CharRange
Function PBMain() As Long
Local style&, buf$
buf$ = "This is sample" + $CrLf + "text for the" + $CrLf + "rich edit control."
style& = %WS_Child Or %WS_Visible Or %ES_MultiLine Or %WS_VScroll Or %ES_AutoHScroll _
Or %WS_HScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %WS_TabStop 'or %ES_NoHideSel
Dialog New Pixels, 0, "Test Code",300,300,200,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Push", 30,10,140,20
LoadLibrary("riched32.dll") : InitCommonControls
Control Add "RichEdit", hDlg, %IDC_RichEdit, buf$,20,40,160,100, style&
Control Handle hDlg, %IDC_RichEdit To hRichEdit
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
OldProc& = SetWindowLong(GetDlgItem(hDlg, 500), %GWL_WndProc, CodePtr(NewProc)) 'subclass
Case %WM_Destroy
SetWindowLong hRichEdit, %GWL_WNDPROC, OldProc& 'un-subclass
End Select
End Function
Function NewProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case %WM_SetFocus
Dialog Set Text hDlg, "got focus"
SendMessage hRichEdit, %EM_ExSetSel, 0,VarPtr(CR)
Case %WM_KillFocus
Dialog Set Text hDlg, "lost focus"
SendMessage hRichEdit, %EM_ExGetSel,0,VarPtr(CR)
End Select
Function = CallWindowProc(OldProc&, hWnd, Msg, wParam, lParam)
End Function
'gbs_01064
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm