熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

WinForm特效:桌面上的遮罩層

2013-11-13 09:45:03  來源: .NET編程 

  一個窗體特效幫你了解幾個windows api函數效果windows桌面上增加一個簡單的遮罩層其中WS_EX_TRANSPARENT 比較重要它實現了鼠標穿透的功能

  using System;
        using SystemDrawing;
        using SystemWindowsForms;
        using SystemRuntimeInteropServices;
        namespace WindowsApplication
        {
            public partial class Form : Form
            {
                public Form()
                {
                    InitializeComponent();
                }
                [DllImport(userdll EntryPoint = GetWindowLong)]
                public static extern long GetWindowLong(IntPtr hwnd int nIndex);
                [DllImport(userdll EntryPoint = SetWindowLong)]
                public static extern long SetWindowLong(IntPtr hwnd int nIndex long dwNewLong);
                [DllImport(user EntryPoint = SetLayeredWindowAttributes)]
                private static extern int SetLayeredWindowAttributes(IntPtr Handle int crKey byte bAlpha int dwFlags);
                const int GWL_EXSTYLE = ;
                const int WS_EX_TRANSPARENT = x;
                const int WS_EX_LAYERED = x;
                const int LWA_ALPHA = ;
                private void Form_Load(object sender EventArgs e)
                {
                    thisBackColor = ColorSilver;
                    thisTopMost = true;
                    thisFormBorderStyle = FormBorderStyleNone;
                    thisWindowState = FormWindowStateMaximized;
                    SetWindowLong(Handle GWL_EXSTYLE GetWindowLong(Handle GWL_EXSTYLE) | WS_EX_TRANSPARENT | WS_EX_LAYERED);
                    SetLayeredWindowAttributes(Handle LWA_ALPHA );
                }
            }
        }


From:http://tw.wingwit.com/Article/program/net/201311/11485.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.