Re: Updated Ver 3 : AutoResize EditorGadget [Windows]
Posted: Sat Jul 24, 2010 5:21 pm
I doRASHAD wrote:Ver 3.0
This code as per @MV request
It is not the advanced one
I hope you like it

I've seen, that the resizing does not work, when the window will be invisible, so there's a kind of flicker – no problem for me, because I won't resize the gadget, but typically, I move the cursor to the first line using SendMessage_(GadgetID(1),#EM_SETSEL,0,0)
Here's just one small iteration of the given code, demonstrating how to create nice help dialogs with colors, bold text and more...
Code: Select all
Procedure SetFormat(Gadget,FSize=9,FColor=#Black,FFlags=0)
; SetFormat(Gadget,FSize,FName.s,FColor,FFlags)
#Alignment_Left=0
#Alignment_Center=1
#Alignment_Right=2
Protected FontFormat.CHARFORMAT
Protected FontMask
With FontFormat
\cbSize=SizeOf(CHARFORMAT)
;If Len(FName.s)
; PokeS(@FontFormat\szFaceName,FName.s)
; FontMask|#CFM_FACE
;EndIf
If FSize
\yHeight=FSize*20;1440/72
FontMask|#CFM_SIZE
EndIf
#CFM_LINK=$20
\dwMask=FontMask|#CFM_COLOR|#CFM_ITALIC|#CFM_BOLD|#CFM_STRIKEOUT|#CFM_UNDERLINE|#CFM_LINK
\crTextColor=FColor
\dwEffects=FFlags
SendMessage_(GadgetID(Gadget),#EM_SETCHARFORMAT,#SCF_SELECTION,@FontFormat)
EndWith
EndProcedure
Procedure AddText(Gadget,Text.s,Eol=#True)
If Eol
Text.s+#CR$
EndIf
SendMessage_(GadgetID(Gadget),#EM_REPLACESEL,#True,@Text)
If Eol>1
SetFormat(Gadget,Eol)
Text=#CR$
SendMessage_(GadgetID(Gadget),#EM_REPLACESEL,#True,@Text)
EndIf
SetFormat(Gadget); Einstellungen rücksetzen
EndProcedure
Procedure AddBoldText(Gadget,Text.s,Eol=#True)
Protected Dummy.s
Protected Bold
Repeat
Bold=FindString(Text,#TAB$,1)
If Bold
Dummy=Left(Text,Bold)
Text=Mid(Text,Bold+1)
SetFormat(Gadget,0,0,#CFM_BOLD)
SendMessage_(GadgetID(Gadget),#EM_REPLACESEL,#True,@Dummy)
SetFormat(Gadget,0,0,0)
EndIf
Bold=FindString(Text,#CR$,1)
If Bold
Dummy=Left(Text,Bold)
Text=Mid(Text,Bold+1)
SendMessage_(GadgetID(Gadget),#EM_REPLACESEL,#True,@Dummy)
Else
Break
EndIf
ForEver
AddText(Gadget,Text,Eol)
EndProcedure
Procedure AddParagraph(Gadget,Size=9)
SetFormat(Gadget,Size); Zeilenabstand definieren
AddText(Gadget,""); CR$
SetFormat(Gadget); Einstellungen rücksetzen
EndProcedure
If OpenWindow(0,0,0,500,500,"EditorGadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
EditorGadget(1,10,10,480,412,#PB_Editor_ReadOnly|#Alignment_Left)
#InstanceWindow="Forerunner Training Center"
#TextHeaderColor=$30A030
#TextHeaderSize=11
AddParagraph(1,4)
SetFormat(1,#TextHeaderSize,#TextHeaderColor,#CFM_BOLD)
AddText(1,"INFORMATION",4)
AddText(1,"The "+#InstanceWindow+" is able to read your sport history taken from Garmin"+#CR$+"applications (e.g. Forerunner Training Center) which can be easily adapted using"+#CR$+"the Converter program."+#CR$+#CR$+"To view one of your sport tracks in 3D, choose it from the main dialog and press"+#CR$+"enter. You can rotate the track by using the cursor keys or the mouse and set many"+#CR$+"display options (see shortcuts page). Chosing 'report' from the main dialog generates"+#CR$+"monthly reports which also can exported easily to other programs."+#CR$+#CR$+"The option dialog contains different panels. When changing an option parameter"+#CR$+"followed by an asterisk, the History track is reloaded to take effect. A small circle"+#CR$+"behind a parameter indicates restarting the program is required to take effekt."+#CR$+#CR$+"The "+#InstanceWindow+" has been written by Michael Vogel - hopefully you"+#CR$+"like this program. If you also like puzzles like Sudoku, you can also have a look at")
SetFormat(1,0,0,#CFM_LINK)
AddText(1,"http://sites.google.com/site/mrvogel",12)
SetFormat(1,#TextHeaderSize,#TextHeaderColor,#CFM_BOLD)
AddText(1,"SPORT PROGRAMS",4)
AddBoldText(1,"Training Center:"+#TAB$+"software from Garmin to collect and organize sport tracks"+#CR$+#TAB$+#TAB$+"from GPS sport devices"+#CR$+#TAB$+#TAB$+"(reads '.hst' and '.tcx' files, writes '.hst' or '.tcx' files)"+#CR$+#CR$+"Converter:"+#TAB$+"compresses '.hst' and the large '.tcx' history files and"+#CR$+#TAB$+#TAB$+"converts standard '.gpx' files to '.hst' history files"+#CR$+#CR$+#InstanceWindow+":"+#CR$+#TAB$+#TAB$+"displays tracks and make monthly reports (reads '.hst', '.hsz'"+#CR$+#TAB$+#TAB$+"and '.tcz' files, writes '.hst' and '.gpx' files)",12)
SetFormat(1,#TextHeaderSize,#TextHeaderColor,#CFM_BOLD)
AddText(1,"HISTORY FILE TYPES",4)
AddBoldText(1," .hst"+#TAB$+"old history file of the Garmin Training Center"+#CR$+" .hsz"+#TAB$+"compressed history file"+#CR$+" .tcx"+#TAB$+"new history file of the Garmin Training Center"+#CR$+" .tcz"+#TAB$+"compressed history file"+#CR$+" .gpx"+#TAB$+"standard exchange file format")
SendMessage_(GadgetID(1),#EM_SETSEL,0,0)
SetActiveGadget(1)
;AutoresizeEG(1)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf