about drawtestex

Posted on 1998-08-23
Medium Priority
Last Modified: 2008-02-01

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

        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_END_ELLIPSIS = &H8000
Const WS_BORDER = &H800000
Const GWL_STYLE = (-16)

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, _
Next i     'set Breakpoint here
End Sub
Question by:victorlong
  • 6
  • 3
LVL 10

Expert Comment

ID: 1430497
Did you try removing the first string and then draw on the same place again??

Viktor Ivanov

Accepted Solution

Answers2000 earned 100 total points
ID: 1430498
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.  

Author Comment

ID: 1430499
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?
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 1430500
To  viktornet:

No, I didn't remove the first string. Why?
LVL 10

Expert Comment

ID: 1430501
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..

Viktor Ivanov
LVL 10

Expert Comment

ID: 1430502
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....

Viktor Ivanov

Author Comment

ID: 1430503
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:-)

LVL 10

Expert Comment

ID: 1430504
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....

Viktor Ivanov
LVL 10

Expert Comment

ID: 1430505
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..

Viktor Ivnaov
LVL 10

Expert Comment

ID: 1430506
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.. ;-)

Viktor Ivnaov

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question