VB编程实用精典小技巧3例
新建窗体Form1和按钮Command1ぴ诖疤迥?橹刑砑尤缦麓码:
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
  最后将此程序加入启动组即可。
- 上一篇:如何自动移动Mouse
 - 下一篇:VB查找并替换WORD文档中的字符串
 




