vb中,如何使计时器在离开窗口后停止跳动,当回到窗口后继续跳动_百度知 ...
发布网友
发布时间:2024-05-30 14:13
我来回答
共3个回答
热心网友
时间:2024-07-27 19:36
那就你在加载那个显示窗口的时候也就是这样说吧 比如你说的是你的两个窗口,同一程序的
那么private sub form_load() timer1.enabled=ture form2.timer1.enabled=false '这里就是令另一窗口的计时器停止计时了 end sub
热心网友
时间:2024-07-27 19:35
使用子类化拦截窗体消息比较好 '模块代码
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hWnd As Long, ByVal _
wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_NCACTIVATE = &H86
Public Const GWL_WNDPROC = (-4)
Public OldWndProc&
Public Function Hook&(ByVal hWnd1&)
OldWndProc = SetWindowLong(hWnd1, GWL_WNDPROC, AddressOf NewWndProc)
Hook = OldWndProc
End Function
Public Sub UnHook(ByVal hWnd1&)
SetWindowLong hWnd1, GWL_WNDPROC, OldWndProc
End Sub
Public Function NewWndProc&(ByVal hWnd1&, ByVal uMsg&, ByVal wParam&, ByVal lParam&)
If uMsg = WM_NCACTIVATE Then
If wParam = 0 Then '失去焦点
Debug.Print "窗口失去了焦点"
Else '得到焦点
Debug.Print "窗口得到了焦点"
End If
End If
NewWndProc = CallWindowProc(OldWndProc, hWnd1, uMsg, wParam, lParam)
End Function
'窗口代码
Private Sub Form_Load()
Hook Me.hWnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnHook Me.hWnd
End Sub
热心网友
时间:2024-07-27 19:35
form2的代码:Private Sub Command1_Click()
Form2.Hide
Form1.Show
Timer1.Enabled = False
End SubPrivate Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 1000
Text1.Text = 1
End SubPrivate Sub Timer1_Timer()
Text1.Text = Text1.Text + 1
End Sub
form1的代码:Private Sub Command1_Click()
Form1.Hide
Form2.Show
Form2.Timer1.Enabled = True
End Sub