Jump to content

Recommended Posts

Posted

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

 

Posted (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 by Dan_555

Some of my script sourcecode

Posted

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...

Posted (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 by Nine
Posted

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..

Posted (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 by Nine
  • Solution
Posted (edited)

Here to reset consolas when it gets deleted :

#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 by Nine
better code
Posted (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 by TheAutomator

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...