Page 1 of 1

Posted: Fri Apr 19, 2002 11:14 am
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

Hi,

The following code creates a RichEdit control and places some text in it. According to the Win32 API Reference and to MSDN, SendMessage_() used as you can see should right-align the text. Well, it doesn't. Any API guru around who can help me solve this?

Code: Select all

If OpenWindow(0, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget, "RichEdit sample")
  RichEditID = CreateWindowEx_(0, @"RichEdit20A", @"This text should appear right aligned after the following code is executed", #WS_CHILD|#WS_VISIBLE|#WS_VSCROLL|#ES_MULTILINE|#ES_AUTOVSCROLL|#ES_NOHIDESEL|#WS_CLIPSIBLINGS, 0, 0, WindowWidth(), WindowHeight(), WindowID(), 0, LoadLibrary_("RICHED20.DLL"), 0)
  pf.PARAFORMAT
  pf\cbSize = SizeOf(PARAFORMAT)
  pf\dwMask = #PFM_ALIGNMENT
  pf\wAlignment = #PFA_RIGHT
  SendMessage_(RichEditID, #EM_SETPARAFORMAT, 0, @pf)
  Repeat
  Until WaitWindowEvent()=#PB_EventCloseWindow
EndIf
Thanks a lot. Bye,

El_Choni

Posted: Fri Apr 19, 2002 12:46 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

Hi,

The Windows SDK says the following about Edit controls and Styles:
Edit Control Styles
To create an edit control using the CreateWindow or CreateWindowEx function, specify the EDIT class, appropriate window style constants, and a combination of the following edit control styles. After the control has been created, these styles cannot be modified, except as noted.
It also says, that the following Styles can be modyfied using SetWindowLong:
ES_LOWERCASE
ES_NUMBER
ES_OEMCONVERT
ES_UPPERCASE
ES_WANTRETURN

ES_PASSWORD can bechanged by sending the EM_SETPASSWORDCHAR message and
ES_READONLY can bechanged by sending the EM_SETREADONLY message.

Well, it seems, that you can set the other Styles only while creating the control.
This means, you have to include #ES_RIGHT to the Constants at CreateWindowEx_().

I don't think, there's another way to change it later, sorry.

Timo

A debugged program is one for which you have not yet found the conditions that make it fail.

Posted: Fri Apr 19, 2002 1:16 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

Hi freak,

Your advice sounds correct for an "Edit" control. Anyway, the code I've posted creates a "RichEdit" control, which differs from the first in many important aspects.

Anyway, thanks for your help, I didn't expect an answer as soon as you've done.

Bye,

El_Choni

Posted: Fri Apr 19, 2002 1:48 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

Well, you're right, RichEdit is different.

I took a look at EM_SETPARAFORMAT in the Windows SDK
It says:
The EM_SETPARAFORMAT message sets the paragraph formatting for the current selection in a rich edit control.
So, this means, the text has to be selected in order to change it's Style.
So I tried the following:

Code: Select all

If OpenWindow(0, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget, "RichEdit sample")
  RichEditID = CreateWindowEx_(0, @"RichEdit20A", @"This text should appear right aligned after the following code is executed", #WS_CHILD|#WS_VISIBLE|#WS_VSCROLL|#ES_MULTILINE|#ES_AUTOVSCROLL|#ES_NOHIDESEL|#WS_CLIPSIBLINGS, 0, 0, WindowWidth(), WindowHeight(), WindowID(), 0, LoadLibrary_("RICHED20.DLL"), 0)
    
  range.CHARRANGE
  range\cpMin = 0
  range\cpMax = -1
  SendMessage_(RichEditID, #EM_EXSETSEL,0, @range) ; Select the Text
   
  pf.PARAFORMAT
  pf\cbSize = SizeOf(PARAFORMAT)
  pf\dwMask = #PFM_ALIGNMENT
  pf\wAlignment = #PFA_RIGHT
  SendMessage_(RichEditID, #EM_SETPARAFORMAT, 0, @pf)
  
  Repeat  
  Until WaitWindowEvent()=#PB_EventCloseWindow
EndIf
But still, it doesn't work. The SendMessage Returns 0, which means, that the Operation failed. But I don't know the reason why.

I'm still trying some Stuff, maybe I'll find a solution.

Timo

A debugged program is one for which you have not yet found the conditions that make it fail.

Posted: Fri Apr 19, 2002 5:36 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

I've found the problem:

The PARAFORMAT Structure has a wrong size. It is 32 byte, but according to the
SDK, it should be 156 bytes. It seems that rgxTabs appears only
once in the Structure, but it has to be an Array like rgxTabs[32] .
Where are those predefined Structures declared?
Is this a bug? (Fred?)

Well, anyway, here's a solution for your problem:

Code: Select all

; ++++++++++++++++++++++++++++++++++++++++++++++
  
Structure Para
  cbSize.l
  dwMask.l 
  wNumbering.w 
  wReserved.w
  dxStartIndent.l
  dxRightIndent.l
  dxOffset.l
  wAlignment.w
  cTabCount.w
  rgxTabs.l[#MAX_TAB_STOPS]; 
EndStructure
  
If OpenWindow(0, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget, "RichEdit sample")
  RichEditID = CreateWindowEx_(0, @"RichEdit20A", @"This text should appear right aligned after the following code is executed", #WS_CHILD|#WS_VISIBLE|#WS_VSCROLL|#ES_MULTILINE|#ES_AUTOVSCROLL|#ES_NOHIDESEL|#WS_CLIPSIBLINGS, 0, 0, WindowWidth(), WindowHeight(), WindowID(), 0, LoadLibrary_("RICHED20.DLL"), 0)
    
  pf.Para
  pf\cbSize = SizeOf(Para)
  pf\dwMask = #PFM_ALIGNMENT
  pf\wAlignment = #PFA_RIGHT
  SendMessage_(RichEditID, #EM_SETPARAFORMAT, 0, @pf)
  
  Repeat  
  Until WaitWindowEvent()=#PB_EventCloseWindow
EndIf
  
; +++++++++++++++++++++++++++++++++++++++++++++++
This should work. You don't have to select the Text in order to use this, like I said before. (If nothing is selected, the changes aply to all Text.)

That's it...

Timo



A debugged program is one for which you have not yet found the conditions that make it fail.


Edited by - freak on 19 April 2002 18:39:08

Posted: Fri Apr 19, 2002 5:44 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

Thanks a lot, freak! I've been around this problem for months, now I can add paragraph formatting to the RichEdit lib (not before a week). I have to test the PARAFORMAT2 structure, too (it's not defined in PB).

Thanks again and have a nice day,

El_Choni

Posted: Fri Apr 19, 2002 5:48 pm
by BackupUser
Restored from previous forum. Originally posted by fred.

Thanks a lot, it's corrected now... Sorry for the problem El_Choni !

Fred - AlphaSND

Posted: Sat Apr 20, 2002 4:39 am
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

Hi,

Thanks, Fred. Talking about structure sizes, I found this problem time ago:

The STARTUPINFO structure has a size of 68 in PB. So does in Masm includes, as far as I can remember, but it has a bizarre size of 65 in some others (Nasm's Win32n.inc, i.e.), due to the lpReserved2 member being defined as having a byte size instead of a doubleword size. I thought this was due to some difference between NT and 9X, so always when I'm going to use STARTUPINFO I use GetStartupInfo first to avoid problems. Do you know if this is an error in Nasm's include (I think I remember seeing it in some others) or a real difference between Windows versions?

(Don't waste too much time on this :wink: Thanks, and bye,


El_Choni

Posted: Sat Apr 20, 2002 10:41 am
by BackupUser
Restored from previous forum. Originally posted by Don.

Hi El_Choni

You probably already know this, but in a Rich Edit control, you can change the paragraph formatting for individual paragraphs without having to select the paragraph beforehand. You just need to make sure that the paragraph finishes with Chr(13)+Chr(10). Here's an example:

Code: Select all

#RICHEDIT = #WS_CHILD | #WS_VISIBLE | #ES_MULTILINE | #WS_VSCROLL
#MAINFLAGS = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget
#XMARGIN = 6
#YMARGIN = 24
eol.s = Chr(13)+Chr(10)
 
Structure Para
  cbSize.l
  dwMask.l 
  wNumbering.w 
  wReserved.w
  dxStartIndent.l
  dxRightIndent.l
  dxOffset.l
  wAlignment.w
  cTabCount.w
  rgxTabs.l[#MAX_TAB_STOPS]
EndStructure
 
If OpenWindow(0, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #MAINFLAGS, "RichEdit sample")
  RichEditID = CreateWindowEx_(#WS_EX_CLIENTEDGE, "RichEdit20A", "", #RICHEDIT, 0, 0, WindowWidth()-#XMARGIN, WindowHeight()-#YMARGIN, WindowID(), 0, LoadLibrary_("RICHED20.DLL"), 0)
 
  pf.Para
  pf\cbSize = SizeOf(Para)
  pf\dwMask = #PFM_ALIGNMENT
  pf\wAlignment = #PFA_RIGHT
  SendMessage_(RichEditID, #EM_SETPARAFORMAT, 0, @pf)
   
  SendMessage_(RichEditID, #EM_REPLACESEL, #FALSE, "This text is right aligned"+eol)
  pf\wAlignment = #PFA_LEFT
  SendMessage_(RichEditID, #EM_SETPARAFORMAT, 0, @pf)
  SendMessage_(RichEditID, #EM_REPLACESEL, #FALSE, "This text is left aligned"+eol)
  pf\wAlignment = #PFA_CENTER
  SendMessage_(RichEditID, #EM_SETPARAFORMAT, 0, @pf)
  SendMessage_(RichEditID, #EM_REPLACESEL, #FALSE, "This text is center aligned"+eol)
 
  Repeat : Until WaitWindowEvent()=#PB_EventCloseWindow
EndIf
By the way, the CHARFORMAT2 and PARAFORMAT2 structures to use are:

Code: Select all

Structure CHARFORMAT2
  cbSize.l
  dwMask.l
  dwEffects.l
  yHeight.l
  yOffset.l
  crTextColor.l
  bCharSet.b
  bPitchAndFamily.b
  szFaceName.b[#LF_FACESIZE]
  _wPad2.w
  wWeight.w
  sSpacing.w
  crBackColor.l
  lcid.l
  dwReserved.l
  sStyle.w
  wKerning.w
  bUnderlineType.b
  bAnimation.b
  bRevAuthor.b
  bReserved1.b
EndStructure
 
Structure PARAFORMAT2 
  cbSize.l
  dwMask.l 
  wNumbering.w
  wEffects.w
  dxStartIndent.l
  dxRightIndent.l
  dxOffset.l
  wAlignment.w
  cTabCount.w
  rgxTabs.l[#MAX_TAB_STOPS]
  dySpaceBefore.l
  dySpaceAfter.l
  dyLineSpacing.l
  sStyle.w
  bLineSpacingRule.b
  bOutlineLevel.b
  wShadingWeight.w
  wShadingStyle.w
  wNumberingStart.w
  wNumberingStyle.w
  wNumberingTab.w
  wBorderSpace.w
  wBorderWidth.w
  wBorders.w
EndStructure
Don

Posted: Sat Apr 20, 2002 12:45 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

Thanks, Don, I didn't know about that CR/LF needing at the end of the paragraph.

Regards,

El_Choni