VisualBasic6.0实用编程技巧3例
想不想get新技能酷炫一下,今天图老师小编就跟大家分享个简单的VisualBasic6.0实用编程技巧3例教程,一起来看看吧!超容易上手~
OptionExplicit
PrivateDeclareFunctionGetWindowTextLib"us—
er32"Alias"GetWindowTextA"(ByValhwndAs
Long,ByVallpStringAsString,ByValcchAs
Long)AsLong
'在窗体声明节中加入API函数“GetWindowText”的说明
'函数将向lpstring中载入要获得的窗体caption
PrivateSubCommand1_Click()
DimreturncodeAsLong
DimcaptextAsString
DimcaplenAsLong
captext=String$(100,0)
caplen=99
returncode=GetWindowText(ByValme.hwnd,
ByValcaptext,ByValcaplen)
printreturncode
Printcaptext
Printcaplen
EndSub
二、获取鼠标在当前窗口(客户区)的屏幕坐标そ立一新项目窗体form1并添加控件文本框Text1、Text2ぴ诖疤迥?橹惺淙耄邯
OptionExplicit
PrivateDeclareFunctionGetCursorPosLib"user32"
(lpPointAsPOINTAPI)AsLong
PrivateTypePOINTAPI
XAsLongYAsLong
EndType
DimptAsPOINTAPI
DimreturncodeAsLong
PrivateSubForm_Load()
Text1.Text=""
Text2.Text=""
MaxButton=False
MinButton=False
Form1.WindowState=2
EndSub
PrivateSubForm_MouseMove(ButtonAsInteger,
ShiftAsInteger,XAsSingle,YAsSingle)
'注意pt结构是按引用传递的
returncode=GetCursorPos(pt)
Text1.Text=pt.X
Text2.Text=pt.Y
EndSub
三、记录Windows使用时间
建立新项目窗口form1,输入代码:
PrivateSubForm_Load()
form1.visible=false
Openapp.paht+"memo.txt"ForAppendAs#1
Print#1,"启动windows:"&CStr(Now)
Close#1
EndSub
PrivateSubForm_Unload(CancelAsInteger)
Openapp.paht+"memo.txt"ForAppendAs#1
Print#1,"关闭windows:"&CStr(Now)
Close#1
End
EndSub
最后将此程序加入启动组即可。(->