@wilbert also has trick to embed nicely formatted RTF-files this way, but I found regular txt-files "enough for everyone" for now ^^
Code: Select all
EnableExplicit
;{ ReadMe window }
; This code packs readme.txt into executable on compilation stage
; and shows it's content when function is called while program running
Global WndAbout, TxtAbout
; separated ReadMe window callbacks
Procedure ReadmeSize()
ResizeGadget(TxtAbout, 0, 0, WindowWidth(WndAbout), WindowHeight(WndAbout))
EndProcedure
Procedure ReadmeClose()
UnbindEvent(#PB_Event_CloseWindow, @ReadmeClose(), WndAbout)
UnbindEvent(#PB_Event_SizeWindow, @ReadmeSize(), WndAbout)
CloseWindow(WndAbout)
EndProcedure
; Use following function to display ReadMe window
; W, H window sizes
; FontName$, FontSize font params to use
; RETURN: none, ReadMe window is created or activated if already exists
Procedure ReadMe(Title$, W = 640, H = 480, FontName$ = "Consolas", FontSize = 9)
DataSection
lblAboutMe:
IncludeBinary "res\ReadMe.txt" ; set here path to your readme.txt
Data.i 0
EndDataSection
; only activate window if About dialog already exists
If IsWindow(WndAbout)
SetActiveWindow(WndAbout)
ProcedureReturn
EndIf
Protected AboutData$ = PeekS(?lblAboutMe + 3, -1, #PB_UTF8) ; for utf-8 ignoring 1st byte
WndAbout = OpenWindow(#PB_Any, 0, 0, W, H, Title$, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_WindowCentered)
TxtAbout = EditorGadget(#PB_Any, 0, 0, W, H, #PB_Editor_ReadOnly | #PB_Editor_WordWrap)
Protected hFont = LoadFont(#PB_Any, FontName$, FontSize)
If IsFont(hFont)
SetGadgetFont(TxtAbout, FontID(hFont))
FreeFont(hFont)
EndIf
ClearGadgetItems(TxtAbout)
AddGadgetItem(TxtAbout, -1, AboutData$)
BindEvent(#PB_Event_CloseWindow, @ReadmeClose(), WndAbout)
BindEvent(#PB_Event_SizeWindow, @ReadmeSize(), WndAbout)
EndProcedure
;}
; usage:
; 1. Set path to your readme file at data section
; 2. Add code to your program
; 3. Call ReadMe() function to display content of readme file in separated window
;
; ReadMe window doesn't interact with other windows, just do the EventWindow() check
; inside you main loop, to avoid messages of ReadMe window. And use CloseWindow (#PB_All)
; at program quit (that's important for DLLs)
; example
OpenWindow(1, 0, 0, 800, 80, "THIS IS MAIN PROGRAM WINDOW")
ReadMe("About")
Repeat
Define Event = WaitWindowEvent(1)
If EventWindow() = 1 ; do this to ignore ReadMe window events
If Event = #PB_Event_CloseWindow
Break
EndIf
EndIf
ForEver
CloseWindow(#PB_All)