ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > E问E答 > Excel VBA > 如何运用API在窗体中输出文字

如何运用API在窗体中输出文字

作者:绿色风 分类: 时间:2022-08-17 浏览:124
楼主
xmyjk
Q:如何运用API在窗体中输出文字?

A:
  1. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
  2. Private Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
  3. Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
  4. Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
  5. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  6. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

  7. Private Sub CommandButton1_Click()
  8.     Dim dc As Long, s As String, formhandle As Long
  9.     formhandle = FindWindow(vbNullString, UserForm1.Caption)
  10.     dc = GetDC(formhandle)    '获取窗体句柄的DC
  11.     s = "你好"
  12.     Call SetBkColor(dc, &HF0F0F0)  '设置绘制区域的背景色,也起清除作用
  13.     Call TextOut(dc, 10, 10, s, LenB(s))    '输出文本!
  14.     Call Sleep(40)    '等待
  15.     Call ReleaseDC(formhandle, dc)  '释放资源!
  16. End Sub

窗体文字.zip
2楼
lnt1231
向妃公致敬
3楼
老糊涂
学习

免责声明

有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素, 经与ExcelTip.Net站长Apolloh商议并征得其同意, 现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示, 供有需要的人士查询使用,也慰缅曾经的论坛时代。 所示各个帖子的原作者如对版权有异议, 可与本人沟通提出,或于本站点留言,我们会尽快处理。 在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一

评论列表
sitemap