AndreyS

Applying styles to RichEdit

17 posts in this topic

#1 ·  Posted

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



#3 ·  Posted

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

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

Share this post


Link to post
Share on other sites

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

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

#8 ·  Posted (edited)

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

@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

#10 ·  Posted

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

1 person likes this

Share this post


Link to post
Share on other sites

#11 ·  Posted

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

#12 ·  Posted

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

#13 ·  Posted

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

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

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
1 person likes this

Share this post


Link to post
Share on other sites

#15 ·  Posted

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

#16 ·  Posted

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

#17 ·  Posted (edited)

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

    • 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.
    • TheSaint
      By TheSaint
      I've finally come up with some simple solutions for dragging & dropping a URL onto a control.
      There have been many requests here for this over the years.
      I do have an issue though, with my second code example solution as is mentioned here.
      The issue relates to working in Win 7 (and no doubt newer Windows).
      As I state there, failure is no doubt due to 'MSCOMCT2.OCX' missing from the System32 folder, at the very least.
      Not sure if it would be wise to just dump 'MSCOMCT2.OCX' from WinXP into the Win 7 System32 folder. I expect not.
      I imagine there is a better solution available in Win 7. Maybe a different OCX file, and perhaps a different Class of object etc.
      Any help would be greatly appreciated.
      Code is here (second example).
      EDIT
      Okay, I have rediscovered that 'MSCOMCT2.OCX' is a VB6 ActiveX control. So while I could dig up a copy and register it, that would probably not be helpful to everyone.
      And registering it didn't help. Possibly other dependencies are also needed?
      When running the script, it is clear going by the error reported, that Object is not being created.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I was looking around the forum if there were some customizable solutions about creating a PDF from "0" to something like a report...
      What I'd like to do is something with a header ( 2 logos and a title ), with a table which contains data read from a file
      At the moment, I was working with HTML, since I know it and it's very simple to do a table with some data inside...
      But know, I'm a bit stuck about the exporting the HTML page to PDF... And, here too, if someone knows how to do it, please, I'm here listening
      Thanks guys