Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change the text font in the function ShowText
#6
As an alternative you can use this
 uses QM_DlgInfo control instead of richedit .It is scintilla based 
Function ShowText4
 
Code:
Copy      Help
function# $caption $text [hwndowner] [~FontName] [FontSize] [flags]
;;flags: 2 QM-format

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 406 296 ""
;3 QM_DlgInfo 0x54000004 0x0 0 0 406 296 ""
;4 Button 0x54000001 0x4 0 161 0 0 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" "3"

str controls = "0 3"
str title qmdi3
title=iif(empty(caption) "QM Textbox" caption)
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc v
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,SetFocus(id(4 hDlg))    
,int chwnd=id(3 hDlg)
,if(!empty(FontName))
,,sub.QmDlgInfoControlSetFont chwnd FontName FontSize
,;set text after changing font
,if(flags&2)
,,str s=F"<><code>{text}</code>"
,else
,,s=text
,s.setwintext(chwnd)
,SendMessage chwnd SCI.SCI_USEPOPUP 0 0
,SendMessage chwnd SCI.SCI_SETMARGINTYPEN 0 SCI.SC_MARGIN_NUMBER
,int-- lnm=SendMessage(chwnd SCI.SCI_TEXTWIDTH SCI.STYLE_LINENUMBER F"_{numlines(text)}")
,SendMessage chwnd SCI.SCI_SETMARGINWIDTHN 0 0
,case WM_CONTEXTMENU
,sel GetDlgCtrlID(wParam)
,,case 3
,,int gmw=SendMessage(wParam SCI.SCI_GETMARGINWIDTHN 0 0)
,,str shText=iif(gmw=0 "Show" "Hide") 
,,sel ShowMenu(F"1 Copy[]2 Paste[]3 {shText} Line Numbers" hDlg)
,,,case 1 SendMessage wParam SCI.SCI_COPY 0 0
,,,case 2 SendMessage wParam SCI.SCI_PASTE 0 0
,,,case 3
,,,sel gmw
,,,,case 0
,,,,SendMessage wParam SCI.SCI_SETMARGINWIDTHN 0 lnm            
,,,,case else
,,,,SendMessage wParam SCI.SCI_SETMARGINWIDTHN 0 0
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

#sub QmDlgInfoControlSetFont
function hwnd [$fontName] [fontSize]

;Changes font of control of class QM_DlgInfo.
;Call on WM_INITDIALOG. Set control text after.

;hwnd - control handle.
;fontName - font name, or 0 to not change.
;fontSize - font size, or 0 to not change.


int h=hwnd
if(!empty(fontName)) SendMessage(h SCI.SCI_STYLESETFONT 32 fontName)
if(fontSize) SendMessage(h SCI.SCI_STYLESETSIZE 32 fontSize)

;save <code> styles
type __QDISTYLE colText colBack !bold !italic !underline !eol
ARRAY(__QDISTYLE) a.create(32)
int i
for i 1 18
,__QDISTYLE& r=a[i]
,r.colText=SendMessage(h SCI.SCI_STYLEGETFORE i 0)
,r.colBack=SendMessage(h SCI.SCI_STYLEGETBACK i 0)
,r.bold=SendMessage(h SCI.SCI_STYLEGETBOLD i 0)
,r.italic=SendMessage(h SCI.SCI_STYLEGETITALIC i 0)
,r.underline=SendMessage(h SCI.SCI_STYLEGETUNDERLINE i 0)
,r.eol=SendMessage(h SCI.SCI_STYLEGETEOLFILLED i 0)

;set other styles the same as the default style 32. It clears <code> styles etc, that is why we save/restore them.
SendMessage(h SCI.SCI_STYLECLEARALL 0 0)

;restore
for i 1 18
,&r=a[i]
,SendMessage(h SCI.SCI_STYLESETFORE i r.colText)
,SendMessage(h SCI.SCI_STYLESETBACK i r.colBack)
,SendMessage(h SCI.SCI_STYLESETBOLD i r.bold)
,SendMessage(h SCI.SCI_STYLESETITALIC i r.italic)
,SendMessage(h SCI.SCI_STYLESETUNDERLINE i r.underline)
,SendMessage(h SCI.SCI_STYLESETEOLFILLED i r.eol)
SendMessage(h SCI.SCI_STYLESETVISIBLE 31 0)


call like this
example
Code:
Copy      Help
_s.getmacro("ShowText4")
ShowText4("Test" _s 0 "Microsoft YaHei" 10 2)


Messages In This Thread
RE: Change the text font in the function ShowText - by Kevin - 01-15-2023, 04:23 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)