Posts: 1,031
Threads: 246
Joined: Jul 2022
01-10-2023, 01:08 AM
(This post was last modified: 01-10-2023, 01:09 AM by Davider.)
Hi,
I want to change the text font and font size in the function ShowText, I added the code below, but it doesn't work
__Font- f.Create("Microsoft YaHei Mono" 12 0); f.SetDialogFont(hDlg "3")
Thanks in advance for any advice and help
david
Function ShowText2
/Dialog_Editor
;function# $caption $text [hwndOwner] [flags] ;;flags: 1 modeless, 2 QM-format, 4 text is file.
str caption
str s.getmacro()
str text=s
int flags=2
int hwndOwner=0
str dd=
;BEGIN DIALOG
;2 "" 0x90CF0A48 0x100 0 0 350 220 ""
;3 RichEdit20W 0x54200844 0x4 0 0 350 220 ""
;2 Button 0x54000001 0x4 0 161 0 0 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "" "" "" ""
str controls = "0 3"
str Dlg Edit3
Dlg=iif(empty(caption) "QM Textbox" caption)
if(flags&4) Edit3.from("&" text); else Edit3=text
ret ShowDialog(dd &sub.DlgProc &controls hwndOwner flags&1 0 0 flags)
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,__Font- f.Create("Microsoft YaHei Mono" 12 0); f.SetDialogFont(hDlg "3") ;;Changing the font has no effect
,
,SetFocus(id(2 hDlg))
,int flags=DT_GetParam(hDlg)
,if(flags&2) SendMessage(_hwndqm WM_USER+26 flags id(3 hDlg))
,
,case WM_COMMAND
,sel wParam
,,case [IDOK,IDCANCEL] DT_Cancel hDlg
,ret 1
,
,case WM_SIZE
,RECT r; GetClientRect(hDlg &r)
,MoveWindow(id(3 hDlg) 0 0 r.right r.bottom 1)
Posts: 1,336
Threads: 61
Joined: Jul 2006
01-10-2023, 05:17 AM
(This post was last modified: 01-10-2023, 02:42 PM by Kevin.)
use this for showtext with different font and size
Function ShowText3
;/
function# $caption $text [hwndowner] [flags]
;Everything is the same as with <tip "#ShowText">ShowText</tip>, except:
;;;flag 1 (nonmodal) unavailable.
opt waitmsg 1
int i he=id(3 ShowText(caption text hwndowner flags|1))
CHARFORMAT cf.cbSize=sizeof(CHARFORMAT)
cf.dwMask=CFM_FACE|CFM_SIZE
strncpy(&cf.szFaceName "Courier New" 12);; change font and size
long twips= 12*20;; change 1st number to match font size above
cf.yHeight=twips ;;twips
SendMessage he EM_SETCHARFORMAT SCF_ALL &cf
rep
,0.01
,if(!IsWindow(he)) break
ret
Posts: 1,031
Threads: 246
Joined: Jul 2022
01-10-2023, 06:48 AM
(This post was last modified: 01-10-2023, 06:52 AM by Davider.)
Thanks for your help
strncpy(&cf.szFaceName "Microsoft YaHei Mono" 10);; change font and size
The font display effect is not the same as in the QM code editor, ( Each character is not the same width)
Posts: 1,336
Threads: 61
Joined: Jul 2006
01-10-2023, 02:41 PM
(This post was last modified: 01-10-2023, 02:42 PM by Kevin.)
did you change the 1st number in twips to the same as your font size? I forgot to add instructions corrected above.
Posts: 1,031
Threads: 246
Joined: Jul 2022
Still no effect
strncpy(&cf.szFaceName "Microsoft YaHei Mono" 10);; change font and size
long twips= 10*20;; change 1st number to match font size above
Posts: 1,336
Threads: 61
Joined: Jul 2006
01-15-2023, 04:23 AM
(This post was last modified: 01-15-2023, 04:24 AM by Kevin.)
As an alternative you can use this
uses QM_DlgInfo control instead of richedit .It is scintilla based
Function ShowText4
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
_s.getmacro("ShowText4")
ShowText4("Test" _s 0 "Microsoft YaHei" 10 2)
Posts: 1,031
Threads: 246
Joined: Jul 2022
kevin
The text displayed in the ShowText4 dialog box is read-only. Can i modify the text?
|