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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

771 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