Jump to content

Applying styles to RichEdit


Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
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.

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

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
Link to comment
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.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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?

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

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
Link to comment
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
 Share

×
×
  • Create New...