Solved

about drawtestex

Posted on 1998-08-23
10
241 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:victorlong
  • 6
  • 3
10 Comments
 
LVL 10

Expert Comment

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

Regards,
Viktor Ivanov
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 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.  
0
 

Author Comment

by:victorlong
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?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:victorlong
ID: 1430500
To  viktornet:

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

Expert Comment

by:viktornet
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..

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
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....

Regards,
Viktor Ivanov
0
 

Author Comment

by:victorlong
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:-)

Cheers.
0
 
LVL 10

Expert Comment

by:viktornet
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....

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
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..

Regards,
Viktor Ivnaov
0
 
LVL 10

Expert Comment

by:viktornet
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.. ;-)

Regards,
Viktor Ivnaov
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

829 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