zoukankan      html  css  js  c++  java
  • 【转】如何让你的WinForm嵌入桌面

    如何让你的WinForm嵌入桌面

    新一篇: SyntaxHighlighter part1

    首先, 调用一些User32.dll的WinAPI函数

    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);
        }

     转自: http://blog.csdn.net/leomaya/archive/2007/10/26/1845950.aspx

    然后, 在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, 10000, 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, 10000, User32.SE_SHUTDOWN_PRIVILEGE);
                }

            }


            
    private void MainForm_Paint(object sender, PaintEventArgs e)
            
    {
                
    if (Environment.OSVersion.Version.Major >= 6)
                
    {
                    User32.SetWindowPos(
    base.Handle, 10000, User32.SE_SHUTDOWN_PRIVILEGE);
                }

            }
  • 相关阅读:
    读《大道至简》第二章有感
    读大道至简之感
    C#学习笔记二:并行编程基础:在 PLINQ 和 TPL 中的 Lambda 表达式
    C#学习笔记一:委托、匿名函数、Lambda 表达式
    VS2013 最常用 和 不是最常用的快捷键备忘
    EntityFramework初上手
    C#的值类型,引用类型,栈,堆,ref,out
    python批量下载图片
    django部署for新浪SAE
    Linux下安装搜狗拼音输入法
  • 原文地址:https://www.cnblogs.com/hetonghai/p/1207055.html
Copyright © 2011-2022 走看看