창 을 설정 하면 마우스 드래그 크기 로 통과 할 수 있 습 니 다.

4985 단어 쓰다
private void Window_Loaded(object sender, RoutedEventArgs e)

        {

            //        

            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;



            //          

            int oldstyle = NativeMethods.GetWindowLong(hwnd, NativeMethods.GWL_STYLE);



            //               

            NativeMethods.SetWindowLong(hwnd, NativeMethods.GWL_STYLE, oldstyle & ~NativeMethods.WS_CAPTION);



            // SetWindowLong(hwnd, GWL_EXSTYLE, oldstyle & ~WS_EX_LAYERED); 

            // 1 | 2 << 8 | 3 << 16  r=1,g=2,b=3   winuse.h   

            //           

            NativeMethods.SetLayeredWindowAttributes(hwnd, 1 | 2 << 8 | 3 << 16, 0, NativeMethods.LWA_ALPHA);



            //         12                 

            NativeMethods.SetWindowRgn(hwnd, NativeMethods.CreateRoundRectRgn(0, 0, Convert.ToInt32(this.ActualWidth), Convert.ToInt32(this.ActualHeight), 12, 12), true); 

        }


  
NativeMethods.cs   :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;



namespace SEsoft

{

    public class NativeMethods

    {

        /// <summary> 

        ///          windows    

        /// </summary> 

        public const int WS_CAPTION = 0X00C0000;



        /// <summary> 

        /// window           

        /// </summary> 

        public const int WS_EX_LAYERED = 0x00080000;



        /// <summary> 

        ///   alpha    

        /// </summary> 

        public const int LWA_ALPHA = 0x00000002;



        /// <summary> 

        ///      

        /// </summary> 

        public const int LWA_COLORKEY = 0x00000001;



        /// <summary> 

        /// window      

        /// </summary> 

        public const int GWL_STYLE = -16;



        /// <summary> 

        /// window      

        /// </summary> 

        public const int GWL_EXSTYLE = -20;



        /// <summary> 

        ///         

        /// </summary> 

        /// <param name="handle">       </param> 

        /// <param name="oldStyle">           .</param> 

        /// <param name="newStyle">   </param> 

        [System.Runtime.InteropServices.DllImport("User32.dll")]

        public static extern void SetWindowLong(IntPtr handle, int oldStyle, int newStyle);



        /// <summary> 

        ///          . 

        /// </summary> 

        /// <param name="handle">       </param> 

        /// <param name="style">        </param> 

        /// <returns>  window   </returns> 

        [System.Runtime.InteropServices.DllImport("User32.dll")]

        public static extern int GetWindowLong(IntPtr handle, int style);



        /// <summary> 

        ///          . 

        /// </summary> 

        /// <param name="handle">       .</param> 

        /// <param name="handleRegion">         .</param> 

        /// <param name="regraw">if set to <c>true</c> [regraw].</param> 

        /// <returns>   </returns> 

        [System.Runtime.InteropServices.DllImport("User32.dll")]

        public static extern int SetWindowRgn(IntPtr handle, IntPtr handleRegion, bool regraw);



        /// <summary> 

        ///          . 

        /// </summary> 

        /// <param name="x1">      X .</param> 

        /// <param name="y1">      Y .</param> 

        /// <param name="x2">      X .</param> 

        /// <param name="y2">      Y .</param> 

        /// <param name="width">     width.</param> 

        /// <param name="height">     height.</param> 

        /// <returns>hRgn   </returns> 

        [System.Runtime.InteropServices.DllImport("gdi32.dll")]

        public static extern IntPtr CreateRoundRectRgn(int x1, int y1, int x2, int y2, int width, int height);



        /// <summary> 

        /// Sets the layered window attributes. 

        /// </summary> 

        /// <param name="handle">          </param> 

        /// <param name="colorKey">RGB  </param> 

        /// <param name="alpha">Alpha  ,   </param> 

        /// <param name="flags">    </param> 

        /// <returns>true or false</returns> 

        [System.Runtime.InteropServices.DllImport("User32.dll")]

        public static extern bool SetLayeredWindowAttributes(IntPtr handle, uint colorKey, byte alpha, int flags);

    }

}


  

좋은 웹페이지 즐겨찾기