Jump to content
AndreyS

Applying styles to RichEdit

Recommended Posts

AndreyS

Please tell me, who knows how to apply and cancel styles in RTF?
The following code does not work:

#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("RichEdit Style", 500, 500, -1, -1)
$hRichEdit = _GUICtrlRichEdit_Create($hGui, "Test", 20,40,460,400)
GUISetState(@SW_SHOW, $hGUI)
Sleep(3000)
GUICtrlSetStyle($hRichEdit, $ES_RIGHT)
Sleep(3000)
GUICtrlSetStyle($hRichEdit, -1)
Sleep(3000)

Thanks!

Share this post


Link to post
Share on other sites
AndreyS

Thank you for your participation, InunoTaishou!
I know that it is possible so to realize. But the problem is not that it is the alignment applied. I need to apply in general any other style, but after the creation of RichEdit.

Share this post


Link to post
Share on other sites
AndreyS

Well, since experts and professionals? Really not apply the styles after creating RichText?

Share this post


Link to post
Share on other sites
czardas

Did you run the help file example for _GUICtrlRichEdit_SetParaAlignment() as suggested by @InunoTaishou ? The paragraphs are aligned after the creation of the rich edit control. If you read the description, it says:

Quote

Sets alignment of paragraph(s) in the current selection

This is the default behaviour when working with an edit control. The user is supposed to select the paragraph that they want to be aligned. You can also select text automatically if you wish, but the complexity of this operation will depend on context.

Share this post


Link to post
Share on other sites
AndreyS

)) Well, I'm saying that the style of alignment is just as an example. Well I wrote: "I need to apply in general any other style"

Okay in this case show how to apply the style $ WS_EX_TRANSPARENT?

Share this post


Link to post
Share on other sites
InunoTaishou
$hRichEdit = _GUICtrlRichEdit_Create($hGui, "Test", 20,40,460,400, Deafult, $WS_EX_TRANSPARENT)

Should work. I don't currently have the time to test it. Most window styles will work with the richedit control. Check out this topic to see what you can do with the richedit

https://msdn.microsoft.com/en-us/library/windows/desktop/bb787605(v=vs.85).aspx

Share this post


Link to post
Share on other sites
AndreyS

Ohhh no! (((( Well, I wrote: " apply the styles after creating RichText?"
I know perfectly all the function and styles of RichEdit! I need to use style AFTER creating it!

It is necessary for me to apply some styles and other styles to cancel during the program.

Edited by AndreyS

Share this post


Link to post
Share on other sites
orbs

@AndreyS,

if you refer to windows styles, then no, you cannot change these styles after the control was created (that is true for any type of control). one workaround you can try is to save the RTF stream, destroy the RichEdit control, create it with the new style, and reload the RTF stream. not tested.

if you refer to text styles, like paragraph direction, color, font size, etc. then you can change them easily at any time, as demonstrated above.

Share this post


Link to post
Share on other sites
InunoTaishou

@orbs You can change the styles of windows after a window has been created (richedit is a window) and you can change the styles of any control after it's been created too

Here's how you would add a the $WS_EX_TRANSPARENT to your richedit control

#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("RichEdit Style", 500, 500, -1, -1)
$hRichEdit = _GUICtrlRichEdit_Create($hGui, "Test", 20,40,460,400)
GUISetState(@SW_SHOW, $hGUI)
MsgBox("", "", "Default")
_WinAPI_SetWindowLong($hRichEdit, $GWL_EXSTYLE, BitOR(_WinAPI_GetWindowLong($hRichEdit, $GWL_EXSTYLE), $WS_EX_TRANSPARENT))
MsgBox("", "", "WS_EX_TRANSPARENT")

If you wanted to change the Style property, not ExStyle, you use $GWL_STYLE.

  • Like 1

Share this post


Link to post
Share on other sites
AndreyS

Oh, here it is the solution! Thank you, InunoTaishou!
Why not make it easier, through a more standard functions (GUICtrlSetStyle, GUISetStyle)?

Share this post


Link to post
Share on other sites
InunoTaishou

Yup, GUISetStyle is a function you could use. I was on lunch and had a brain fart, the only thing I could remember was SetWindowLong lol.

Share this post


Link to post
Share on other sites
AndreyS

Tell me more, please, how to cancel $WS_EX_TRANSPARENT style?

Share this post


Link to post
Share on other sites
InunoTaishou

There's a couple ways you can remove the style. This is the easiest (to understand), just save the default styles when the window is created

#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("RichEdit Style", 500, 500, -1, -1)
$hRichEdit = _GUICtrlRichEdit_Create($hGui, "Test", 20,40,460,400)
$iExStyle = _WinAPI_GetWindowLong($hRichEdit, $GWL_EXSTYLE)
GUISetState(@SW_SHOW, $hGUI)
MsgBox("", "", "Default")
_WinAPI_SetWindowLong($hRichEdit, $GWL_EXSTYLE, BitOR(_WinAPI_GetWindowLong($hRichEdit, $GWL_EXSTYLE), $WS_EX_TRANSPARENT))
MsgBox("", "", "WS_EX_TRANSPARENT added")
_WinAPI_SetWindowLong($hRichEdit, $GWL_EXSTYLE, $iExStyle)
MsgBox("", "", "WS_EX_TRANSPARENT removed")

The other way is to subtract the style

#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("RichEdit Style", 500, 500, -1, -1)
$hRichEdit = _GUICtrlRichEdit_Create($hGui, "Test", 20,40,460,400)
GUISetState(@SW_SHOW, $hGUI)
MsgBox("", "", "Default")
_WinAPI_SetWindowLong($hRichEdit, $GWL_EXSTYLE, BitOR(_WinAPI_GetWindowLong($hRichEdit, $GWL_EXSTYLE), $WS_EX_TRANSPARENT))
MsgBox("", "", "WS_EX_TRANSPARENT added")
_WinAPI_SetWindowLong($hRichEdit, $GWL_EXSTYLE, _WinAPI_GetWindowLong($hRichEdit, $GWL_EXSTYLE) - $WS_EX_TRANSPARENT)
; Or use the BitXO operation
; _WinAPI_SetWindowLong($hRichEdit, $GWL_EXSTYLE, BitXOR(_WinAPI_GetWindowLong($hRichEdit, $GWL_EXSTYLE), $WS_EX_TRANSPARENT))
MsgBox("", "", "WS_EX_TRANSPARENT removed")

Or, some easy to use functions

#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("RichEdit Style", 500, 500, -1, -1)
$hRichEdit = _GUICtrlRichEdit_Create($hGui, "Test", 20,40,460,400)
GUISetState(@SW_SHOW, $hGUI)
MsgBox("", "", "Default")
GUIAddExStyle($hRichEdit, $WS_EX_TRANSPARENT)
MsgBox("", "", "WS_EX_TRANSPARENT added")
GUIRemoveExStyle($hRichEdit, $WS_EX_TRANSPARENT)
MsgBox("", "", "WS_EX_TRANSPARENT removed")

Func GUIAddStyle($hWnd, $iStyle)
    Return _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitOR(_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), $iStyle))
EndFunc

Func GUIRemoveStyle($hWnd, $iStyle)
    Return _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitXOR(_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), $iStyle))
EndFunc

Func GUIAddExStyle($hWnd, $iExStyle)
    Return _WinAPI_SetWindowLong($hWnd, $GWL_EXSTYLE, BitOR(_WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE), $iExStyle))
EndFunc

Func GUIRemoveExStyle($hWnd, $iExStyle)
    Return _WinAPI_SetWindowLong($hWnd, $GWL_EXSTYLE, BitXOR(_WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE), $iExStyle))
EndFunc

 

Edited by InunoTaishou
  • Like 1

Share this post


Link to post
Share on other sites
AndreyS

Wow! How many variants written! :)
Thank you very much, InunoTaishou! You helped me a lot!

Share this post


Link to post
Share on other sites
orbs
On 1/10/2017 at 8:31 PM, InunoTaishou said:

You can change the styles of windows after a window has been created (richedit is a window) and you can change the styles of any control after it's been created too

thank you @InunoTaishou, i did not know this, although i made several attempts to toggle RichEdit styles, for wrapping and for RTL. would you please visit these links, and let me know where i stumbled?

Share this post


Link to post
Share on other sites
InunoTaishou
10 hours ago, orbs said:

thank you @InunoTaishou, i did not know this, although i made several attempts to toggle RichEdit styles, for wrapping and for RTL. would you please visit these links, and let me know where i stumbled?

I had doubts I could do it if Melba wasn't able to, I was right lol. Seems to be a bug (maybe intended? doubt it) with richedit not updating word wrap when the style is removed.

Edit: Check your wrapping topic, there is a solution ;)

Edited by InunoTaishou

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hello
      Dear Sirs, I have a question please
      About UPDown ctrl
      Where I want to adjust its format
      For example, I want to create a window to set the clock like the window in the system
      Can this be done?
      here's the example
      ______

      #include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <UpDownConstants.au3> goto() func Goto() local $wGoto = GUICreate("go to spissific position", 250, 180, @DesktopWidth / 2 - 192, @DesktopHeight / 2 - 235, -1) GUICtrlCreateLabel("please write a corect position to go to it", 50, 10, 220, 20) GUICtrlCreateLabel("hours", 0, 80, 100, 30) local $Inp1 = GUICtrlCreateInput("00", 0, 90, 100, 20, $ES_NUMBER + $WS_TABSTOP)     GUICtrlCreateUpdown($Inp1, $UDS_ARROWKEYS) GUICtrlSetLimit(-1, 23, 0) GUICtrlCreateLabel("minuts", 110, 80, 100, 30) local $Inp2 = GUICtrlCreateInput("00", 110, 90, 100, 20, $ES_NUMBER + $WS_TABSTOP)     GUICtrlCreateUpdown($Inp2, $UDS_ARROWKEYS) GUICtrlSetLimit(-1, 60, 0) GUICtrlCreateLabel("seconds", 220, 80, 100, 30) local $Inp3 = GUICtrlCreateInput("00", 220, 90, 100, 20, $ES_NUMBER + $WS_TABSTOP)     GUICtrlCreateUpdown($Inp3, $UDS_ARROWKEYS) GUICtrlSetLimit(-1, 60, 0) local $Ok = GUICtrlCreateButton("&ok", 0, 150, 50, 30, 0x01) local $cancel = GUICtrlCreateButton("&cancel", 200, 150, 50, 30) GUISetState(@sw_show, $WgoTo) while 1 switch GUIGetMSG() case $GUI_Event_Close, $cancel exit case $OK local $read1 = GUICtrlRead($inp1) if $read1 >= 1 then $Read1 = ($Read1*60)*60 local $read2 = GUICtrlRead($inp2) if $read2 >= 1 then $Read2 = $Read2*60 local $read3 = GUICtrlRead($inp3) GUIDelete($WgoTo) Return $read1+$read2+$read3 exit endSwitch Wend EndFunc
      ________
      What I need is to be the contents of the inputs as follows when i change the value of the UPDown CTRL
      00
      01
      02
      03
      ...
       
    • nacerbaaziz
      By nacerbaaziz
      Hello, dears.
      First I apologise to you for the stupid question I'm going to ask.
      is the default style for Windows created using AutoIt   a dialog box style?
      I decided to ask this question
      Because I am using a screen reader
      If i open any program that is designed using autoit, the screen reader read for example,  
      test dialog
      but If i open any other program, for example goldwave, it read goldwav only without a word dialog
      Is there a solution to this
      The code i used to create the window is:
      $hGUI = GUICreate(str("title"), 500, 420, -1, -1, BitOr($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_SYSMENU, $WS_CAPTION), BitOr($WS_EX_ACCEPTFILES,$WS_EX_LAYERED,$WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
      I hope to find a solution to this problem
      please Accept my greetings, and thank you very much.
    • loganizzi
      By loganizzi
      If you look at the help file for the above command, you'll see that it states that it only works for certain zoom values (100 and 200 to 6400).   I assume that this is due to an issue in an MSDN library that the command relies on.
      After doing some investigating, I noticed that the GUIRichEdit.au3 library file contains the following code:
      ; #FUNCTION# ==================================================================================================================== ; Authors........: Chris Haslam (c.haslam) ; Modified ......: ; =============================================================================================================================== Func _GUICtrlRichEdit_SetZoom($hWnd, $iPercent) If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, False) If Not __GCR_IsNumeric($iPercent, ">0") Then Return SetError(1021, 0, False) Local $iNumerator, $iDenominator Select Case Not ($iPercent = 100 Or ($iPercent >= 200 And $iPercent < 6400)) Return SetError(1022, 0, False) Case $iPercent >= 100 $iNumerator = 10000 $iDenominator = 10000 / ($iPercent / 100) Case Else $iNumerator = 10000 * ($iPercent / 100) $iDenominator = 10000 EndSelect Return _SendMessage($hWnd, $EM_SETZOOM, $iNumerator, $iDenominator) <> 0 EndFunc ;==>_GUICtrlRichEdit_SetZoom Which ensures that values are only within the bounds specified in the help file.    I found that if I comment out the portion of the code that limits the values, the function works fine for most (if not all) values.   I changed the code in the library file to this by simply commenting out the restricting lines of code:
      ; #FUNCTION# ==================================================================================================================== ; Authors........: Chris Haslam (c.haslam) ; Modified ......: ; =============================================================================================================================== Func _GUICtrlRichEdit_SetZoom($hWnd, $iPercent) If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, False) If Not __GCR_IsNumeric($iPercent, ">0") Then Return SetError(1021, 0, False) Local $iNumerator, $iDenominator Select ; Case Not ($iPercent = 100 Or ($iPercent >= 200 And $iPercent < 6400)) ; Return SetError(1022, 0, False) Case $iPercent >= 100 $iNumerator = 10000 $iDenominator = 10000 / ($iPercent / 100) Case Else $iNumerator = 10000 * ($iPercent / 100) $iDenominator = 10000 EndSelect Return _SendMessage($hWnd, $EM_SETZOOM, $iNumerator, $iDenominator) <> 0 EndFunc ;==>_GUICtrlRichEdit_SetZoom  
      I assume whatever windows bug existed at the time this was created, no longer exists so there is no need to restrict the values.   
      Just wanted to point this out if anyone else is using this part of the library and required this functionality like I did.
       
    • AndreyS
      By AndreyS
      Tell me, please, how to set / change the cursor over RichEdit (created with _GUICtrlRichEdit_Create)?
    • StMaSi
      By StMaSi
      Two questions...
      When presenting a form containing a richedit control, is there any way to make the displayed text, within said richedit control, non-selectable?
      In addition, is there any way to hide the vertical line cursor, within said richedit control?
      Thanx.
×