2012-09-17 75 views
0

我似乎無法找到答案,這個看似簡單的問題在任何地方d:VB.NET檢查,如果形式集中

我想,如果集中在一個表格/窗口,這樣我只能閃光的檢測窗口如果不專注,這裏是代碼的位:

If Me.Focused = False Then ' Doesn't work D: please fix 
    Dim flash As New FLASHWINFO 
    flash.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(flash) '/// size of structure in bytes 
    flash.hwnd = MyBase.Handle '/// Handle to the window to be flashed 
    flash.dwFlags = FLASHW_ALL '/// to flash both the caption bar + the tray 
    flash.uCount = 5 '/// the number of flashes 
    flash.dwTimeout = 1000 '/// speed of flashes in MilliSeconds (can be left out) 
    '/// flash the window you have specified the handle for... 
    FlashWindowEx(flash) 
End If 

有沒有簡單的方法來使這項工作?

+0

[確定程序是否是.NET中的活動窗口]的可能重複(http://stackoverflow.com/questions/893669/determine-whether-program-is-the-active-window-in- net) –

+0

這是C#,這是VB -.- – King

+0

你讀過答案#2嗎?即使這個答案不是VB.NET,但是C#,這應該不會有真正的區別。 –

回答

0
Private Sub Form1_LostFocus(sender As Object, e As System.EventArgs) Handles Me.LostFocus 
    Dim flash As New FLASHWINFO 
    flash.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(flash) '/// size of structure in bytes 
    flash.hwnd = MyBase.Handle '/// Handle to the window to be flashed 
    flash.dwFlags = FLASHW_ALL '/// to flash both the caption bar + the tray 
    flash.uCount = 5 '/// the number of flashes 
    flash.dwTimeout = 1000 '/// speed of flashes in MilliSeconds (can be left out) 
    '/// flash the window you have specified the handle for... 
    FlashWindowEx(flash) 

    End Sub 
+0

wasent正是我​​正在尋找的東西,但是我已經將它工作到了我的代碼中;如果調用此函數,則使用設置爲false的變量,然後在重新建立焦點時使用true。 :)以便異步後臺工作人員可以知道是否集中或不在 – King

+0

說FLASHWINFO未定義。請糾正它。 – Kenta