在vb6中使用计时器 [英] qestion using timer in vb6

查看:143
本文介绍了在vb6中使用计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码来获取当前打开的excel文件的标题,此代码正常工作。如果标题更改,我会每隔10秒使用一次计时器,然后在list1中添加新标题。



所以问题是有任何方法或事件来检测标题是否更改然后我的代码工作否则它不工作不检查。如果我运行此代码,我的电脑工作每10秒钟定时检查一次







I have following code to get title of current opened excel file this code working fine. I use timer to every 10 seconds if title change then add new title in list1.

So question is there any method or event to detect if title change then my code work otherwise it not work not check. timer check every 10 seconds my pc work slow if I run this code



Private Const GW_HWNDNEXT = 2
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Sub ListWins(Optional Title = "*", Optional Class = "*")
  Dim hWndThis As Long

  hWndThis = FindWindow(vbNullString, vbNullString)

  While hWndThis
    Dim sTitle As String, sClass As String
    sTitle = Space$(255)
    sTitle = Left$(sTitle, GetWindowText(hWndThis, sTitle, Len(sTitle)))

    sClass = Space$(255)
    sClass = Left$(sClass, GetClassName(hWndThis, sClass, Len(sClass)))

    If sTitle Like Title And sClass Like Class Then
      Debug.Print sTitle, sClass
      List1.AddItem (sTitle)
    End If

    hWndThis = GetWindow(hWndThis, GW_HWNDNEXT)
  Wend

Private Sub Timer1_Timer()
 ListWins "*.xls*"
End Sub

推荐答案

255
sTitle = Left
(255) sTitle = Left


(sTitle,GetWindowText(hWndThis,sTitle,Len(sTitle)))

sClass = Space
(sTitle, GetWindowText(hWndThis, sTitle, Len(sTitle))) sClass = Space


255
sClass = Left
(255) sClass = Left


这篇关于在vb6中使用计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆