Solved

about drawtestex

Posted on 1998-08-23
10
233 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
 

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now