VB编程实用精典小技巧3例

2008-02-23 06:49:44来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

一、利用API 获取窗口的标题
新建窗体Form1和按钮Command1 ぴ诖疤迥?橹刑砑尤缦麓 码:
Option Explicit
Private Declare Function Get WindowText Lib "us—
er32"Alias "Get WindowTextA"(ByVal hwnd As
Long ,ByVal lpString As String ,ByVal cch As
Long)As Long
'在窗体声明节中加入API 函数“Get WindowText”的说明
'函数将向lpstring 中载入要获得的窗体caption
Private Sub Command1_Click()
Di mreturncode As Long
Di mcaptext As String
Di mcaplen As Long
captext =String$(100,0)
caplen =99
returncode =Get WindowText(ByVal me .hwnd ,
ByVal captext ,ByVal caplen)
print returncode
Print captext
Print caplen
End Sub

二、获取鼠标在当前窗口(客户区)的屏幕坐标 そ 立一新项目窗体form1并添加控件文本框Text1、Text2 ぴ诖疤迥?橹惺淙耄邯
Option Explicit
Private Declare Function GetCursorPos Lib "user32"
(lpPoint As POINTAPI)As Long
Private Type POINTAPI
XAs Long Y As Long
End Type
Di mpt As POINTAPI
Di mreturncode As Long
Private Sub Form_Load()
Text1.Text =""
Text2.Text =""
MaxButton =False
MinButton =False
Form1.WindowState =2
End Sub
Private Sub Form_MouseMove(Button As Integer ,
Shift As Integer ,XAs Single ,Y As Single)
'注意pt 结构是按引用传递的
returncode =GetCursorPos(pt)
Text1.Text =pt .X
Text2.Text =pt .Y
End Sub

三、记录Wi ndows 使用时间
建立新项目窗口form1,输入代码:
Private Sub Form_Load()
form1.visible =false
Open app .paht +"memo .txt"For Append As #1
Print #1,"启动windows :"&CStr(Now)
Close #1
End Sub
Private Sub Form_Unload(Cancel As Integer)
Open app .paht +"memo .txt"For Append As #1
Print #1,"关闭windows :"&CStr(Now)
Close #1
End
End Sub
最后将此程序加入启动组即可。

上一篇: 如何自动移动Mouse
下一篇: Visual Basic6.0实用编程技巧3例

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:加速Visual Basic For Application(VBA)

下一篇:树视TreeView树视的使用技巧