关于textout问题

lq__222 2007-04-25 06:22:08
我想改变textout字体为宋体小三号,代码如何写,我找了好多资料都写不出来,特来此找高手解决~
...全文
424 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainstormmaster 2007-04-26
  • 打赏
  • 举报
回复
Option Explicit

Private Const MM_ANISOTROPIC = 8
Private Const LF_FACESIZE = 32
Private Const DEFAULT_CHARSET = 1

Private Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName(0 To LF_FACESIZE - 1) As Byte
End Type
Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Declare Function TextOut Lib "gdi32.dll" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, source As Any, ByVal numBytes As Long)

Private Const TRANSPARENT = 1


Private Sub Command1_Click()

Dim hwnd As Long
Dim LF As LOGFONT
Dim hFont As Long, oldfont As Long
hwnd = GetDC(0)
CopyMemory LF.lfFaceName(0), ByVal CStr("宋体"), LenB(StrConv("宋体", vbFromUnicode)) + 1
LF.lfHeight = (18 * 20) / Screen.TwipsPerPixelY
LF.lfWidth = (18 * 20) / Screen.TwipsPerPixelY
LF.lfCharSet = DEFAULT_CHARSET
hFont = CreateFontIndirect(LF)
oldfont = SelectObject(hwnd, hFont)

Cls
SetBkMode hwnd, TRANSPARENT '设置透明
TextOut hwnd, 550, 150, "ttyy", 18
TextOut hwnd, 600, 150, "staifdsj", 18
DoEvents
End Sub
rainstormmaster 2007-04-26
  • 打赏
  • 举报
回复
我晕死,你不会用api浏览器自己添加声明吗?
lq__222 2007-04-26
  • 打赏
  • 举报
回复
楼上的同志,第二行编译出问题了,LOGFONT没定义???
rainstormmaster 2007-04-25
  • 打赏
  • 举报
回复
Dim hwnd As Long
Dim LF As LOGFONT
Dim hFont As Long, oldfont As Long
hwnd = GetDC(0)
RtlMoveMemory LF.lfFaceName(0), ByVal CStr("宋体"), LenB(StrConv("宋体", vbFromUnicode)) + 1
LF.lfHeight = (18 * 20) / Screen.TwipsPerPixelY
LF.lfWidth = (18 * 20) / Screen.TwipsPerPixelY
LF.lfCharSet = DEFAULT_CHARSET
hFont = CreateFontIndirect(LF)
oldfont = SelectObject(hwnd, hFont)

Cls
SetBkMode hwnd, TRANSPARENT '设置透明
TextOut hwnd, 550, 150, "ttyy", 18
TextOut hwnd, 600, 150, "staifdsj", 18
DoEvents
zdingyun 2007-04-25
  • 打赏
  • 举报
回复
关注!
lq__222 2007-04-25
  • 打赏
  • 举报
回复
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Declare Function TextOut Lib "gdi32.dll" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long

Private Const TRANSPARENT = 1

Private Sub Timer1_Timer()

Dim hwnd As Long
hwnd = GetDC(0)
Cls
SetBkMode hwnd, TRANSPARENT '设置透明
TextOut hwnd, 550, 150, "ttyy", 18
TextOut hwnd, 600, 150, "staifdsj", 18
DoEvents
End Sub
代码里要加些什么???

1,488

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧