如何在正常大小时阻止窗口闪烁 [英] How do I stop a window from flashing when its normal size
本文介绍了如何在正常大小时阻止窗口闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个像雅虎和PM的聊天服务,如果用户将聊天最小化并收到消息它应该闪橙色然后当他们点击它恢复正常时它会停止然而我的不会一直闪烁。
这是我正在使用的代码
I am creating a chat service like yahoo and on PM's if a user has the chat minimized and receives a message it should flash orange then when they click it to return to normal it will stop however mine don't it keeps flashing.
Here is the code I am using
[DllImport("user32.dll")]
static extern Int32 FlashWindowEx(ref FLASHWINFO pwfi);
[StructLayout(LayoutKind.Sequential)]
public struct FLASHWINFO
{
public UInt32 cbSize;
public IntPtr hwnd;
public Int32 dwFlags;
public UInt32 uCount;
public Int32 dwTimeout;
}
// stop flashing
const int FLASHW_STOP = 0;
// flash the window title
const int FLASHW_CAPTION = 1;
// flash the taskbar button
const int FLASHW_TRAY = 2;
const int FLASHW_ALL = 3;
// flash continuously
const int FLASHW_TIMER = 4;
// flash until the window comes to the foreground
const int FLASHW_TIMERNOFG = 12;
private void Flash(bool stop)
{
FLASHWINFO fw = new FLASHWINFO();
fw.cbSize = Convert.ToUInt32(Marshal.SizeOf(typeof(FLASHWINFO)));
fw.hwnd = Handle;
if (!stop)
fw.dwFlags = 2;
else
fw.dwFlags = 0;
fw.uCount = UInt32.MaxValue;
FlashWindowEx(ref fw);
}
然后在发送新聊天功能中我有以下
Then in the send new chat function I have the following
//flashing code
if (WindowState == FormWindowState.Minimized)
{
Flash(false);
}
if (WindowState == FormWindowState.Normal)
{
this.Focus();
Flash(true);
}
//End flashing code
所以让它停止闪烁是问题
任何帮助都会是一个巨大的帮助。
So making it stop flashing is the issue
any help would be a huge help.
推荐答案
为Activated添加处理程序或覆盖OnActivate方法。
< a href =https://msdn.microsoft.com/en-us/library/system.windows.forms.form.activated%28v=vs.110%29.aspx> https://msdn.microsoft.com /en-us/library/system.windows.forms.form.activated%28v=vs.110%29.aspx [ ^ ]
https: //msdn.microsoft.com/en-us/library/system.windows.forms.form.onactivated%28v=vs.110%29.aspx [ ^ ]
在处理程序中,调用Flash(false);
Add a handler for Activated or override the OnActivate method.
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.activated%28v=vs.110%29.aspx[^]
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.onactivated%28v=vs.110%29.aspx[^]
In the handler, call Flash(false);
private void Form1_Activated(object sender, System.EventArgs e)
{
Flash(false);
}
这篇关于如何在正常大小时阻止窗口闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文