2011年5月17日 星期二

透過程式關閉 MsgBox

參考來源

---

Public Class Form1

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer



Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click

Me.Timer1.Enabled = True

Me.Timer1.Interval = 1000

MsgBox("測試", MsgBoxStyle.OkOnly, "MsgBox")

Me.Timer1.Enabled = False

End Sub



Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Dim hWnd As Integer

hWnd = FindWindow(vbNullString, "MsgBox")

If hWnd Then

PostMessage(hWnd, &H10, 0&, 0&)

End If

End Sub

End Class

---

以上為原著!

這篇不錯,竟有這想法;值得記一下timer的控制運用!

沒有留言:

張貼留言