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

            }
  • 相关阅读:
    Android网络项目课程笔记-----系统设置_首选项框架&Holo风格的设置
    Android网络项目课程笔记-----加载数据
    Android网络项目课程笔记-----代码复用性
    Android网络项目课程笔记-----AdapterView嵌套
    Android网络项目课程笔记-----滑动Banner
    Android网络项目课程笔记-----滑动Tab&Banner
    Android网络项目课程笔记-----页面结构
    Android网络项目课程笔记-----欢迎页面新手引导
    C#调用SAP S4/HANA Gateway Service
    CefSharp试用
  • 原文地址:https://www.cnblogs.com/hetonghai/p/1207055.html
Copyright © 2011-2022 走看看