Jump to content
Sign in to follow this  
AndreyS

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!

Share this post


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

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

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

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

Share this post


Link to post
Share on other sites

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

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

Share this post


Link to post
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?

Share this post


Link to post
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

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Aelc
      Hey there!
      I'm gonna try to get access to an RichEdit Control in PSPad with Autoit which is scripted with Delphi. I wrote the commands out ouf the RichEdit.au3 UDF to can change them, because it always fails or crashs, when i call it. I Just want to set the Textcolor for the RichEdit.
      It seems to be a Problem with $EM_SETCHARFORMAT... (maybe protected?) I can use e.g. $EM_SETBKGNDCOLOR or other messages with no error. Sadly it doesn't exist a message constant to just set the textcolor... This is what i already tried:
      use $EM_GETCHARFORMAT but it crashs/doesn't work too. I saw the riched20.dll is linked to GDI+ but i couldn't make something work with it... (GetDc and so on but maybe there is another way?) Tried to set some other style on it (setWindowLong) I read the MSDN about $EM_SETCHARFORMAT up and down, but i can't find any other solution.
      The RichEdit should be version 2 ( error message point to riched20.dll )
       
      Here is the PSPad that will be required for testing:
      https://autoit.de/wcf/attachment/87712-pspad4autoit3-v1-0-0-beta-without-setup-zip/
      You need to start PSPad.exe first!
      ; = Info =========================================================================================== ; Title : RichEdit_Test ; -------------------------------------------------------------------------------------------------- ; ; Version (vnots) : 0.0.1 ; Date : 2020-05-13 ; Author(s) : Aelc ; ; ================================================================================================== #include <File.au3> #include <Misc.au3> #include <Date.au3> #include <String.au3> #include <GuiListBox.au3> #include <WinAPI.au3> #include <MsgBoxConstants.au3> #include <Color.au3> #include <GuiRichEdit.au3> #include <EditConstants.au3> AutoItSetOption("MustDeclareVars", 1) RichEdit_Test_Main() Func RichEdit_Test_Main() Local $hPSPad = Null Local $tLogCtrls Local $hLB_hwnd Local $hLB_ID $hPSPad = _WinAPI_GetForegroundWindow() If Not WinExists("[CLASS:TfPSPad]") Then MsgBox ( 48,"","PSPad not found." ) Exit EndIf Sleep(1000) $hPSPad = WinGetHandle("[CLASS:TfPSPad]") ;~ If $hPSPad = Null Then ;~ MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, 'AutoIt3_CompilerRunner: - Error -', 'No handle found for PSPad!') ;~ Exit (2) ; 2 = PSPad-hwnd not found ;~ EndIf If _WinAPI_IsClassName($hPSPad, "TfPSPad") Then ; -------------------------------------------------------------------------- If _Singleton("PSPad->RichEdit_Test " & String($hPSPad), 1) = 0 Then MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "RichEdit_Test: - Error -", _ '"RichEdit_Test" is already running') Exit EndIf ; -------------------------------------------------------------------------- $tLogCtrls = PSPad_GetLogControls($hPSPad, 'Log') $hLB_hwnd = $tLogCtrls.hWnd_ListBox $hLB_ID = $tLogCtrls.ID_ListBox If $hLB_hwnd > 0 Then _SendMessage($hLB_hwnd, 0xCF,False) ;Set $READONLY to False Local $tagCHARFORMAT_changeable = "struct;uint cbSize;long dwMask;long dwEffects;long yHeight;long yOffset;INT crTextColor;" & _ "byte bCharSet;byte bPitchAndFamily;wchar szFaceName[32];endstruct" Local $aColor[3] = [0xFF, 0x00, 0xFF] Local $nColor = _ColorSetCOLORREF($aColor) Local $tCharFormat = DllStructCreate($tagCHARFORMAT_changeable) DllStructSetData($tCharFormat, 1, DllStructGetSize($tCharFormat)) DllStructSetData($tCharFormat, 2, $CFM_COLOR) DllStructSetData($tCharFormat, 6, $nColor) MsgBox ( 64,"",_SendMessage($hLB_hwnd, $EM_SETCHARFORMAT, $SCF_SELECTION, $tCharFormat, 0, "wparam", "struct*")) Else ; Log-Fenster konnte nicht gefunden werden. MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "AutoIt3_CompilerRunner: - Error -", _ "The log window of PSPad could not be found.") Exit EndIf Else EndIf EndFunc ;==>RichEdit_Test_Main ;~ Func _RichEditGetTextLength($hWnd) ;~ If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, 0) ;~ Local $bChars = True ;~ Local $bExact = True ;~ Local $tGetTextLen = DllStructCreate($tagGETTEXTLENGTHEX) ;~ Local $iFlags = BitOR($GTL_USECRLF, ($bExact ? $GTL_PRECISE : $GTL_CLOSE)) ;~ $iFlags = BitOR($iFlags, ($bChars ? $GTL_DEFAULT : $GTL_NUMBYTES)) ;~ DllStructSetData($tGetTextLen, 1, $iFlags) ;~ DllStructSetData($tGetTextLen, 2, ($bChars ? $CP_ACP : $CP_UNICODE)) ;~ Local $iRet = _SendMessage($hWnd, $EM_GETTEXTLENGTHEX, $tGetTextLen, 0, 0, "struct*") ;~ Return $iRet ;~ EndFunc ;==>_RichEditGetTextLength ;~ Func _RichEditGetBKColor($hWnd) ;~ If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, 0) ;~ Local $iBkColor = _SendMessage($hWnd, $EM_SETBKGNDCOLOR, False, 0) ;~ _SendMessage($hWnd, $EM_SETBKGNDCOLOR, False, $iBkColor) ;~ Return $iBkColor ;~ EndFunc ;==>_RichEditGetBKColor ;~ Func _RichEditSetBKColor($hWnd, $iBkColor) ;~ If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, 0) ;~ _SendMessage($hWnd, $EM_SETBKGNDCOLOR, False, $iBkColor) ;~ Return $iBkColor ;~ EndFunc ;==>_RichEditSetBKColor Func PSPad_GetLogControls($_hPSPad, $_sSheetText = 'Log') Local $sStruct_LogCtrls = _ 'hwnd hWnd_PageControl;' & _ ; TPageControl 'int ID_PageControl;' & _ 'hwnd hWnd_TabSheet;' & _ ; TTabSheet 'int ID_TabSheet;' & _ 'hwnd hWnd_ListBox;' & _ ; TListBox 'int ID_ListBox;' Local $tResult = DllStructCreate($sStruct_LogCtrls) Local $aEnum Local $sSheet Local $i, $x $aEnum = _WinAPI_EnumChildWindows($_hPSPad, False) If IsArray($aEnum) Then For $i = 1 To $aEnum[0][0] If $aEnum[$i][1] = "TTabSheet" Then $sSheet = ControlGetText($_hPSPad, '', _WinAPI_GetDlgCtrlID($aEnum[$i][0])) If $sSheet = $_sSheetText Then ; TabSheet gefunden. $tResult.hWnd_TabSheet = $aEnum[$i][0] $tResult.ID_TabSheet = _WinAPI_GetDlgCtrlID($tResult.hWnd_TabSheet) $tResult.hWnd_PageControl = _WinAPI_GetParent($tResult.hWnd_TabSheet) $tResult.ID_PageControl = _WinAPI_GetDlgCtrlID($tResult.hWnd_PageControl) For $x = $i + 1 To $aEnum[0][0] If $aEnum[$x][1] = "TRichEdit" Then $tResult.hWnd_ListBox = $aEnum[$x][0] $tResult.ID_ListBox = _WinAPI_GetDlgCtrlID($tResult.hWnd_ListBox) Return $tResult ; Wenn gefunden, dann raus aus der Funktion. EndIf Next EndIf EndIf Next EndIf Return $tResult EndFunc ;==>PSPad_GetLogControls I don't have any ideas anymore  But maybe someone else has?
      I would be happy for every idea  
       
      Thanks in advance
    • By MrCreatoR
      This UDF allows to create formatted label using pseudo element RichLabel (RichEdit actually). Formating is set by using special modificator similar to <font> tag in Html.
      Notes: This UDF is a transformation-continuation of related UDF


      Example:
      Download:
      GUIRichLabel_1.2.zip
      Small syntax related fix: GUIRichLabel_1.1.zip
      GUIRichLabel_1.1.zip
       
      History version:
    • By cdeb
      How can you select the specific style of a font with multiple * .otf files?
      The font in question has several files:
       
      Thin Thin Italic Extra-Light Extra-Light Italic Light Light Italic Regular Regular Italic Medium Medium Italic Semi-Bold Semi-Bold Italic Bold Bold Italic Extra-Bold Extra-Bold Italic Black Black Italic But after doing several tests I can recall the font like this, without being able to specify the precise style:
      Local $hFamily = _GDIPlus_FontFamilyCreate("Poppins") ; Local $hFont = _GDIPlus_FontCreate($hFamily, 95, 1+2, 3) ; Example I cannot therefore select "Poppins Black Italic"
      but only "Poppins" 
      Thank you

    • By Reher
      Hi
      so i ran into a Problem i didn't expect to get stuck on.
      It sounds simple (and probably is) but i can't seem to get it to work
      So i created a Combobox and filled it with some things from an array which worked fine.
      $combobox = GUICtrlCreateCombo($list[0], 160, 200, 265, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GuiCtrlSetData($list, "|" & _ArrayToString($list,Default,1),$list[2]) GUICtrlSetFont(-1, 9, 400, 0, "Arial") Now i want to change the style of the combobox from $CBS_DROPDOWN to $CBS_DROPDOWNLIST via a checkbox.
      $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 160, 96, 105, 25) Case $Checkbox1 If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then Call ("Read_only") Else Call ("Edit") Endif Func Read_only() GUICtrlSetStyle ($Combobox1,something to change it to $CBS_DROPDOWNLIST) EndFunc Func Edit() GUICtrlSetStyle ($Combobox1,something to change it to $CBS_DROPDOW) EndFunc I tried using $CBS_DROPDOWN and $CBS_DROPDOWNLIST but it simply does nothing.
      I also tried $ES_READONLY which kinda worked, it changed the combobox so i couldn't change the input via dropdown anymore but i could still type in it via keyboard (which i dont want).
      It's essential that its Editable but once the checkbox is checked the combobox becomes readonly so you can't type in it anymore but you can still choose between the items in the list. (It does not have to save your current input if you write something in it and then check the Checkbox it would be best if it would simpy jump back to the first item in the list)
      Im sure this is a simple thing but after long google search im tired of my stupidity can someone give me a push in the right direction?
    • 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
      ...
       
×
×
  • Create New...