SendMessage WM_SYSCOMMAND无法最小化窗口? [英] SendMessage WM_SYSCOMMAND fails to minimize a window?!

查看:279
本文介绍了SendMessage WM_SYSCOMMAND无法最小化窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码片段,无法最小化窗口!唯一的区别是FormBorderStyle设置为none,但是更改此成员无效!

I have the following code snippet that fails to minimize the window! the only difference is the FormBorderStyle is set to none, howevere changing this member has no effect!

[DllImport("User32.DLL")]
public static extern int SendMessage(IntPtr hWnd, UInt32 Msg, Int32 wParam, Int32 lParam);
public const Int32 WM_SYSCOMMAND = 0x112;
public const Int32 SC_MINIMIZE = 0xF020;

    /*invoked from a control added in the form*/
    SendMessage(FindForm().Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0);



任何建议,将不胜感激.

谢谢,
Vallarasu S.



Any suggestions would be appreciated.

Thanks,
Vallarasu S.

推荐答案

在Forms应用程序中使用原始Windows消息确实是一件坏事.您是否知道编写准确的Forms应用程序不仅可以在Windows上运行,而且可以在无需重新编译的许多平台上运行(在Mono下)?一次使用HWMD将立即破坏此出色功能,并损害与未来平台的潜在兼容性.一定要避免!

纯.NET解决方案几乎总是可行的.请执行以下操作:

Using raw Windows messages in Forms application is really bad thing. Do you know that accurately written Forms application will run not on just Windows, but on many platforms without recompilation (under Mono)? A single use of HWMD will spoil this wonderful feature immediately and compromise potential compatibility with future platforms. Avoid it by all means!

Pure .NET solutions are nearly always possible. Do this:

myForm.WindowState = WindowState.Minimized;


或者,如果您在同一堂课上做,


or, if you do it in the same class,

this.WindowState = WindowState.Minimized;



—SA



—SA


这篇关于SendMessage WM_SYSCOMMAND无法最小化窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆