首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

printer怎么使用drawtext这个API涵数

2012-05-02 
printer如何使用drawtext这个API涵数以下内容:call drawtext(obj.hdc,aaa,-,trc,tformat)当obj为picture

printer如何使用drawtext这个API涵数
以下内容:
call drawtext(obj.hdc,"aaa",-,trc,tformat)

当obj为picturebox时,可以画出aaa这个字符在对应的trc里面,但当obj为printer时,却打印不出来,我查了一些相关的内容,确实有这种情况,也看过有个方法是先在drawtext运行之前加入obj.line (0,0)-(100,100),vbwhite进行先画线来激活printer,但我试了还是不行,请问各位还有什么好方法能让drawtext可以使用printer对象呢?

如果没有,那能用哪个API代替drawtext呢?(必须能定义水平对齐、自动换行等方式,因为编写的需要)

衷心感激各位!

[解决办法]
我使用drawtext打印,一切正常
[解决办法]

VB code
'Example Name: Changing the Dropdown Width of a Combo Box, Advanced'------------------------------------------'' BAS Moduel Code''------------------------------------------Option ExplicitPublic Declare Function SendMessage Lib "user32" _   Alias "SendMessageA" _  (ByVal hwnd As Long, _   ByVal wMsg As Long, _   ByVal wParam As Long, _   lParam As Long) As LongPublic Const CB_GETLBTEXTLEN = &H149Public Const CB_SHOWDROPDOWN = &H14FPublic Const CB_GETDROPPEDWIDTH = &H15FPublic Const CB_SETDROPPEDWIDTH = &H160Public Const ANSI_FIXED_FONT = 11Public Const ANSI_VAR_FONT = 12Public Const SYSTEM_FONT = 13Public Const DEFAULT_GUI_FONT = 17 'win95/98 onlyPublic Const SM_CXHSCROLL = 21Public Const SM_CXHTHUMB = 10Public Const SM_CXVSCROLL = 2Public Type SIZE  cx As Long  cy As LongEnd TypePublic Type RECT   Left As Long   Top As Long   Right As Long   Bottom As LongEnd TypePublic 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 LongPublic Const DT_CALCRECT = &H400Public Declare Function SelectObject Lib "gdi32" _    (ByVal hDC As Long, ByVal hObject As Long) As LongPublic Declare Function GetTextExtentPoint32 Lib "gdi32" _    Alias "GetTextExtentPoint32A" _   (ByVal hDC As Long, _    ByVal lpsz As String, _    ByVal cbString As Long, _    lpSize As SIZE) As LongPublic Declare Function GetStockObject Lib "gdi32" _  (ByVal nIndex As Long) As Long  Public Declare Function DeleteObject Lib "gdi32" _  (ByVal hObject As Long) As Long  Public Declare Function ReleaseDC Lib "user32" _  (ByVal hwnd As Long, _   ByVal hDC As Long) As Long   Public Declare Function GetDC Lib "user32" _  (ByVal hwnd As Long) As Long  Public Declare Function GetSystemMetrics Lib "user32" _  (ByVal nIndex As Long) As LongPublic Function GetFontDialogUnits() As Long   Dim hFont As Long   Dim hFontOld As Long   Dim r As Long   Dim avgWidth As Long   Dim hDc As Long   Dim tmp As String   Dim sz As SIZE     'get the hdc to the main window     hDc = GetDC(Form1.hwnd)     'with the current font attributes, select the font     hFont = GetStockObject(ANSI_VAR_FONT)   hFontOld = SelectObject(hDc, hFont&)     'get its length, then calculate the average character width     tmp = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"   GetTextExtentPoint32(hDc, tmp, 52, sz)   avgWidth = (sz.cx \ 52)     're-select the previous font & delete the hDc     SelectObject(hDc, hFontOld)   DeleteObject(hFont)   ReleaseDC(Form1.hwnd, hDc)     'return the average character width     GetFontDialogUnits = avgWidthEnd Function'--end block--''------------------------------------------'' Form Code''------------------------------------------Option ExplicitPrivate Sub Command1_Click()   Dim cwidth As Long   Dim NewDropDownWidth As Long     'check if a number is entered into Text1.   'If not, bail out.   If Val(Text1.Text)      'here we simply set the dropdown list size to      'the value entered in Text1. Note: If the proposed      'width this is less than the width of the combo     'portion, the combo width is used (the dropdown      'can never be narrower than the combobox)      NewDropDownWidth = Val(Text1.Text)        'resize the dropdown portion of the combo box using SendMessage      Call SendMessage(Combo1.hwnd, CB_SETDROPPEDWIDTH, NewDropDownWidth, ByVal 0)        'reflect the new dropdown list width in the Label         cwidth = SendMessage(Combo1.hwnd, CB_GETDROPPEDWIDTH, 0, ByVal 0)      Label1.Caption = "Current dropdown width = " & cwidth & " pixels."        'drop the list down by code to show the new size         Call SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, True, ByVal 0)End SubPrivate Sub Command2_Click()   Dim cwidth As Long   Dim i As Long   Dim NumOfChars As Long   Dim LongestComboItem As Long   Dim avgCharWidth As Long   Dim NewDropDownWidth As Long     'loop through the combo entries, using SendMessage  'with CB_GETLBTEXTLEN to determine the longest item  'in the dropdown portion of the combo      For i = 0 To Combo1.ListCount - 1      NumOfChars = SendMessage(Combo1.hwnd, CB_GETLBTEXTLEN, i, ByVal 0)      If NumOfChars > LongestComboItem Then LongestComboItem = NumOfChars    Next     'get the average size of the characters using the   'GetFontDialogUnits API. Because a dummy string is   'used in GetFontDialogUnits, avgCharWidth is an   'approximation based on that string.      avgCharWidth = GetFontDialogUnits()     'compute the size the dropdown needs to be to accommodate  'the longest string. Here I subtract 2 because I find that  'on my system, using the dummy string in GetFontDialogUnits,  'the width is just a bit too wide.      NewDropDownWidth = (LongestComboItem - 2) * avgCharWidth     'resize the dropdown portion of the combo box      Call SendMessage(Combo1.hwnd, CB_SETDROPPEDWIDTH, NewDropDownWidth, ByVal 0)     'reflect the new dropdown list width in Label2 and in Text1      cwidth = SendMessage(Combo1.hwnd, CB_GETDROPPEDWIDTH, 0, ByVal 0)   Label1.Caption = "Current dropdown width = " & cwidth & " pixels."   Text1.Text = cwidth     'finally, drop the list down by code to show the new size      Call SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, True, ByVal 0)End Sub 

热点排行