C # how to embed winform into the bottom layer of the desktop window

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.