EditorGadget - Automatischer Zeileneinzug
Verfasst: 16.11.2009 23:30
Da ich es kürzlich brauchte wollte ich es mal online stellen.
Code: Alles auswählen
Enumeration
#Window
#RichEdit
EndEnumeration
Procedure RichEditCallback(hWnd, uMsg, wParam, lParam)
Protected Range.CHARRANGE
Protected PrevLine.l
Protected PrevLineContent.s
Protected Indent.s
Protected *Pointer.Character
If uMsg = #WM_CHAR And wParam = #CR
SendMessage_(hWnd, #EM_EXGETSEL, 0, @Range)
PrevLine = SendMessage_(hWnd, #EM_EXLINEFROMCHAR, 0, Range\cpMin) - 1
PrevLineContent = GetGadgetItemText(#RichEdit, PrevLine)
*Pointer = @PrevLineContent
Indent = ""
While *Pointer\c And (*Pointer\c = 9 Or *Pointer\c = 32)
Indent + Chr(*Pointer\c)
*Pointer + SizeOf(Character)
Wend
SendMessage_(hWnd, #EM_REPLACESEL, 0, @Indent)
ProcedureReturn 0
EndIf
ProcedureReturn CallWindowProc_(GetWindowLongPtr_(hWnd, #GWLP_USERDATA), hWnd, uMsg, wParam, lParam)
EndProcedure
If OpenWindow(#Window, 0, 0, 500, 350, "Auto-Indent in a EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(#RichEdit, 10, 10, 480, 330)
SetActiveGadget(#RichEdit)
SetWindowLongPtr_(GadgetID(#RichEdit), #GWLP_USERDATA, SetWindowLongPtr_(GadgetID(#RichEdit), #GWLP_WNDPROC, @RichEditCallback()))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf