C # how to embed winform into the bottom layer of the desktop window 2010-03-26 from: csdnblog
- Abstract:This article introduces C # using Windows API functions: setparent, setwindowpos, and findwindow to embed winform into the bottom layer of the desktop window and provide detailed implementation.CodeFor reference.
This class always places the form at the bottom of the window.
First, call some winapi functions of user32.dll.
Internal Class USER32
{
Public Const Int Se_shutdown_privilege = 0x13 ;
[Dllimport ( " User32.dll " )]
Public Static Extern Intptr findwindow ( String Lpclassname, String Lpwindowname );
[Dllimport ( " User32.dll " )]
Public Static Extern Intptr setparent (intptr hwndchild, intptr hwndnewparent );
[Dllimport ( " User32.dll " )]
Public Static Extern Bool Setwindowpos (intptr hwnd, Int Hwndinsertafter, Int X, Int Y, Int CX,
Int Cy, Uint Uflags );
}
Then, in winform:
Public Mainform ()
{
Initializecomponent ();
Try
{
If (Environment. osversion. version. Major < 6 )
{
Base . Sendtoback ();
Intptr hwndnewparent = User32.findwindow ( " Progman " , Null );
User32.setparent ( Base . Handle, hwndnewparent );
}
Else
{
User32.setwindowpos ( Base . Handle, 1 , 0 , 0 , 0 , 0 , User32.se _ shutdown_privilege );
}
}
Catch (Applicationexception Exx)
{
MessageBox. Show ( This , Exx. Message, " PIN to desktop " );
}
}
Private Void Mainform_activated ( Object Sender, eventargs E)
{
If (Environment. osversion. version. Major > = 6 )
{
User32.setwindowpos ( Base . Handle, 1 , 0 , 0 , 0 , 0 , User32.se _ shutdown_privilege );
}
}
Private Void Mainform_paint ( Object Sender, painteventargs E)
{
If (Environment. osversion. version. Major > = 6 )
{
User32.setwindowpos ( Base . Handle, 1 , 0 , 0 , 0 , 0 , User32.se _ shutdown_privilege );
}
}
The above section describes how to embed winform into the bottom layer of the desktop window in C #, which is helpful to you.
Author: zfrong