protected override IntPtr CreateWindow(int x, int y, int width, int height, string title, IntPtr parentHandle)
        {
            // Set ex style similiar to wpf
            var value1 = (ExtendedWindowStyle)Functions.SetWindowLong(
                parentHandle, -20, (int)(ExtendedWindowStyle.WindowEdge | ExtendedWindowStyle.ApplicationWindow));

            // Set style similiar to wpf, without ClipChildren -> flicker
            var value2 = (WindowStyle)Functions.SetWindowLong(
                parentHandle, -16, (int)(WindowStyle.ClipSiblings | WindowStyle.ClipChildren | WindowStyle.Caption | WindowStyle.SystemMenu | WindowStyle.ThickFrame | WindowStyle.Group | WindowStyle.TabStop));

            var wc = new ExtendedWindowClass();

            wc.Size      = ExtendedWindowClass.SizeInBytes;
            wc.Style     = ClassStyle.OwnDC | ClassStyle.HorizontalRedraw | ClassStyle.VerticalRedraw;
            wc.Instance  = Instance;
            wc.WndProc   = WindowProcedureDelegate;
            wc.ClassName = ClassName;
            wc.Icon      = IntPtr.Zero;
            wc.IconSm    = IntPtr.Zero;
            //wc.Background = IntPtr.Zero;
            wc.Background = Functions.CreateSolidBrush((uint)System.Drawing.ColorTranslator.ToWin32(System.Drawing.Color.Green));
            wc.Cursor     = Functions.LoadCursor();
            ushort atom = Functions.RegisterClassEx(ref wc);

            if (atom == 0)
            {
                throw new Exception(String.Format("Failed to register window class. Error: {0}", Marshal.GetLastWin32Error()));
            }

            IntPtr window_name = Marshal.StringToHGlobalAuto(title);
            IntPtr handle      = Functions.CreateWindowEx(
                0, ClassName, window_name, WindowStyle.Visible | WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings,
                x, y, width, height,
                parentHandle, IntPtr.Zero, Instance, IntPtr.Zero);

            if (handle == IntPtr.Zero)
            {
                throw new Exception(String.Format("Failed to create window. Error: {0}", Marshal.GetLastWin32Error()));
            }

            return(handle);
        }
예제 #2
0
 public static extern ushort RegisterClassEx(ref ExtendedWindowClass window_class);