*Edit* / i cleared this tread abit up so it more readable, i had had just a littel to much drink yesterday. :roll:
The Code posted here is El_Choni's, i changed a variable or 2, it's a bad hack cuz i don't know what i'm doing, really,
maybe, El_Choni have found a better solution - the PB editor works- sooo ?
/*Edit*
Now, i knew that i couldn't sleep with the stupid hack i gave you, so i had to look at it once more
First i added #WS_HSCROLL
then text in the editor needs to be 10 Height, if you paste text in the editor.
you still need to check for the users FontMetrics
I don't know now why the changes works ??, but it does on my end
Line 87
Code: Select all
;-------------
;Changed
;===============================
lfnt\lfHeight = -13
;===============================
Line 99
Code: Select all
;-------------
;Changed
;========================================================
cf\yHeight=(-lfnt\lfHeight)*15; if user uses BigFonts *13
;========================================================
the whole code ps. you need the "Procedure SmallFonts()"
Code: Select all
#RICHEDIT = #WS_CHILD|#WS_VISIBLE|#WS_VSCROLL|#WS_HSCROLL|#ES_MULTILINE|#ES_AUTOVSCROLL|#ES_NOHIDESEL
#WINDOW_PARAMETERS = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_MaximizeGadget
Global RichEditID, hWindow, WindowWidth, WindowHeight
Global hLnFont, rc.RECT, FontHeight, buffer.s, OldRedProc
Procedure Error(message.s, fatal.b)
Mem=AllocateMemory(256)
FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError_(), 0, Mem, 256, 0)
; MessageRequester("Error", message+Chr(10)+Chr(10)+PeekS(MemoryID()), 0)
FreeMemory(Mem)
If fatal
End
EndIf
EndProcedure
Procedure DrawLineNumbers()
hDC = GetDC_(RichEditID)
OldObject = SelectObject_(hDC, hLnFont)
lineno = SendMessage_(RichEditID, #EM_GETFIRSTVISIBLELINE, 0, 0)+1
GetClientRect_(RichEditID, rc)
rc\right = 28
FillRect_(hDC, rc, GetStockObject_(#GRAY_BRUSH))
SetBkMode_(hDC, #TRANSPARENT)
SetTextColor_(hDC, $0FFFF)
lastline = WindowHeight/FontHeight+lineno
While lineno<lastline
buffer = Str(lineno)
DrawText_(hDC, @buffer, -1, rc, #DT_RIGHT)
rc\top+FontHeight
lineno+1
Wend
MoveToEx_(hDC, rc\right, 0, #NULL)
LineTo_(hDC, rc\right, rc\bottom)
SelectObject_(hDC, OldObject)
ReleaseDC_(RichEditID, hDC)
EndProcedure
Procedure RedProc(hWnd, uMsg, wParam, lParam)
Select uMsg
Case #WM_PAINT
CallWindowProc_(OldRedProc, hWnd, uMsg, wParam, lParam)
DrawLineNumbers()
result = 0
Default
result = CallWindowProc_(OldRedProc, hWnd, uMsg, wParam, lParam)
EndSelect
ProcedureReturn result
EndProcedure
Procedure WndProc(hWnd, uMsg, wParam, lParam)
result = #PB_ProcessPurebasicEvents
Select uMsg
Case #WM_SIZE
If hWnd=hWindow And wParam<>#SIZE_MINIMIZED
WindowWidth = lParam&$ffff
WindowHeight = lParam>>16
MoveWindow_(RichEditID, 0, 0, WindowWidth, WindowHeight, 1)
EndIf
EndSelect
ProcedureReturn result
EndProcedure
hWindow = OpenWindow(0, 0, 0, 640, 480, #WINDOW_PARAMETERS, "RichEdit line numbers example")
If hWindow
SetClassLong_(hWindow, #GCL_HBRBACKGROUND, 0) ; remove resize flicker
If LoadLibrary_("RICHED20.DLL")
RichClass.s = "RichEdit20A"
ElseIf LoadLibrary_("RICHED32.DLL")
RichClass.s = "RichEdit"
Else
Error("RichEdit library not present.", 0)
End
EndIf
WindowWidth = WindowWidth()
WindowHeight = WindowHeight()
RichEditID = CreateWindowEx_(#WS_EX_CLIENTEDGE, RichClass, 0, #RICHEDIT, 0, 0, WindowWidth, WindowHeight, hWindow, 0, GetModuleHandle_(0), 0)
If RichEditID
SendMessage_(RichEditID, #EM_GETRECT, 0, rc)
rc\left+32
SendMessage_(RichEditID, #EM_SETRECT, 0, rc)
lfnt.LOGFONT
cf.CHARFORMAT
FontName.s = "Courier New"
lstrcpy_(@lfnt\lfFaceName[0], @FontName)
lstrcpy_(@cf\szFaceName[0], @FontName)
;-------------
;Changed
;===============================
lfnt\lfHeight = -13
;===============================
lfnt\lfWeight = 400
hLnFont = CreateFontIndirect_(lfnt)
hFont = CreateFontIndirect_(lfnt)
cf\cbSize = SizeOf(CHARFORMAT)
cf\dwMask = #CFM_FACE|#CFM_SIZE
;-------------
;Changed
;========================================================
cf\yHeight=(-lfnt\lfHeight)*15; if user uses BigFonts *13
;========================================================
SendMessage_(RichEditID, #EM_SETCHARFORMAT, #SCF_SELECTION, cf)
hDC = GetDC_(RichEditID)
OldObject = SelectObject_(hDC, hFont)
GetTextExtentPoint32_(hDC, @"||||", 4, siz.SIZE)
FontHeight = siz\cy
SelectObject_(hDC, OldObject)
ReleaseDC_(RichEditID, hDC)
OldRedProc = SetWindowLong_(RichEditID, #GWL_WNDPROC, @RedProc())
SetWindowCallback(@WndProc())
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_EventCloseWindow
Else
Error("Could not create the RichEdit control.", 0)
End
EndIf
Else
Error("Could not create the main window.", 0)
EndIf
End
*Edit*
The FontMetrics routine, i'm not sure who made it "Think it was Freak" but i have used it in several sources but not the author name, hmm.
Code: Select all
;-Returns 1 if your PC is using small fonts, or 0 if not (eg. large).
Procedure SmallFonts()
SmallFonts=1 : dt=GetDesktopWindow_() : hdc=GetWindowDC_(dt)
If hdc
tm.TEXTMETRIC : PrevMapMode=SetMapMode_(hdc,#MM_TEXT)
GetTextMetrics_(hdc,tm) : PrevMapMode=SetMapMode_(hdc,PrevMapMode)
ReleaseDC_(dt,hdc) : If tm\tmHeight>16 : SmallFonts=0 : EndIf
EndIf
Debug SmallFonts
ProcedureReturn SmallFonts
EndProcedure
good night...
Best regrads
Henrik