询问者
C#如何实现WPF程序窗口当用户使用Win+D快捷键后,不让窗体实现最小化操作?

问题
-
C#如何实现WPF程序窗口当用户使用Win+D快捷键后,不让窗体实现最小化操作?在网上看到一些答案,都会使用SetParent和FindWindow两个系统API,但是我在Window_Load事件里面写的时候,当程序运行后窗口打不开了???希望各位能帮我解决Win+D不会把C#程序里面的窗口最小化。
- 已移动 ThankfulHeart 2013年5月1日 4:02 WPF问题
全部回复
-
可以把 你Window_Load里怎么做的贴出来吗?谢谢。
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
[DllImport("User32.dll", EntryPoint = "SetParent", SetLastError = true)]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);[DllImport("User32.dll", EntryPoint = "FindWindow", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);public Window1(){
this.SourceInitialized += (sender, e) =>
{
this._hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
this._handle = this._hwndSource.Handle;
};this.Load+=this.Window1_Load;
}
Window1_Load(object sender,EventArgs e){
SetParent(this._handle , FindWindow("Progman", "Program Manager"));
}
-
Program Manager是一个什么样的程序?
不管怎样试试这个方法:
1. 将Window.WindowStyle 设为 WindowStyle.None
2. 在右上角自己定义三个button。
3. 设置一个全局变量,表示是否是自定义的这个button按下。
4. 处理StateChanged事件:先判断flag:
private bool flag; private void button1_Click(object sender, RoutedEventArgs e) { flag = true; this.WindowState = System.Windows.WindowState.Minimized ; } private void Window_StateChanged(object sender, EventArgs e) { if (this.WindowState == System.Windows.WindowState.Minimized) { if (flag == false) { this.WindowState = System.Windows.WindowState.Normal; } } else flag = false; }
5. Set the topmost to true: http://msdn.microsoft.com/en-us/library/system.windows.window.topmost.aspx
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已编辑 Mike Feng 2013年5月1日 10:24
- 已建议为答案 Lisa ZhuModerator 2013年5月2日 12:28
- 已标记为答案 Lisa ZhuModerator 2013年5月2日 12:29
- 取消答案标记 孔雀 2013年5月6日 1:27
-
你说的有道理,但是我也试过了,如果屏蔽Win键,那么所有的程序都不会最小化。但我想要的是像QQ那样,只有自己的程序不最小化,而其他正在运行的程序还必须最小化。
你好 ,麻烦问下 我的代码 在你那边是什么效果?
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.