about drawtestex

Hi

Using DrawTextEx:

I put a string on a form and found there was 3 dots
at the end, fine. However, in the second time, I put
the same string in the same place of the form with
the same RECT, there was 4 dots at the end.

Sometimes, a thick vertical line appeared (following
3 dots) at the end in the second time. (I can not
repeat this, I forgot the code)

Perhaps I misunderstood the parameters in function
DrawTextEx, can you explain each of them for me and
tell me why I got the above problems?

Here is the code for the 4 dots case:

Option Explicit

Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Declare Function DrawTextEx Lib "user32" Alias "DrawTextExA" (ByVal hdc As Long, ByVal lpsz As String, ByVal n As Long, lpRect As RECT, ByVal un As Long, ByVal lpDrawTextParams As Long) As Long

Private Sub Command3_Click()

Dim CellPosition As RECT
Dim str As String
Dim i As Integer
Const DT_LEFT = &H0
Const DT_SINGLELINE = &H20
Const DT_PATH_ELLIPSIS = &H4000
Const DT_END_ELLIPSIS = &H8000
Const WS_BORDER = &H800000
Const GWL_STYLE = (-16)
Const SM_CYCAPTION = 4

CellPosition.Top = 0
CellPosition.Bottom = 100
CellPosition.Left = 100
CellPosition.Right = 200
str = "12345678901234567890"

ScaleMode = 3

For i = 1 To 2
DrawTextEx hdc, str, Len(str), CellPosition, _
           DT_LEFT Or DT_SINGLELINE Or DT_END_ELLIPSIS, 0
Next i     'set Breakpoint here
     
End Sub
victorlongAsked:
Who is Participating?
 
Answers2000Connect With a Mentor Commented:
Your text doesn't fit in the box.

1. When you set DT_END_ELLIPSIS, windows put's in dots at the end of the string to indicate it doesn't fit.
2. When you put in other cases, the text is being clipped and the left edge of a character

Your program is too small a rectangle.  Also if you don't want dots remove DT_END_ELLIPSIS.  
0
 
viktornetCommented:
Did you try removing the first string and then draw on the same place again??

Regards,
Viktor Ivanov
0
 
victorlongAuthor Commented:
To Answers2000:

please check you answer. It looks not finished in part 2.

I do like the dots, but don't know why they can be changed rome 3 dots to 4 dots or from 3 dots to 3dots + a vertical short line.

As I mentioned in my question, can you explain each parameters of function DrawTextEx for me and tell me why I got the above problem?
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
victorlongAuthor Commented:
To  viktornet:

No, I didn't remove the first string. Why?
0
 
viktornetCommented:
Why don;t you try repainting the form so it cleans up the canvas, and then draw the string.,...after each drawing of the string try repaiting it..

Regards,
Viktor Ivanov
0
 
viktornetCommented:
The improtant parameters are....
hdc - Device Context
str   - the string to be drawn
Len(str) - Length of string
CellPosition - rect on the hdc where to be drawn
DT_LEFT Or DT_SINGLELINE Or DT_END_ELLIPSIS - Windows defined constants....

Regards,
Viktor Ivanov
0
 
victorlongAuthor Commented:
To viktornet:

Thank you for your help as comments.

How to repaint? Use 'Line (,)-(,),White,BF'? I got another example: set the form to Autoredraw, after doing 'DrawText hdc, "abcd", 4, lpRect, 0', nothing happened until I drag a window to cover the area (lpRect) for a while the stirng appeard:-)

Cheers.
0
 
viktornetCommented:
I don't actually use VB but my mother has it on her computer so I saw an example from that and here it is...
------------
This example constructs a circle on your form with random FillColor and FillStyle property settings as you click the mouse. To try this example, paste the code into the Declarations section of a form, and then press F5 and click the form.

Private Sub Form_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
      FillColor = QBColor(Int(Rnd * 15))      ' Choose random FillColor.
      FillStyle = Int(Rnd * 8)      ' Choose random FillStyle.
      Circle (X, Y), 250      ' Draw a circle.
End Sub
--------------------------
Use the FillColor to color the form the same color as it is before you draw on the string...
Then when you fill the form with that color draw the next string you want on the form....it is supose to be working now =)
Hey and don't use the Circle(...) stuff...this is just an example I took from the help file....

Regards,
Viktor Ivanov
0
 
viktornetCommented:
You can try declaring a Rect that is as big as the form and then fill it with the same color as the form....If you need Delphi code I can show you how to do many things....but in VB...uh I ain't that good..

Regards,
Viktor Ivnaov
0
 
viktornetCommented:
You can try declaring a Rect that is as big as the form and then fill it with the same color as the form....If you need Delphi code I can show you how to do many things....but in VB...uh I ain't that good..If you need furthur help with VB I'll try to see something if I can help.. ;-)

Regards,
Viktor Ivnaov
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.