mike1950r Posted June 16, 2021 Share Posted June 16, 2021 Hi, I've searching for a while to solve this. I found also other people searching a possibility to setup a permanent (say default) font for RichEdit Control. In fact a default font is set for RichEdit Control, but it is limited to some StockObject Fonts, which are not satisfying. You can see this fonts under:https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_GetStockObject.htm The line where the font is defined in the _GUICtrlRichEdit_Create function is: _SendMessage($hRichEdit, $__RICHEDITCONSTANT_WM_SETFONT, _WinAPI_GetStockObject($DEFAULT_GUI_FONT), True) _WinAPI_GetStockObject($DEFAULT_GUI_FONT) gets the handle to the preselected RichEdit default font $DEFAULT_GUI_FONT. My question is how can i get the font handle (for example used by notepad) which replaces this RichEdit default font. Sounds easy, but so far I did not come further... Thanks for assistance. Cheers mike Link to comment Share on other sites More sharing options...
Solution Nine Posted June 16, 2021 Solution Share Posted June 16, 2021 (edited) You could wrap a function around like this : #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> #include <WinAPIGdi.au3> #include <FontConstants.au3> Example() Func Example() Local $hGui, $hRichEdit, $iMsg $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1) $hRichEdit = _GUICtrlRichEdit_CreateEx($hGui, "This is a test.", 10, 10, 300, 220, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) _GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & "This is more text") GUISetState(@SW_SHOW) While True $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes ; GUIDelete() ; is OK too Exit EndSelect WEnd EndFunc ;==>Example Func _GUICtrlRichEdit_CreateEx($hWnd, $sText, $iLeft, $iTop, $iWidth = 150, $iHeight = 150, $iStyle = -1, $iExStyle = -1) Local $hCtrl = _GUICtrlRichEdit_Create($hWnd, $sText, $iLeft, $iTop, $iWidth, $iHeight, $iStyle, $iExStyle) If @error Then Return SetError(@error) Local $hFont = _WinAPI_CreateFont(20, 0, 0, 0, 600, False, False, False, $DEFAULT_CHARSET, _ $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial') _SendMessage($hCtrl, $WM_SETFONT, $hFont, True) _WinAPI_DeleteObject($hFont) Return $hCtrl EndFunc Where you would have the definition of the font standardized... Edited June 16, 2021 by Nine pixelsearch, Musashi and mike1950r 3 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
mike1950r Posted June 16, 2021 Author Share Posted June 16, 2021 Thanks lot Nine, works exellent. I wonder why this is not implented. The other way setting the font is just not working satisfying. BTW I use 10, Lucida Console but have to setup 13, Lucida Console if I setup with the _Send function. $hFont = _WinAPI_CreateFont(13, 0, 0, 0, $FW_NORMAL, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Lucida Console') _SendMessage($hWnd, $WM_SETFONT, $hFont, True) _WinAPI_DeleteObject($hFont) Anyway, thanks again Cheers mike Link to comment Share on other sites More sharing options...
Nine Posted June 16, 2021 Share Posted June 16, 2021 Glad it is working for you. I agree it could be a feature to add into the UDF. You can submit this proposal into Bug Tracker. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Musashi Posted June 16, 2021 Share Posted June 16, 2021 44 minutes ago, mike1950r said: Thanks lot Nine, works exellent. I wonder why this is not implented. Aside : My opinion regarding the new feature of the 'Solved Counter' is somewhat ambivalent, frankly speaking. However, since this feature is now in place, and likely to remain, it should be used to make sense of it. @mike1950r : As @Nine 's contribution obviously solved your problem, you can mark it accordingly, if you like . JockoDundee 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
mike1950r Posted June 16, 2021 Author Share Posted June 16, 2021 Nine, why is there a height difference between _SendMessage($hWnd, $WM_SETFONT, $hFont, True) and _GUICtrlRichEdit_SetFont($hWnd, 10, "Lucida Console") of 3. In SendMessage(.. I must set 13 instead of 10. Thanks for advice. Cheers mike Link to comment Share on other sites More sharing options...
Nine Posted June 16, 2021 Share Posted June 16, 2021 It is because they both sending different messages to the control. _GUICtrlRichEdit_SetFont uses $EM_SETCHARFORMAT message and does a different calculation to determine the size of the font. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
mike1950r Posted June 17, 2021 Author Share Posted June 17, 2021 Nine, thanks for the info. so i have modified my function respecting this difference of 3. Func WindowEditSetDefaultFont($hWnd, $iPoints, $sName) Local $hFont $hFont = _WinAPI_CreateFont($iPoints + 3, 0, 0, 0, $FW_NORMAL, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, $sName) _SendMessage($hWnd, $WM_SETFONT, $hFont, True) _WinAPI_DeleteObject($hFont) EndFunc ;==>WindowEditSetDefaultFont All the best and thanks for all. Cheers mike Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now