vb code examples:Start a new project in Visual Basic. Form1 is created by default.
Add a Command button to Form1.
Place the following code in the General Declarations section of Form1: Option Explicit 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 Const DT_BOTTOM = &H8
Private Const DT_CENTER = &H1
Private Const DT_LEFT = &H0
Private Const DT_RIGHT = &H2
Private Const DT_TOP = &H0
Private Const DT_VCENTER = &H4
Private Const DT_WORDBREAK = &H10 Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type Private Sub Command1_Click()
Dim lSuccess As Long
Dim sPrintText As String
Dim MyRect As RECT
Form1.Font.Size = 12
Form1.ScaleMode = vbPixels
MyRect.Left = 0
MyRect.Right = Form1.ScaleWidth
MyRect.Top = 20
MyRect.Bottom = 60
sPrintText = "Print this text"
lSuccess = DrawText(Form1.hdc, sPrintText, Len(sPrintText), _
MyRect, DT_CENTER or DT_WORDBREAK)
End Sub Press the F5 key to run the project, and press the Command button. Text should appear in the middle of the form and be word-wrapped. If you Resize the form and run the project again, you will note that the text still appears in the middle of the form on the horizontal axis.
Following is a list of all the constants that can be used with the DrawText API to give the various effects documented in the Win32 SDK: Global Const DT_TOP = &H00000000
Global Const DT_LEFT = &H00000000
Global Const DT_CENTER = &H00000001
Global Const DT_RIGHT = &H00000002
Global Const DT_VCENTER = &H00000004
Global Const DT_BOTTOM = &H00000008
Global Const DT_WORDBREAK = &H00000010
Global Const DT_SINGLELINE = &H00000020
Global Const DT_EXPANDTABS = &H00000040
Global Const DT_TABSTOP = &H00000080
Global Const DT_NOCLIP = &H00000100
Global Const DT_EXTERNALLEADING = &H00000200
Global Const DT_CALCRECT = &H00000400
Global Const DT_NOPREFIX = &H00000800
Global Const DT_INTERNAL = &H00001000
Global Const DT_EDITCONTROL = &H00002000
Global Const DT_PATH_ELLIPSIS = &H00004000
Global Const DT_END_ELLIPSIS = &H00008000
Global Const DT_MODIFYSTRING = &H00010000
Global Const DT_RTLREADING = &H00020000
Global Const DT_WORD_ELLIPSIS = &H00040000 vc code examples:Text3D Sample
Description
The Text3D sample shows how to draw 2-D text in a 3-D scene. This is useful for displaying statistics or game menus, and so on.Path
Source: (SDK Root)\Samples\Multimedia\Direct3D\Text3DExecutable: (SDK Root)\Samples\Multimedia\Direct3D\Bin
Add a Command button to Form1.
Place the following code in the General Declarations section of Form1: Option Explicit 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 Const DT_BOTTOM = &H8
Private Const DT_CENTER = &H1
Private Const DT_LEFT = &H0
Private Const DT_RIGHT = &H2
Private Const DT_TOP = &H0
Private Const DT_VCENTER = &H4
Private Const DT_WORDBREAK = &H10 Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type Private Sub Command1_Click()
Dim lSuccess As Long
Dim sPrintText As String
Dim MyRect As RECT
Form1.Font.Size = 12
Form1.ScaleMode = vbPixels
MyRect.Left = 0
MyRect.Right = Form1.ScaleWidth
MyRect.Top = 20
MyRect.Bottom = 60
sPrintText = "Print this text"
lSuccess = DrawText(Form1.hdc, sPrintText, Len(sPrintText), _
MyRect, DT_CENTER or DT_WORDBREAK)
End Sub Press the F5 key to run the project, and press the Command button. Text should appear in the middle of the form and be word-wrapped. If you Resize the form and run the project again, you will note that the text still appears in the middle of the form on the horizontal axis.
Following is a list of all the constants that can be used with the DrawText API to give the various effects documented in the Win32 SDK: Global Const DT_TOP = &H00000000
Global Const DT_LEFT = &H00000000
Global Const DT_CENTER = &H00000001
Global Const DT_RIGHT = &H00000002
Global Const DT_VCENTER = &H00000004
Global Const DT_BOTTOM = &H00000008
Global Const DT_WORDBREAK = &H00000010
Global Const DT_SINGLELINE = &H00000020
Global Const DT_EXPANDTABS = &H00000040
Global Const DT_TABSTOP = &H00000080
Global Const DT_NOCLIP = &H00000100
Global Const DT_EXTERNALLEADING = &H00000200
Global Const DT_CALCRECT = &H00000400
Global Const DT_NOPREFIX = &H00000800
Global Const DT_INTERNAL = &H00001000
Global Const DT_EDITCONTROL = &H00002000
Global Const DT_PATH_ELLIPSIS = &H00004000
Global Const DT_END_ELLIPSIS = &H00008000
Global Const DT_MODIFYSTRING = &H00010000
Global Const DT_RTLREADING = &H00020000
Global Const DT_WORD_ELLIPSIS = &H00040000 vc code examples:Text3D Sample
Description
The Text3D sample shows how to draw 2-D text in a 3-D scene. This is useful for displaying statistics or game menus, and so on.Path
Source: (SDK Root)\Samples\Multimedia\Direct3D\Text3DExecutable: (SDK Root)\Samples\Multimedia\Direct3D\Bin
可以截取到星际按钮的文本吗?我尝试过多次,也没有成功,但是截取notepad, wordpad等程序就可以。
谢谢
TextOut(hdc,...................);
lpDDSSecondary->ReleaseDC(hdc);
Flip();
你大概没有用GetDC函数来锁定。先在后台画好,再反转,我上的程序只是象征性,有所省略