作者:绿色风
分类:
时间:2022-08-17
浏览:124
楼主 xmyjk |
Q:如何运用API在窗体中输出文字?
A:- Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
- 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
- Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
- Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
- Private Sub CommandButton1_Click()
- Dim dc As Long, s As String, formhandle As Long
- formhandle = FindWindow(vbNullString, UserForm1.Caption)
- dc = GetDC(formhandle) '获取窗体句柄的DC
- s = "你好"
- Call SetBkColor(dc, &HF0F0F0) '设置绘制区域的背景色,也起清除作用
- Call TextOut(dc, 10, 10, s, LenB(s)) '输出文本!
- Call Sleep(40) '等待
- Call ReleaseDC(formhandle, dc) '释放资源!
- End Sub
窗体文字.zip |
2楼 lnt1231 |
向妃公致敬 |
3楼 老糊涂 |
学习 |
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一