Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Long
解决方案 »
- 为什么在代码窗体鼠标显示正常,而在界面窗体鼠标就变成十字了?
- 有办法让msgflexgrid的滚动条不管数据有无都显示出来可以做到吗?
- 请问怎样遍历VB菜单项item(名称)?(送分)
- 要合并多行多列中相同内容的单元格,用什么控件可以做到?
- 我怎样用存放路径的方法来显示数据库中的图片?请高手急救!谢谢!!
- 一个关于WORD节的问题
- 如何把 Crystal Report 打进安装程序?
- 用ACCESS能做网络版的软件吗
- 如何工具栏的toolbar事件中触发form表单上一个按钮的onclick事件?
- 怎么判断一个文件被打开了?
- 一个瞬间创意,等待着您的加入(欢迎vb编程爱好者入内)
- 在WebBrowser中,怎样判断一个网站正确连接了,还是该网页打开错误?
next
GetWindowText()
List1.AddItem GetActiveWindow
End Sub我运行后,切换到EXCEL并输入一些数据,再切换回来,发现List1中除了0就是VB的窗口的句柄,难道在EXCEL输入数据,EXCEL窗口还不算是活动窗口吗?
'- two timers, interval=100
'- a button'in general section
Private Type POINTAPI
x As Long
y As Long
End TypePrivate Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As LongPrivate 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 GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
Timer2.Interval = 100
Timer2.Enabled = True
Command1.Caption = "Draw Text"
End Sub
'This will draw an Ellipse on the active window
Sub Timer1_Timer()
Dim Position As POINTAPI
'Get the cursor position
GetCursorPos Position
'Draw the Ellipse on the Screen's DC
Ellipse GetWindowDC(0), Position.x - 5, Position.y - 5, Position.x + 5, Position.y + 5
End Sub
Sub Command1_Click()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: [email protected] Dim intCount As Integer, strString As String
strString = "Cool, text on screen !"
For intCount = 0 To 30
'Draw the text on the screen
TextOut GetWindowDC(0), intCount * 20, intCount * 20, strString, Len(strString)
Next intCount
End Sub
Private Sub Timer2_Timer()
'Draw the text to the active window
TextOut GetWindowDC(GetActiveWindow), 50, 50, "This is a form", 14
End Sub
GetActiveWindow只可得到自己开发的程序的活动窗口,应该用GetForegroundWindow,再用GetWindowText,谢谢ygd(小小大圣)提醒我.