TheAutomator Posted March 2, 2025 Posted March 2, 2025 Ok, try this: run script, CTRL+A, start typing something.. now close, run again, type something but no do CTRL+A... Why can't I set the default font and color of the edit correctly? #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> $Form = GUICreate('MiniText', 300, 400, Default, Default, BitOR($WS_SYSMENU,$WS_POPUP)) GUISetBkColor(0x000000) $edit = _GUICtrlRichEdit_Create($Form, '', 0, 0, 300, 400, -1, 0) _GUICtrlRichEdit_SetFont($edit, 12, "consolas") _GUICtrlRichEdit_SetCharColor($edit, 0xffffff) _GUICtrlRichEdit_SetBkColor($edit, 0x202020) _GUICtrlRichEdit_SetRECT($edit, 20, 20, 280, 380) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($Edit) ; needed unless script crashes Exit EndSwitch WEnd Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone MiniMark Editor
Dan_555 Posted March 3, 2025 Posted March 3, 2025 (edited) The colors that you need to provide is in this format: Alpha, blue, green, red _GUICtrlRichEdit_SetCharColor($edit, 0x0000ff00)) you can read it in the help file of _GUICtrlRichEdit_SetCharColor under remarks: "If you need to create a COLORREF value from an color array use _ColorSetCOLORREF() not _ColorSetRGB()." As for the font, maybe try this solution ? : Edited March 3, 2025 by Dan_555 Some of my script sourcecode
MattyD Posted March 3, 2025 Posted March 3, 2025 Just some wild speculation... The rtf format is basically just a markup - so you can paste this into a text doc, save as an rtf, and you get "aaa" {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang3081{\fonttbl{\f0\fnil\fcharset0 Calibri;}} {\*\generator Riched20 10.0.22621}\viewkind4\uc1 \pard\sa200\sl276\slmult1\f0\fs22\lang9 aaa\par } So I'm guessing if we just start typing, we might kick off a paragraph - or something that is bound to a color palate. But if we do an initial ctrl-A, I suspect we either don't commit this block where the formatting is defined, or we somehow end up before it. EM_SETTEXTEX may help to test this theory, it seems like you may be able to write some of the underlying RTF with that message...
Nine Posted March 3, 2025 Posted March 3, 2025 (edited) My take is that ctrl-a is also grabbing your font/color definitions. As a proof, type something, do ctrl-a, ctrl-c and paste it in WordPad. It will copy everything (text and definitions). Identically if you type something do a ctrl-a, press del, you will also loose all your font/color definitions. So when you first start with a ctrl-a and start typing it is just as if you deleted all your definitions... Before delete : {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang3084{\fonttbl{\f0\fnil\fcharset0 consolas;}{\f1\fnil\fcharset0 MS Shell Dlg;}{\f2\fnil\fcharset0 Calibri;}} {\colortbl ;\red255\green0\blue0;} {\*\generator Riched20 10.0.19041}\viewkind4\uc1 \pard\cf1\f0\fs22 test\cf0\f1\fs17\par \pard\sa200\sl276\slmult1\f2\fs22\lang12\par } After delete : {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang3084{\fonttbl{\f0\fnil\fcharset0 MS Shell Dlg;}{\f1\fnil\fcharset0 Calibri;}} {\*\generator Riched20 10.0.19041}\viewkind4\uc1 \pard\f0\fs17 test\par \pard\sa200\sl276\slmult1\f1\fs22\lang12\par } Edited March 3, 2025 by Nine “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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
TheAutomator Posted March 3, 2025 Author Posted March 3, 2025 Thanks for the comments! I'm using sticky notes classic, and whatever you do over there, it manages to keep it's default comic sans font. The link to that other topic only helps for setting the font, not the color. I was thinking about looking for a way to detect when the user makes the whole edit empty maybe? but that slows down the code a lot I guess.. Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone MiniMark Editor
Nine Posted March 3, 2025 Posted March 3, 2025 (edited) 1 hour ago, TheAutomator said: The link to that other topic only helps for setting the font, not the color It is just a wrapper to create in a standardized way a rich edit. You can add color to the wrapper if you want to. Another solution, you could simply block ctrl-a ? Edited March 3, 2025 by Nine TheAutomator 1 “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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Solution Nine Posted March 3, 2025 Solution Posted March 3, 2025 (edited) Here to reset consolas when it gets deleted : expandcollapse popup#include <GUIConstants.au3> #include <GuiRichEdit.au3> Opt("MustDeclareVars", True) Global $idEdit Example() Func Example() Local $hForm = GUICreate('MiniText', 300, 400, Default, Default, $WS_POPUP) GUISetBkColor(0) $idEdit = _GUICtrlRichEdit_Create($hForm, '', 0, 0, 300, 400, -1, 0) SetRichEdit($idEdit) GUISetState() GUIRegisterMsg($WM_COMMAND, WM_COMMAND) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _GUICtrlRichEdit_Destroy($idEdit) EndFunc ;==>Example Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) If $idEdit = $lParam And _GUICtrlRichEdit_GetFont($lParam)[1] <> "consolas" Then SetRichEdit($lParam) Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func SetRichEdit($idCtrl) _GUICtrlRichEdit_SetFont($idCtrl, 12, "consolas") _GUICtrlRichEdit_SetCharColor($idCtrl, 0xffffff) _GUICtrlRichEdit_SetBkColor($idCtrl, 0x202020) _GUICtrlRichEdit_SetRECT($idCtrl, 20, 20, 280, 380) EndFunc ;==>SetRichEdit Edited March 4, 2025 by Nine better code TheAutomator 1 “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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
TheAutomator Posted March 4, 2025 Author Posted March 4, 2025 (edited) 19 hours ago, Nine said: It is just a wrapper to create in a standardized way a rich edit. You can add color to the wrapper if you want to. Another solution, you could simply block ctrl-a ? That... is simple and brilliant at first glance, didn't think about that unfortunately you have many other ways to select everything Edited March 4, 2025 by TheAutomator Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone MiniMark Editor
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