|
-
Jan 9th, 2002, 07:12 AM
#1
Thread Starter
PowerPoster
DrawText API
Harro. I am trying to draw some text on a picture box using the DrawText API. For Some Reason it does not work, It doesnt draw anything at all. Maybe someone can fill me in.
I am also using the SetRect API to draw the rect to draw the text in.
VB Code:
'In Module
Public Declare Function DrawText Lib "user32" Alias "DrawTextA" _
(ByVal hdc As Long, _
ByVal lpStr As String, ByVal nCount As Long, _
lpRect As RECT, _
ByVal wFormat As Long) As Long
Public Declare Function SetRect Lib "user32" _
(lpRect As RECT, _
ByVal X1 As Long, ByVal Y1 As Long, _
ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Const DT_CENTER = &H1
Public Const DT_LEFT = &H0
Public Const DT_RIGHT = &H2
Public Const DT_VCENTER = &H4
Public Const DT_WORDBREAK = &H10
Public Const DT_SINGLELINE = &H20
'In General Section of Form
Dim ItemRct As RECT
'In a command Button
SetRect ItemRct, 0, Picture1.TextHeight("Aa"), ItemRct.Right, Picture1.TextHeight("Aa") + Picture1.TextHeight("Aa")
DrawText Picture1.hdc, Text1.Text, Len(Text1), ItemRct, DT_SINGLELINE Or DT_VCENTER
THANKS!
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Jan 9th, 2002, 07:19 AM
#2
This works. I just tried it. Hopefully you can modify this example to fit your needs.
VB Code:
Const DC_ACTIVE = &H1
Const DC_ICON = &H4
Const DC_TEXT = &H8
Const BDR_SUNKENOUTER = &H2
Const BDR_RAISEDINNER = &H4
Const EDGE_ETCHED = (BDR_SUNKENOUTER Or BDR_RAISEDINNER)
Const BF_BOTTOM = &H8
Const BF_LEFT = &H1
Const BF_RIGHT = &H4
Const BF_TOP = &H2
Const BF_RECT = (BF_LEFT Or BF_TOP Or BF_RIGHT Or BF_BOTTOM)
Const DFC_BUTTON = 4
Const DFC_POPUPMENU = 5 'Only Win98/2000 !!
Const DFCS_BUTTON3STATE = &H10
Const DT_CENTER = &H1
Const DC_GRADIENT = &H20 'Only Win98/2000 !!
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function DrawCaption Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long, pcRect As RECT, ByVal un As Long) As Long
Private Declare Function DrawEdge Lib "user32" (ByVal hdc As Long, qrc As RECT, ByVal edge As Long, ByVal grfFlags As Long) As Long
Private Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long
Private Declare Function DrawFrameControl Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal un1 As Long, ByVal un2 As Long) As Long
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
Private Sub Form_Paint()
'KPD-Team 1999
'URL: [url]http://www.allapi.net/[/url]
Dim R As RECT
'Clear the form
Me.Cls
'API uses pixels
Me.ScaleMode = vbPixels
'Set the rectangle's values
SetRect R, 0, 0, Me.ScaleWidth, 20
'Draw a caption on the form
DrawCaption Me.hWnd, Me.hdc, R, DC_ACTIVE Or DC_ICON Or DC_TEXT Or DC_GRADIENT
'Move the recatangle
OffsetRect R, 0, 22
'Draw an edge on our window
DrawEdge Me.hdc, R, EDGE_ETCHED, BF_RECT
OffsetRect R, 0, 22
'Draw a focus rectangle on our window
DrawFocusRect Me.hdc, R
OffsetRect R, 0, 22
'Draw a frame control on our window
DrawFrameControl Me.hdc, R, DFC_BUTTON, DFCS_BUTTON3STATE
OffsetRect R, 0, 22
'draw some text on our form
DrawText Me.hdc, "Hello World !", Len("Hello World !"), R, DT_CENTER
End Sub
-
Jan 9th, 2002, 07:53 AM
#3
Thread Starter
PowerPoster
Thanks. Turns out i was missing the line. Picture1.Scalemode=vbpixels
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Jan 9th, 2002, 10:32 AM
#4
Thread Starter
PowerPoster
ARG! Dangit i can not figure this out. I think i had it working once but then fooled around with it and now cant fix it back.
I can draw the text on the picturebox just fine. My problem is Getting the text to add like a list. I.e. i can add this
Text1
But when i click again i want it to add another Text1 below it such as
Text1
Text1
Text1
I cant figure it out! Good lord how agrivating.
VB Code:
'This code here in a command button draws 1 item
'Maybe someone can figure out how to get it to draw multiple items i HOPE:D
Picture1.ScaleMode = vbPixels
SetRect ItemRct, 0, 0, Picture1.ScaleWidth, Picture1.TextHeight("Aa")
DrawText Picture1.hdc, Text1.Text, Len(Text1), ItemRct, DT_SINGLELINE Or DT_VCENTER
Just add the API from above to a module and those 3 lines to a command button or whatever.
THANKS!
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Jan 9th, 2002, 11:43 AM
#5
Thread Starter
PowerPoster
NM i figured it out FInally! Whoohoo!
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|