1 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊
這是一個(gè)臨時(shí)解決方案,直到有人找到合適的解決方案。它通過(guò)在應(yīng)用程序的托盤(pán)圖標(biāo)鼠標(biāo)移動(dòng)事件中連續(xù)讀取和保存焦點(diǎn)窗口來(lái)工作。這個(gè)保存的窗口將被設(shè)置為在托盤(pán)圖標(biāo)鼠標(biāo)按下事件中聚焦:
[DllImport("user32.dll", ExactSpelling = true)]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
private void notifyIcon_MouseDown(object sender, MouseEventArgs e)
{
if (lastActiveWin != IntPtr.Zero)
{
SetForegroundWindow(lastActiveWin);
}
}
IntPtr lastActiveWin = IntPtr.Zero;
private void notifyIcon_MouseMove(object sender, MouseEventArgs e)
{
lastActiveWin = GetForegroundWindow();
}
- 1 回答
- 0 關(guān)注
- 86 瀏覽
添加回答
舉報(bào)