Click here to Skip to main content
15,884,744 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
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!

C#
[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);


Any suggestions would be appreciated.

Thanks,
Vallarasu S.
Posted
Comments
Sergey Alexandrovich Kryukov 18-Nov-11 14:40pm    
Why using handle at all?!
--SA
VallarasuS 19-Nov-11 3:01am    
In the user view it may sound unnecessary, but for the needs of creating a custom window this is the preferred way!

1 solution

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:

C#
myForm.WindowState = WindowState.Minimized;

or, if you do it in the same class,
C#
this.WindowState = WindowState.Minimized;


—SA
 
Share this answer
 
Comments
VallarasuS 19-Nov-11 1:02am    
I've never been into mono! and not aware of it. The intention is not just to handle window state. By interpreting Windows procedure we can customize a lot more functions. However I've used the way suggested (http://www.codeproject.com/KB/dialog/MetroWindow.aspx), all i want to know if why this one fails.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900