I am making a text editor(just for experience) and I cant find any way to change the font so it shows like notepad
I want to change it to courier new western size 10 so i can view .nfo file designs and such..
I try createfont examples maybe im doing it wrong I add it at WM_INITDIALOG
also please remember I am not using richedit for this I am using a normal edit control
maybe someone already done this and has an example?
As long as you have a valid font handle from CreateFont() or even a predefined system font, you normally only need to use the message WM_SETFONT to change the font in a rich edit control.
does this work in an normal edit control?
Just look up the message WM_SETFONT and you will see where it applies.
thanks I will
I took this as an opportunity to make a procedure that automates the creation of a font by point size. My test code sets the font for an edit control. The procedure seems to work OK, but it is not well tested.
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
MakeFont PROTO :DWORD,:DWORD,:DWORD,:DWORD
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.data
hInstance dd 0
.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
DlgProc proc hDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
LOCAL hwndEdit:DWORD
LOCAL rc:RECT
Switch uMsg
Case WM_INITDIALOG
invoke GetDlgItem,hDlg,101
mov hwndEdit, eax
invoke GetClientRect,hDlg,ADDR rc
invoke MoveWindow,hwndEdit,0,0,rc.right,rc.bottom,TRUE
invoke MakeFont,10,FW_NORMAL,0,chr$("Courier New")
;invoke MakeFont,12,FW_NORMAL,0,chr$("Courier New")
;invoke MakeFont,12,FW_NORMAL,TRUE,chr$("Courier New")
;invoke MakeFont,12,FW_BOLD,0,chr$("Courier New")
;invoke MakeFont,12,FW_BOLD,TRUE,chr$("Courier New")
;invoke MakeFont,12,FW_NORMAL,TRUE,chr$("WingDings")
invoke SendMessage,hwndEdit,WM_SETFONT,eax,TRUE
Case WM_CLOSE
invoke EndDialog,hDlg,0
Endsw
xor eax, eax
ret
DlgProc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
invoke GetModuleHandle, NULL
mov hInstance, eax
Dialog "Test", \
"MS Sans Serif",10, \
WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \
1,0,0,120,90,1024
DlgEdit ES_MULTILINE or ES_WANTRETURN,0,0,0,0,101
CallModalDialog hInstance,0,DlgProc,NULL
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
; This is a modification of the MakeFont procedure from the MASM32
; examples, with the height and width specifications replaced with
; a point size specification.
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
MakeFont proc pointSize:DWORD,weight:DWORD,italic:DWORD,lpFontName:DWORD
invoke GetDC, 0
invoke GetDeviceCaps,eax,LOGPIXELSY
mul pointSize
xor edx, edx
mov ecx, 72
div ecx
invoke CreateFont,eax,0,NULL,NULL,weight,italic,NULL,NULL,
DEFAULT_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,DEFAULT_PITCH or FF_DONTCARE,
lpFontName
ret
MakeFont endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
Here's another *maybe related* idea... Have a play with CreateFontIndirect if personal or just for practice. Should be able to expand.
http://www.masm32.com/board/index.php?PHPSESSID=30de85c24589c10e73c1cc7e8e2bdb84&topic=3835.0
I use it something like this trying to match actual font size ...
; ..................................... hFont_Editor 10 pt
mov esi, offset sz_Editor_Font
mov edi, offset lf.lfFaceName
mov ecx, Sizeof sz_Editor_Font ;13
rep movsb
mov if.lfHeight,-21 ;;; -22 ;;-18
mov lf.lfWidth, -9
mov lf.lfWeight, 600
PUSH offset lf
CALL CreateFontIndirectA
mov hFont_Editor_10, eax
thanks :cheekygreen:
great!
works perfect on normal edit and rich edit I just found out normal edit controls dont display those extra chars .nfo's display
I got to use a rich edit oh well rich edits have many more advantages over normal edits.