Ejemplo n.º 1
0
		public static Size GetTextSize(Graphics graphics, string text, Font font)
		{
			IntPtr hdc = IntPtr.Zero;
			if ( graphics != null )
			{
				// Get device context from the graphics passed in
				hdc = graphics.GetHdc();
			}
			else
			{
				// Get screen device context
				hdc = WindowsAPI.GetDC(IntPtr.Zero);
			}

			IntPtr fontHandle = font.ToHfont();
			IntPtr currentFontHandle = WindowsAPI.SelectObject(hdc, fontHandle);

			Win32.RECT rect = new Win32.RECT();
			rect.left = 0;
			rect.right = 0;
			rect.top = 0;
			rect.bottom = 0;

			WindowsAPI.DrawText(hdc, text, text.Length, ref rect,
				(int)(DrawTextFormatFlags.DT_SINGLELINE | DrawTextFormatFlags.DT_LEFT | DrawTextFormatFlags.DT_CALCRECT));
			WindowsAPI.SelectObject(hdc, currentFontHandle);
			WindowsAPI.DeleteObject(fontHandle);

			if ( graphics != null )
				graphics.ReleaseHdc(hdc);
			else
				WindowsAPI.ReleaseDC(IntPtr.Zero, hdc);

			return new Size(rect.right - rect.left, rect.bottom - rect.top);
		}
Ejemplo n.º 2
0
 protected override void OnPaint(PaintEventArgs e)
 {
     IntPtr data=Win32.OpenThemeData2(this.Handle,"Scrollbar");
     if (data!=IntPtr.Zero)//mit xp themes
     {
         IntPtr hdc=e.Graphics.GetHdc();
         Win32.RECT rct=new Win32.RECT(0,0,this.Width,this.Height);
         Win32.DrawThemeBackground2(data,hdc,4,4,ref rct);
         rct=base._elems[0].Bounds; rct.Top--;
         Win32.DrawThemeBackground2(data,hdc,1,(int)base._elems[0].State+8,ref rct);
         rct=base._elems[1].Bounds; rct.Top--;
         Win32.DrawThemeBackground2(data,hdc,1,(int)base._elems[1].State+12,ref rct);
         rct=base._elems[2].Bounds; rct.Top--;
         Win32.DrawThemeBackground2(data,hdc,2,(int)base._elems[2].State,ref rct);
         e.Graphics.ReleaseHdc(hdc);
         Win32.CloseThemeData2(data);
     }
     else//ohne xpthemes, einfache rechtecke
     {
         e.Graphics.FillRectangle(SystemBrushes.ControlLightLight,this.ClientRectangle);
         ControlPaint.DrawScrollButton(e.Graphics,base._elems[0].Bounds,ScrollButton.Left,base._elems[0].ToButtonState());
         ControlPaint.DrawScrollButton(e.Graphics,base._elems[1].Bounds,ScrollButton.Right,base._elems[1].ToButtonState());
         ControlPaint.DrawButton(e.Graphics,base._elems[2].Bounds,ButtonState.Normal);
     }
     using(StringFormat fmt=new StringFormat(StringFormatFlags.NoWrap))
     {
         fmt.LineAlignment=fmt.Alignment=StringAlignment.Center;
         e.Graphics.DrawString(base.Value.ToString(),base.Font,
             this.Enabled?Brushes.Black:Brushes.Gray,base._elems[2].Bounds,fmt);
     }
 }
Ejemplo n.º 3
0
		public static Size GetTextSize(Graphics graphics, string text, Font font, ref Rectangle rc, DrawTextFormatFlags drawFlags)
		{
			IntPtr hdc = IntPtr.Zero;
			if ( graphics != null )
			{
				// Get device context from the graphics passed in
				hdc = graphics.GetHdc();
			}
			else
			{
				// Get screen device context
				hdc = WindowsAPI.GetDC(IntPtr.Zero);
			}

			IntPtr fontHandle = font.ToHfont();
			IntPtr currentFontHandle = WindowsAPI.SelectObject(hdc, fontHandle);

			Win32.RECT rect = new Win32.RECT();
			rect.left = rc.Left;
			rect.right = rc.Right;
			rect.top = rc.Top;
			rect.bottom = rc.Bottom;

			WindowsAPI.DrawText(hdc, text, text.Length, ref rect, (int)drawFlags);
			WindowsAPI.SelectObject(hdc, currentFontHandle);
			WindowsAPI.DeleteObject(fontHandle);

			if ( graphics != null )
				graphics.ReleaseHdc(hdc);
			else
				WindowsAPI.ReleaseDC(IntPtr.Zero, hdc);

			return new Size(rect.right - rect.left, rect.bottom - rect.top);

		}
        /// <summary>
        /// Retrieves DPI information when running on Windows 8.1 and higher.
        /// </summary>
        private Boolean InitWindows8_1(UltravioletContext uv, IUltravioletDisplay display)
        {
            if (uv.Platform != UltravioletPlatform.Windows || Environment.OSVersion.Version < new Version(6, 3))
                return false;

            var rect = new Win32.RECT
            {
                left   = display.Bounds.Left,
                top    = display.Bounds.Top,
                right  = display.Bounds.Right,
                bottom = display.Bounds.Bottom 
            };

            var hmonitor = IntPtr.Zero;

            Win32.EnumDisplayMonitors(IntPtr.Zero, &rect, (hdc, lprcClip, lprcMonitor, dwData) =>
            {
                hmonitor = hdc;
                return false;
            }, IntPtr.Zero);

            if (hmonitor == IntPtr.Zero)
                return false;

            UInt32 x, y;
            Win32.GetDpiForMonitor(hmonitor, 0, out x, out y);

            this.densityX      = x;
            this.densityY      = y;
            this.densityScale  = x / 96f;
            this.densityBucket = GuessBucketFromDensityScale(densityScale);

            return true;
        }
        /// <summary>
        /// フックプロシージャ
        /// </summary>
        /// <param name="nCode"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        private IntPtr HookProc( int nCode, IntPtr wParam, IntPtr lParam )
        {
            if( nCode == (int)Win32.HCBT.ACTIVATE )
            {
                Win32.RECT rcForm = new Win32.RECT( 0, 0, 0, 0 );
                Win32.RECT rcMsgBox = new Win32.RECT( 0, 0, 0, 0 );

                Win32.Api.GetWindowRect( m_ownerWindow.Handle, out rcForm );
                Win32.Api.GetWindowRect( wParam, out rcMsgBox );

                // センター位置を計算する。
                int x = ( rcForm.Left + ( rcForm.Right - rcForm.Left ) / 2 ) - ( ( rcMsgBox.Right - rcMsgBox.Left ) / 2 );
                int y = ( rcForm.Top + ( rcForm.Bottom - rcForm.Top ) / 2 ) - ( ( rcMsgBox.Bottom - rcMsgBox.Top ) / 2 );

                Win32.Api.SetWindowPos( wParam, 0, x, y, 0, 0, Win32.SWP.NOSIZE | Win32.SWP.NOZORDER | Win32.SWP.NOACTIVATE );

                IntPtr result = Win32.Api.CallNextHookEx( m_hHook, nCode, wParam, lParam );

                // フックを解除する。
                Win32.Api.UnhookWindowsHookEx( m_hHook );
                m_hHook = IntPtr.Zero;

                return result;

            }
            else
            {
                return Win32.Api.CallNextHookEx( m_hHook, nCode, wParam, lParam );
            }
        }
Ejemplo n.º 6
0
        private static void CenterWindowOnParent(IntPtr hChildWnd_)
        {
            Win32.RECT rcChild = new Win32.RECT();
            Win32.GetWindowRect(hChildWnd_, ref rcChild);
            int cxChild = rcChild.right - rcChild.left;
            int cyChild = rcChild.bottom - rcChild.top;

            IntPtr hParent = Win32.GetParent(hChildWnd_);
            Win32.RECT rcParent = new Win32.RECT();
            Win32.GetWindowRect(hParent, ref rcParent);
            int cxParent = rcParent.right - rcParent.left;
            int cyParent = rcParent.bottom - rcParent.top;

            int x = rcParent.left + (cxParent - cxChild) / 2;
            int y = rcParent.top + (cyParent - cyChild) / 2;
            uint uFlags = 0x15;

            Win32.SetWindowPos(hChildWnd_, IntPtr.Zero, x, y, 0, 0, uFlags);
        }
Ejemplo n.º 7
0
    public static Size GetTextSize( Graphics g, string text, Font font, ref Rectangle rc, DrawTextFormatFlags drawFlags )
    {
      IntPtr hdc = GetGraphicsHDC( g );
      IntPtr hFont = font.ToHfont();
      IntPtr hOldFont = WindowsAPI.SelectObject( hdc, hFont );
      
      Win32.RECT rect = new Win32.RECT();
      rect.left   = rc.Left;
      rect.right  = rc.Right;
      rect.top    = rc.Top;
      rect.bottom = rc.Bottom;
    
      WindowsAPI.DrawText( hdc, text, text.Length, ref rect, (int)drawFlags );
      WindowsAPI.SelectObject( hdc, hOldFont );
      WindowsAPI.DeleteObject( hFont );

      ReleaseGraphicHDC( g, hdc );
              
      return ( Size )rect;
    }
Ejemplo n.º 8
0
        public static Size GetTextSize(Graphics g, string text, Font font, ref Rectangle rc, DrawTextFormatFlags drawFlags)
        {
            IntPtr hdc      = GetGraphicsHDC(g);
            IntPtr hFont    = font.ToHfont();
            IntPtr hOldFont = WindowsAPI.SelectObject(hdc, hFont);

            Win32.RECT rect = new Win32.RECT();
            rect.left   = rc.Left;
            rect.right  = rc.Right;
            rect.top    = rc.Top;
            rect.bottom = rc.Bottom;

            WindowsAPI.DrawText(hdc, text, text.Length, ref rect, (int)drawFlags);
            WindowsAPI.SelectObject(hdc, hOldFont);
            WindowsAPI.DeleteObject(hFont);

            ReleaseGraphicHDC(g, hdc);

            return(( Size )rect);
        }
Ejemplo n.º 9
0
        void CopyFrontBufferToBack( /*IntPtr hWnd*/)
        {
            Gl.glDisable(Gl.GL_ALPHA_TEST);
                if (!Types.iBugWhiteout)
                {
                    // Found this by accident; Adam likes it.  Freakshow option #1.
                    Gl.glDisable(Gl.GL_BLEND);
                }
                Win32.RECT rct=new Win32.RECT();
                Win32.User.GetWindowRect(Video.WindowHandle, ref rct);

                Gl.glReadBuffer(Gl.GL_FRONT);
                Gl.glDrawBuffer(Gl.GL_BACK);
                Gl.glRasterPos2i(0, 0);
                Gl.glCopyPixels(0, 0, rct.Right, rct.Bottom, Gl.GL_COLOR);
                if (!Types.iBugWhiteout)
                {
                    Gl.glEnable(Gl.GL_BLEND);
                }
                Gl.glEnable(Gl.GL_ALPHA_TEST);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Draw a themed background element.
        /// </summary>
        /// <param name="g">Graphics object reference.</param>
        /// <param name="draw">Rectangle for drawing.</param>
        /// <param name="part">Theme part.</param>
        /// <param name="state">Theme state of part.</param>
        public void DrawThemeBackground(Graphics g, Rectangle draw, int part, int state)
        {
            if (IsControlThemed)
            {
                // Create a Win32 version of the drawing Rectangle
                Win32.RECT drawWin32 = new Win32.RECT();
                drawWin32.left   = draw.X;
                drawWin32.top    = draw.Y;
                drawWin32.right  = draw.Right;
                drawWin32.bottom = draw.Bottom;

                // Get access to the underlying HDC
                IntPtr hDC = g.GetHdc();

                // Perform actual drawing work
                Uxtheme.DrawThemeBackground(_hTheme, hDC, part, state, ref drawWin32, IntPtr.Zero);

                // Must release the resource to prevent leaks!
                g.ReleaseHdc(hDC);
            }
        }
Ejemplo n.º 11
0
        void CopyFrontBufferToBack(/*IntPtr hWnd*/)
        {
            Gl.glDisable(Gl.GL_ALPHA_TEST);
            if (!Types.iBugWhiteout)
            {
                // Found this by accident; Adam likes it.  Freakshow option #1.
                Gl.glDisable(Gl.GL_BLEND);
            }
            Win32.RECT rct = new Win32.RECT();
            Win32.User.GetWindowRect(Video.WindowHandle, ref rct);

            Gl.glReadBuffer(Gl.GL_FRONT);
            Gl.glDrawBuffer(Gl.GL_BACK);
            Gl.glRasterPos2i(0, 0);
            Gl.glCopyPixels(0, 0, rct.Right, rct.Bottom, Gl.GL_COLOR);
            if (!Types.iBugWhiteout)
            {
                Gl.glEnable(Gl.GL_BLEND);
            }
            Gl.glEnable(Gl.GL_ALPHA_TEST);
        }
Ejemplo n.º 12
0
        public static Size GetTextSize(Graphics graphics, string text, Font font)
        {
            IntPtr hdc = IntPtr.Zero;

            if (graphics != null)
            {
                // Get device context from the graphics passed in
                hdc = graphics.GetHdc();
            }
            else
            {
                // Get screen device context
                hdc = WindowsAPI.GetDC(IntPtr.Zero);
            }

            IntPtr fontHandle        = font.ToHfont();
            IntPtr currentFontHandle = WindowsAPI.SelectObject(hdc, fontHandle);

            Win32.RECT rect = new Win32.RECT();
            rect.left   = 0;
            rect.right  = 0;
            rect.top    = 0;
            rect.bottom = 0;

            WindowsAPI.DrawText(hdc, text, text.Length, ref rect,
                                (int)(DrawTextFormatFlags.DT_SINGLELINE | DrawTextFormatFlags.DT_LEFT | DrawTextFormatFlags.DT_CALCRECT));
            WindowsAPI.SelectObject(hdc, currentFontHandle);
            WindowsAPI.DeleteObject(fontHandle);

            if (graphics != null)
            {
                graphics.ReleaseHdc(hdc);
            }
            else
            {
                WindowsAPI.ReleaseDC(IntPtr.Zero, hdc);
            }

            return(new Size(rect.right - rect.left, rect.bottom - rect.top));
        }
        /// <summary>
        /// 子ウィンドウを親ウィンドウの中央に移動する
        /// </summary>
        /// <param name="hChildWnd"></param>
        private static void MoveToCenterOnParent(IntPtr hChildWnd)
        {
            // 子ウィンドウの領域取得
            var childRect = new Win32.RECT();

            Win32.GetWindowRect(hChildWnd, ref childRect);
            int cxChild = childRect.Right - childRect.Left;
            int cyChild = childRect.Bottom - childRect.Top;

            // 親ウィンドウの領域取得
            var parentRect = new Win32.RECT();

            Win32.GetWindowRect(Win32.GetParent(hChildWnd), ref parentRect);
            int cxParent = parentRect.Right - parentRect.Left;
            int cyParent = parentRect.Bottom - parentRect.Top;

            // 子ウィンドウを親ウィンドウの中央に移動
            int x = parentRect.Left + (cxParent - cxChild) / 2;
            int y = parentRect.Top + (cyParent - cyChild) / 2;

            Win32.SetWindowPos(hChildWnd, IntPtr.Zero, x, y, 0, 0, 0x15);   // 0x15 = SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE
        }
Ejemplo n.º 14
0
        protected override void OnPaint(PaintEventArgs e)
        {
            IntPtr data = Win32.OpenThemeData2(this.Handle, "Scrollbar");

            if (data != IntPtr.Zero)             //mit xp themes
            {
                IntPtr     hdc = e.Graphics.GetHdc();
                Win32.RECT rct = new Win32.RECT(0, 0, this.Width, this.Height);
                Win32.DrawThemeBackground2(data, hdc, 6, 2, ref rct);
                rct = base._elems[0].Bounds;
                rct.Left--;
                Win32.DrawThemeBackground2(data, hdc, 1, (int)base._elems[0].State, ref rct);
                rct = base._elems[1].Bounds;
                rct.Left--;
                Win32.DrawThemeBackground2(data, hdc, 1, (int)base._elems[1].State + 4, ref rct);
                rct = base._elems[2].Bounds;
                rct.Left--;
                Win32.DrawThemeBackground2(data, hdc, 3, (int)base._elems[2].State, ref rct);
                e.Graphics.ReleaseHdc(hdc);
                Win32.CloseThemeData2(data);
            }
            else             //ohne xpthemes, einfache rechtecke
            {
                e.Graphics.FillRectangle(SystemBrushes.ControlLightLight, this.ClientRectangle);
                ControlPaint.DrawScrollButton(e.Graphics, base._elems[0].Bounds, ScrollButton.Up, base._elems[0].ToButtonState());
                ControlPaint.DrawScrollButton(e.Graphics, base._elems[1].Bounds, ScrollButton.Down, base._elems[1].ToButtonState());
                ControlPaint.DrawButton(e.Graphics, base._elems[2].Bounds, ButtonState.Normal);
            }
            base._elems[2].Bounds.X -= 3;
            using (StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap |
                                                       StringFormatFlags.DirectionVertical)) {
                fmt.LineAlignment = fmt.Alignment = StringAlignment.Center;

                e.Graphics.DrawString(base.Value.ToString(), base.Font,
                                      this.Enabled ? Brushes.Black : Brushes.Gray, base._elems[2].Bounds, fmt);
            }
            base._elems[2].Bounds.X += 3;
        }
Ejemplo n.º 15
0
        // Boilerplate window-centering code.
        // Split out of HookCallback() for clarity.
        private static void CenterWindowOnParent(IntPtr hChildWnd)
        {
            // Get child (MessageBox) size
            Win32.RECT rcChild = new Win32.RECT();
            Win32.GetWindowRect(hChildWnd, ref rcChild);
            int cxChild = rcChild.right - rcChild.left;
            int cyChild = rcChild.bottom - rcChild.top;

            // Get parent (Form) size & location
            IntPtr hParent = Win32.GetParent(hChildWnd);
            Win32.RECT rcParent = new Win32.RECT();
            Win32.GetWindowRect(hParent, ref rcParent);
            int cxParent = rcParent.right - rcParent.left;
            int cyParent = rcParent.bottom - rcParent.top;

            // Center the MessageBox on the Form
            int x = rcParent.left + (cxParent - cxChild)/2;
            int y = rcParent.top + (cyParent - cyChild)/2;
            const uint uFlags = 0x15; // SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE;
            x = x < 0 ? 100 : x;
            y = y < 0 ? 100 : y;
            Win32.SetWindowPos(hChildWnd, IntPtr.Zero, x, y, 0, 0, uFlags);
        }
Ejemplo n.º 16
0
            private Rectangle CalculateToolTipLocation(string contentSpacing, IWin32Window window, int x, int y, StemPosition stemPosition)
            {
                Rectangle toolTipBounds = new Rectangle();
                Size      toolTipSize   = GetToolTipWindowSize(contentSpacing);

                Win32.RECT windowBounds = new Win32.RECT();

                Win32.GetWindowRect(window.Handle, ref windowBounds);
                x += windowBounds.left;

                if (StemPosition.TopLeft == stemPosition || StemPosition.BottomLeft == stemPosition)
                {
                    toolTipBounds.X = x - StemInset;
                }
                else if (StemPosition.TopCentre == stemPosition || StemPosition.BottomCentre == stemPosition)
                {
                    toolTipBounds.X = x - (toolTipSize.Width / 2);
                }
                else
                {
                    toolTipBounds.X = x - toolTipSize.Width + StemInset;
                }

                if (StemPosition.TopLeft == stemPosition || StemPosition.TopCentre == stemPosition || StemPosition.TopRight == stemPosition)
                {
                    toolTipBounds.Y = windowBounds.bottom - y;
                }
                else
                {
                    toolTipBounds.Y = y + windowBounds.top - toolTipSize.Height;
                }

                toolTipBounds.Width  = toolTipSize.Width;
                toolTipBounds.Height = toolTipSize.Height;

                return(toolTipBounds);
            }
Ejemplo n.º 17
0
        /// <summary>
        /// Brings the visualiser to the front of all windows, and aligns the windows.
        /// </summary>
        public static void BringVisualiserToFrontAndAlignWindows()
        {
            //Look for the visuliser window
            IntPtr visualiserWindowHandle = Win32.FindWindow(null, "StromoLight Visualiser");

            //If visualiser window hasn't opened yet, keep looking until it does
            while (visualiserWindowHandle == new IntPtr(0))
            {
                System.Threading.Thread.Sleep(20);
                visualiserWindowHandle = Win32.FindWindow(null, "StromoLight Visualiser");
            }

            //Get a Win32 RECT containing the visualiser window properties
            Win32.RECT visualiserRect = new Win32.RECT();
            Win32.GetWindowRect(visualiserWindowHandle, out visualiserRect);


            //If the visualiser window hasn't finished initalising, keep getting it's properties until it has initialised
            while (visualiserRect.Left == 0)
            {
                System.Threading.Thread.Sleep(20);
                Win32.GetWindowRect(visualiserWindowHandle, out visualiserRect);
            }


            Win32.SetWindowPos(visualiserWindowHandle,
                               Win32.HWND_TOP,
                               (System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width / 2) + 4,
                               5,
                               (System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width / 2),
                               System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height,
                               Win32.SWP_SHOWWINDOW);


            //Bring the visualiser window to the front
            Win32.SetForegroundWindow(visualiserWindowHandle);
        }
Ejemplo n.º 18
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            IntPtr data = Win32.OpenThemeData2(this.Handle, "Trackbar");
            if (data != IntPtr.Zero) {
                IntPtr hdc = e.Graphics.GetHdc();
                Win32.RECT rct = new Win32.RECT(
                    _tracker.Bounds.Width/2, this.Height/2 - 2,
                    this.Width - _tracker.Bounds.Width, 4);
                Win32.DrawThemeBackground2(data, hdc, 1, 1, ref rct);
                rct = _tracker.Bounds;
                Win32.DrawThemeBackground2(data, hdc, 4, 1 + (int) _tracker.State, ref rct);
                Win32.CloseThemeData2(hdc);
                e.Graphics.ReleaseHdc(hdc);
            }
            else {
                ControlPaint.DrawBorder3D(e.Graphics,
                                          _tracker.Bounds.Width/2, this.Height/2 - 2,
                                          this.Width - _tracker.Bounds.Width, 4,
                                          Border3DStyle.SunkenOuter, Border3DSide.All);
                ControlPaint.DrawButton(e.Graphics, _tracker.Bounds, ButtonState.Normal);
            }
        }
Ejemplo n.º 19
0
 private IntPtr ReplacementWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
 {
     if (msg == Win32.WM_LBUTTONDOWN || msg == Win32.WM_LBUTTONDBLCLK)
     {
         Win32.POINT loc = new Win32.POINT();
         loc.X = MousePosition.X;
         loc.Y = MousePosition.Y;
         Win32.ScreenToClient(DropDownHandle, ref loc);
         Win32.RECT dropdown_rect = new Win32.RECT();
         Win32.GetClientRect(DropDownHandle, out dropdown_rect);
         if (dropdown_rect.Left <= loc.X && loc.X < dropdown_rect.Right && dropdown_rect.Top <= loc.Y && loc.Y < dropdown_rect.Bottom)
         {
             int index = (int)Win32.SendMessage(DropDownHandle, Win32.LB_ITEMFROMPOINT, IntPtr.Zero, (IntPtr)(loc.X + (loc.Y << 16)));
             if (index >> 16 == 0)
             {
                 if (IsItemNonSelectable(Items[index]))
                 {
                     return(IntPtr.Zero);
                 }
             }
         }
     }
     return(Win32.CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam));
 }
Ejemplo n.º 20
0
            private Size GetToolTipWindowSize(string contentSpacing)
            {
                Win32.TOOLINFO ti = new Win32.TOOLINFO();
                ti.cbSize   = Marshal.SizeOf(ti);
                ti.uFlags   = Win32.TTF_TRACK;
                ti.lpszText = contentSpacing;

                if (0 == Win32.SendMessage(Handle, Win32.TTM_ADDTOOL, 0, ref ti))
                {
                    throw new Exception();
                }

                // enable multi-line text-layout
                Win32.SendMessage(Handle, Win32.TTM_SETMAXTIPWIDTH, 0, SystemInformation.MaxWindowTrackSize.Width);
                Win32.SendMessage(Handle, Win32.TTM_TRACKACTIVATE, 1, ref ti);

                Win32.RECT rect = new Win32.RECT();
                Win32.GetWindowRect(Handle, ref rect);

                Win32.SendMessage(Handle, Win32.TTM_TRACKACTIVATE, 0, ref ti);
                Win32.SendMessage(Handle, Win32.TTM_DELTOOL, 0, ref ti);

                return(new Size(rect.right - rect.left, rect.bottom - rect.top));
            }
Ejemplo n.º 21
0
        void adjust_maximized_client_rect(IntPtr window, Win32.RECT rect)
        {
            if (!maximized(window))
            {
                return;
            }

            IntPtr monitor = Win32.MonitorFromWindow(window, Win32.MONITOR_DEFAULTTONULL);

            if (monitor == IntPtr.Zero)
            {
                return;
            }

            Win32.MONITORINFOEX monitor_info = new Win32.MONITORINFOEX();
            if (!Win32.GetMonitorInfo(monitor, ref monitor_info))
            {
                return;
            }

            // when maximized, make the client area fill just the monitor (without task bar) rect,
            // not the whole window rect which extends beyond the monitor.
            rect = monitor_info.WorkArea;
        }
Ejemplo n.º 22
0
 public static extern IntPtr CreateRectRgnIndirect(ref Win32.RECT rect);
Ejemplo n.º 23
0
        // draws all elements
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.Clear(SystemColors.Control);
            if (this.Height < 24 || this.Width < 24)
            {
                return;
            }
            IntPtr data = Win32.OpenThemeData2(this.Handle, "Combobox");

            if (data != IntPtr.Zero)             //draw with winxp themes
            {
                IntPtr hdc = e.Graphics.GetHdc();

                #region background, dropdown button

                Win32.RECT rct = new Win32.RECT(0, 0, this.Width, 22);
                Win32.DrawThemeBackground2(data, hdc, 0, _mouseentered ? 2 : 1, ref rct);
                rct.Left    = rct.Right - 15;
                rct.Top    += 2;
                rct.Bottom -= 2;
                rct.Right  -= 2;
                Win32.DrawThemeBackground2(data, hdc, 1, (int)_elements[0].State, ref rct);
                Win32.CloseThemeData2(data);

                #endregion

                #region spin buttons

                data = Win32.OpenThemeData2(this.Handle, "Spin");
                if (data == IntPtr.Zero)
                {
                    goto final;
                }
                rct.Left -= 13;
                rct.Width = 13;
                rct.Top--;
                rct.Height = 10;
                Win32.DrawThemeBackground2(data, hdc, 1, (int)_elements[1].State, ref rct);
                rct.Top    += 10;
                rct.Bottom += 10;
                Win32.DrawThemeBackground2(data, hdc, 2, (int)_elements[2].State, ref rct);
                Win32.CloseThemeData2(data);

                #endregion

                #region progress bar

                data = Win32.OpenThemeData2(this.Handle, "Progress");
                if (data == IntPtr.Zero)
                {
                    goto final;
                }
                rct.Bottom = this.Height;
                rct.Top    = rct.Bottom - 3;
                rct.Left   = 0;
                rct.Right  = GetPercentage(this.Width);
                Win32.DrawThemeBackground2(data, hdc, 3, 1, ref rct);
                Win32.CloseThemeData2(data);

                #endregion

final:
                e.Graphics.ReleaseHdc(hdc);
            }
            else             //draw without winxp themes
            {
                #region background, dropdown button

                Rectangle rct = new Rectangle(0, 0, this.Width, 22);
                e.Graphics.FillRectangle(Brushes.White, rct);
                e.Graphics.DrawRectangle(_mouseentered ? SystemPens.Highlight : SystemPens.ControlDark,
                                         rct.X, rct.Y, rct.Width - 1, rct.Height - 1);
                rct.X       = this.Width - 15;
                rct.Y       = 1;
                rct.Height -= 2;
                rct.Width   = 15;
                ControlPaint.DrawComboButton(e.Graphics, rct, _elements[0].ToButtonState());

                #endregion

                #region spin button

                rct.X     -= 13;
                rct.Width  = 13;
                rct.Height = 10;
                ControlPaint.DrawScrollButton(e.Graphics, rct, ScrollButton.Up, _elements[1].ToButtonState());
                rct.Y += 10;
                ControlPaint.DrawScrollButton(e.Graphics, rct, ScrollButton.Down, _elements[2].ToButtonState());

                #endregion

                #region progress bar

                rct.Y      = this.Height - 3;
                rct.Height = 3;
                rct.X      = 0;
                rct.Width  = GetPercentage(this.Width);
                e.Graphics.FillRectangle(SystemBrushes.Highlight, rct);

                #endregion
            }
        }
Ejemplo n.º 24
0
 void SetParent(IntPtr hWnd)
 {
     Win32.RECT rc = new Win32.RECT();
     Win32.User.GetWindowRect(hWnd, ref rc);
     this.Width = rc.Right-rc.Left;
     this.Height = rc.Bottom-rc.Top;
     //int style=Win32.User.GetWindowLong(this.Handle, Win32.User.GWL_STYLE);
     Win32.User.SetParent(this.Handle, hWnd);
     Win32.User.SetWindowLong(this.Handle, Win32.User.GWL_STYLE, Win32.User.WS_VISIBLE | Win32.User.WS_CHILDWINDOW);
     Win32.User.SetWindowPos(this.Handle, IntPtr.Zero, 0, 0, this.Width, this.Height, 0/*Win32.User.SWP_NOMOVE | Win32.User.SWP_NOSIZE*/);
 }
Ejemplo n.º 25
0
        protected static IntPtr CreateRectangleRegion(Rectangle rect, int indent)
        {
            Win32.RECT newWinRect = new Win32.RECT();
            newWinRect.left = rect.Left;
            newWinRect.top = rect.Top;
            newWinRect.right = rect.Right;
            newWinRect.bottom = rect.Bottom;

            // Create region for whole of the new rectangle
            IntPtr newOuter = Gdi32.CreateRectRgnIndirect(ref newWinRect);

            // If the rectangle is to small to make an inner object from, then just use the outer
            if ((indent <= 0) || (rect.Width <= indent) || (rect.Height <= indent))
                return newOuter;

            newWinRect.left += indent;
            newWinRect.top += indent;
            newWinRect.right -= indent;
            newWinRect.bottom -= indent;

            // Create region for the unwanted inside of the new rectangle
            IntPtr newInner = Gdi32.CreateRectRgnIndirect(ref newWinRect);

            Win32.RECT emptyWinRect = new Win32.RECT();
            emptyWinRect.left = 0;
            emptyWinRect.top = 0;
            emptyWinRect.right = 0;
            emptyWinRect.bottom = 0;

            // Create a destination region
            IntPtr newRegion = Gdi32.CreateRectRgnIndirect(ref emptyWinRect);

            // Remove the intersection of the outer and inner
            Gdi32.CombineRgn(newRegion, newOuter, newInner, (int)Win32.CombineFlags.RGN_XOR);

            // Remove unwanted intermediate objects
            Gdi32.DeleteObject(newOuter);
            Gdi32.DeleteObject(newInner);

            // Return the resultant region object
            return newRegion;
        }
Ejemplo n.º 26
0
 /// <summary>
 /// invalidates the titlebar
 /// </summary>
 public void InvalidateTitleBar()
 {
     Win32.RECT rct = new Win32.RECT(0, -HeaderHeight, this.Width, HeaderHeight);
     Win32.RedrawWindow(this.Handle, ref rct, IntPtr.Zero, Win32.RDW_FRAME | 0x85);
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Highlights the designated window by drawing a rectangle around
        /// it, just like Microsoft Spy++.
        /// </summary>
        ///
        /// <param name="hWnd">
        /// Handle to the object to be highlighted.
        /// </param>
        ///
        /// <param name="useNativeHighlighter">
        /// If true, the rectangle will be drawn using the native PatBlt
        /// function.
        /// </param>
        public static void Highlight(IntPtr hWnd, bool useNativeHighlighter)
        {
            var rect = new Win32.RECT();
            var hDC  = Win32.GetWindowDC(hWnd);

            if (hWnd == IntPtr.Zero || !Win32.IsWindow(hWnd))
            {
                return;
            }

            Win32.GetWindowRect(hWnd, out rect);
            Win32.OffsetRect(ref rect, -rect.left, -rect.top);

            // The thickness of the frame
            const int width = 3;

            if (hDC == IntPtr.Zero)
            {
                return;
            }

            if (!Win32.IsRectEmpty(ref rect))
            {
                if (useNativeHighlighter)
                {
                    // Top side
                    Win32.PatBlt(hDC,
                                 rect.left,
                                 rect.top,
                                 rect.right - rect.left,
                                 width,
                                 Win32.RasterOperations.PATINVERT);

                    // Left side
                    Win32.PatBlt(hDC,
                                 rect.left,
                                 rect.bottom - width,
                                 width,
                                 -(rect.bottom - rect.top - 2 * width),
                                 Win32.RasterOperations.PATINVERT);

                    // Right side
                    Win32.PatBlt(hDC,
                                 rect.right - width,
                                 rect.top + width,
                                 width,
                                 rect.bottom - rect.top - 2 * width,
                                 Win32.RasterOperations.PATINVERT);

                    // Bottom side
                    Win32.PatBlt(hDC,
                                 rect.right,
                                 rect.bottom - width,
                                 -(rect.right - rect.left),
                                 width,
                                 Win32.RasterOperations.PATINVERT);
                }
                else
                {
                    // Simple GDI+ rectangle drawing
                    using (var pen = new Pen(ColorTranslator.FromHtml("#FF0000"), 4F))
                    {
                        using (var g = Graphics.FromHdc(hDC))
                            g.DrawRectangle(pen, 0, 0, rect.right - rect.left,
                                            rect.bottom - rect.top);
                    }
                }
            }

            Win32.ReleaseDC(hWnd, hDC);
        }
Ejemplo n.º 28
0
        // draws all elements
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.Clear(SystemColors.Control);
            if (this.Height < 24 || this.Width < 24) return;
            IntPtr data = Win32.OpenThemeData2(this.Handle, "Combobox");
            if (data != IntPtr.Zero) //draw with winxp themes
            {
                IntPtr hdc = e.Graphics.GetHdc();

                #region background, dropdown button

                Win32.RECT rct = new Win32.RECT(0, 0, this.Width, 22);
                Win32.DrawThemeBackground2(data, hdc, 0, _mouseentered ? 2 : 1, ref rct);
                rct.Left = rct.Right - 15;
                rct.Top += 2;
                rct.Bottom -= 2;
                rct.Right -= 2;
                Win32.DrawThemeBackground2(data, hdc, 1, (int) _elements[0].State, ref rct);
                Win32.CloseThemeData2(data);

                #endregion

                #region spin buttons

                data = Win32.OpenThemeData2(this.Handle, "Spin");
                if (data == IntPtr.Zero)
                    goto final;
                rct.Left -= 13;
                rct.Width = 13;
                rct.Top--;
                rct.Height = 10;
                Win32.DrawThemeBackground2(data, hdc, 1, (int) _elements[1].State, ref rct);
                rct.Top += 10;
                rct.Bottom += 10;
                Win32.DrawThemeBackground2(data, hdc, 2, (int) _elements[2].State, ref rct);
                Win32.CloseThemeData2(data);

                #endregion

                #region progress bar

                data = Win32.OpenThemeData2(this.Handle, "Progress");
                if (data == IntPtr.Zero)
                    goto final;
                rct.Bottom = this.Height;
                rct.Top = rct.Bottom - 3;
                rct.Left = 0;
                rct.Right = GetPercentage(this.Width);
                Win32.DrawThemeBackground2(data, hdc, 3, 1, ref rct);
                Win32.CloseThemeData2(data);

                #endregion

                final:
                e.Graphics.ReleaseHdc(hdc);
            }
            else //draw without winxp themes
            {
                #region background, dropdown button

                Rectangle rct = new Rectangle(0, 0, this.Width, 22);
                e.Graphics.FillRectangle(Brushes.White, rct);
                e.Graphics.DrawRectangle(_mouseentered ? SystemPens.Highlight : SystemPens.ControlDark,
                                         rct.X, rct.Y, rct.Width - 1, rct.Height - 1);
                rct.X = this.Width - 15;
                rct.Y = 1;
                rct.Height -= 2;
                rct.Width = 15;
                ControlPaint.DrawComboButton(e.Graphics, rct, _elements[0].ToButtonState());

                #endregion

                #region spin button

                rct.X -= 13;
                rct.Width = 13;
                rct.Height = 10;
                ControlPaint.DrawScrollButton(e.Graphics, rct, ScrollButton.Up, _elements[1].ToButtonState());
                rct.Y += 10;
                ControlPaint.DrawScrollButton(e.Graphics, rct, ScrollButton.Down, _elements[2].ToButtonState());

                #endregion

                #region progress bar

                rct.Y = this.Height - 3;
                rct.Height = 3;
                rct.X = 0;
                rct.Width = GetPercentage(this.Width);
                e.Graphics.FillRectangle(SystemBrushes.Highlight, rct);

                #endregion
            }
        }
Ejemplo n.º 29
0
        protected void RegenerateExpansion()
        {
            // Remove all existing draw commands
            _drawCommands.Clear();

            // Move into the expanded mode
            _showInfrequent = true;

            // Show we remember the expansion to the collection?
            if (_rememberExpansion)
                _menuCommands.ShowInfrequent = true;

            // Generate new ones
            Size newSize = GenerateDrawPositions();

            // Find the new screen location for the window
            Point newPos = CorrectPositionForScreen(newSize);

            // Remember the correct screen drawing details
            _currentPoint = newPos;
            _currentSize = newSize;

            // Update the window clipping region
            if (!_layered)
            {
                SetWindowRegion(newSize);

                // Alter size and location of window
                User32.MoveWindow(this.Handle, newPos.X, newPos.Y, newSize.Width, newSize.Height, true);

                Win32.RECT clientRect = new Win32.RECT();

                clientRect.left = 0;
                clientRect.top = 0;
                clientRect.right = newSize.Width;
                clientRect.bottom = newSize.Height;

                // Get the client area redrawn after MoveWindow has been processed
                User32.InvalidateRect(this.Handle, ref clientRect, true);
            }
            else
            {
                // Update the image for display
                UpdateLayeredWindow();

                // Lets repaint everything
                RefreshAllCommands();
            }
        }
Ejemplo n.º 30
0
 public static extern int ScrollWindowEx(IntPtr hWnd, int dx, int dy, ref Win32.RECT prcScroll, ref Win32.RECT prcClip, IntPtr hrgnUpdate, ref Win32.RECT prcUpdate, uint flags);
Ejemplo n.º 31
0
 public static extern bool ValidateRect(IntPtr hWnd, ref Win32.RECT lpRect);
Ejemplo n.º 32
0
 /// <summary>
 /// invalidates the titlebar
 /// </summary>
 public void InvalidateTitleBar()
 {
     Win32.RECT rct = new Win32.RECT(0, -HeaderHeight, this.Width, HeaderHeight);
     Win32.RedrawWindow(this.Handle,ref rct,IntPtr.Zero,Win32.RDW_FRAME|0x85);
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Erase the trail of the gesture and stop drawing
        /// </summary>
        public void RefreshAndStopDrawing()
        {

            // the drawing of gestures was finished
            m_gestureDrawing = false;
            // drawing in thread timer tick should not continue
            m_drawingEnded = true;
            // stop the thread timer
            m_threadTimerDraw.Change(-1, -1);

            if (!m_threadDrawing)
            {
                int lastIndex = m_curvePoints.Count;
                PointF[] points = m_curvePoints.GetRange(m_lastIndex, lastIndex - m_lastIndex).ToArray();
                m_lastIndex = lastIndex - 1;
                if (points.Length > 1)
                    m_gp.DrawLines(m_pen, points);
            }

            List<PointF> allPoints = new List<PointF>(m_curvePoints.ToArray());
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddLines(allPoints.ToArray());
            RectangleF rect = path.GetBounds();
            int rectShift = m_penWidth * 6;
            rect.X -= rectShift;
            rect.Y -= rectShift;
            rect.Width += rectShift * 2;
            rect.Height += rectShift * 2;
            //Win32.RECT r = new Win32.RECT(rect);
            m_drawnRegion = new Win32.RECT(rect);
            //Rectangle r = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);
            if (!m_threadDrawing)
            {
                Debug.WriteLine(String.Format("##### InvalidateRect in MOUSE UP left: {0}, top: {1}, right: {2}, bottom: {3} ######",
                    m_drawnRegion.left, m_drawnRegion.top, m_drawnRegion.right, m_drawnRegion.bottom));
                //Win32.InvalidateRect(m_hwndForm, ref m_drawnRegion, true);
                Win32.RedrawWindow(m_hwndForm, ref m_drawnRegion, IntPtr.Zero, Win32.RDW_ERASE | Win32.RDW_INVALIDATE | Win32.RDW_UPDATENOW);                
                MakeNonTopMost();
            }
            else
                m_redrawInTick = true;
            //this.Invalidate(r);
            //Win32.RedrawWindow(m_hwndForm, ref r, IntPtr.Zero, 0x2);
        }
Ejemplo n.º 34
0
        protected PopupMenu WantMouseMessage(Win32.POINT screenPos)
        {
            Win32.RECT rectRaw = new Win32.RECT();

            // Grab the screen rectangle of the window
            User32.GetWindowRect(this.Handle, ref rectRaw);

            if ((screenPos.x >= rectRaw.left) && (screenPos.x <= rectRaw.right) &&
                (screenPos.y >= rectRaw.top) && (screenPos.y <= rectRaw.bottom))
                return this;

            if (_parentMenu != null)
                return _parentMenu.WantMouseMessage(screenPos);

            return null;
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Get state according to fullscreen option
        /// </summary>
        /// <param name="wndHandle"></param>
        /// <returns></returns>
        public bool GetFullScreenState(bool currentState, IntPtr wndHandle)
        {
            bool enabled = currentState;

            System.Drawing.Rectangle screen = System.Windows.Forms.Screen.FromHandle(wndHandle).Bounds;
            Win32.RECT screenSize = new Win32.RECT(screen);

            Win32.WINDOWINFO info = new Win32.WINDOWINFO();
            Win32.GetWindowInfo(wndHandle, ref info);
            //Debug.WriteLine(string.Format("Wnd left: {0}, top: {1}, right: {2}, bottom: {3}",
            //    info.rcWindow.left, info.rcWindow.top, info.rcWindow.right, info.rcWindow.bottom));
            if (info.rcWindow.Equals(screenSize))
            {
                switch (Config.User.StateFullScreen)
                {
                    case 1: enabled = true; break;
                    case 2: enabled = false; break;
                }
            }
            else
            {
                switch (Config.User.StateFullScreen)
                {
                    case 1: enabled = false; break;
                    case 2: enabled = true; break;
                }
            }
            return enabled;
        }
Ejemplo n.º 36
0
 public static bool GetRect(this IntPtr window, out Win32.RECT rect) => Win32.GetWindowRect(window, out rect);
Ejemplo n.º 37
0
        internal void Render(IntPtr hdc, RenderProfile prof, Color baseBackColor, int x, int y) {
            if (_text.Length == 0 || _text[0] == '\0')
                return; //何も描かなくてよい。これはよくあるケース

            float fx0 = (float)x;
            float fx1 = fx0;
            int y1 = y;
            int y2 = y1 + (int)prof.Pitch.Height;

            float pitch = prof.Pitch.Width;
            int defaultBackColorArgb = baseBackColor.ToArgb();

            Win32.SetBkMode(hdc, Win32.TRANSPARENT);

            GWord word = _firstWord;
            while (word != null) {
                TextDecoration dec = word.Decoration;

                IntPtr hFont = prof.CalcHFONT_NoUnderline(dec, word.CharGroup);
                Win32.SelectObject(hdc, hFont);

                uint foreColorRef = DrawUtil.ToCOLORREF(prof.CalcTextColor(dec));
                Win32.SetTextColor(hdc, foreColorRef);

                Color bkColor = prof.CalcBackColor(dec);
                bool isOpaque = (bkColor.ToArgb() != defaultBackColorArgb);
                if (isOpaque) {
                    uint bkColorRef = DrawUtil.ToCOLORREF(bkColor);
                    Win32.SetBkColor(hdc, bkColorRef);
                }

                int nextOffset = GetNextOffset(word);

                float fx2 = fx0 + pitch * nextOffset;

                if (prof.CalcBold(dec) || CharGroupUtil.IsCJK(word.CharGroup)) {
                    // It is not always true that width of a character in the CJK font is twice of a character in the ASCII font.
                    // Characters are drawn one by one to adjust pitch.

                    int step = CharGroupUtil.GetColumnsPerCharacter(word.CharGroup);
                    float charPitch = pitch * step;
                    int offset = word.Offset;
                    float fx = fx1;
                    if (isOpaque) {
                        // If background fill is required, we call ExtTextOut() with ETO_OPAQUE to draw the first character.
                        if (offset < nextOffset) {
                            Win32.RECT rect = new Win32.RECT((int)fx1, y1, (int)fx2, y2);
                            char ch = _text[offset];
                            Debug.Assert(ch != GLine.WIDECHAR_PAD);
                            unsafe {
                                Win32.ExtTextOut(hdc, rect.left, rect.top, Win32.ETO_OPAQUE, &rect, &ch, 1, null);
                            }
                        }
                        offset += step;
                        fx += charPitch;
                    }

                    for (; offset < nextOffset; offset += step) {
                        char ch = _text[offset];
                        Debug.Assert(ch != GLine.WIDECHAR_PAD);
                        unsafe {
                            Win32.ExtTextOut(hdc, (int)fx, y1, 0, null, &ch, 1, null);
                        }
                        fx += charPitch;
                    }
                }
                else {
                    int offset = word.Offset;
                    int displayLength = nextOffset - offset;
                    if (isOpaque) {
                        Win32.RECT rect = new Win32.RECT((int)fx1, y1, (int)fx2, y2);
                        unsafe {
                            fixed (char* p = &_text[offset]) {
                                Win32.ExtTextOut(hdc, rect.left, rect.top, Win32.ETO_OPAQUE, &rect, p, displayLength, null);
                            }
                        }
                    }
                    else {
                        unsafe {
                            fixed (char* p = &_text[offset]) {
                                Win32.ExtTextOut(hdc, (int)fx1, y1, 0, null, p, displayLength, null);
                            }
                        }
                    }
                }

                if (dec.Underline)
                    DrawUnderline(hdc, foreColorRef, (int)fx1, y2 - 1, (int)fx2 - (int)fx1);

                fx1 = fx2;
                word = word.Next;
            }

        }
Ejemplo n.º 38
0
        protected bool ParentControlWantsMouseMessage(Win32.POINT screenPos, ref Win32.MSG msg)
        {
            // Special case the MOUSEMOVE so if we are part of a MenuControl
            // then we should let the MenuControl process that message
            if ((msg.message == (int)Win32.Msgs.WM_MOUSEMOVE) && (_parentControl != null))
            {
                Win32.RECT rectRaw = new Win32.RECT();

                // Grab the screen rectangle of the parent control
                User32.GetWindowRect(_parentControl.Handle, ref rectRaw);

                if ((screenPos.x >= rectRaw.left) && (screenPos.x <= rectRaw.right) &&
                    (screenPos.y >= rectRaw.top) && (screenPos.y <= rectRaw.bottom))
                    return true;
            }

            return false;
        }
Ejemplo n.º 39
0
        protected void OnWM_PAINT(ref Message m)
        {
            Win32.PAINTSTRUCT ps = new Win32.PAINTSTRUCT();

            // Have to call BeginPaint whenever processing a WM_PAINT message
            IntPtr hDC = User32.BeginPaint(m.HWnd, ref ps);

            Win32.RECT rectRaw = new Win32.RECT();

            // Grab the screen rectangle of the window
            User32.GetWindowRect(this.Handle, ref rectRaw);

            // Convert to a client size rectangle
            Rectangle rectWin = new Rectangle(0, 0,
                                              rectRaw.right - rectRaw.left,
                                              rectRaw.bottom - rectRaw.top);

            // Create a graphics object for drawing
            using(Graphics g = Graphics.FromHdc(hDC))
            {
                // Create bitmap for drawing onto
                Bitmap memoryBitmap = new Bitmap(rectWin.Width, rectWin.Height);

                using(Graphics h = Graphics.FromImage(memoryBitmap))
                {
                    // Draw the background area
                    DrawBackground(h, rectWin);

                    // Draw the actual menu items
                    DrawAllCommands(h);
                }

                // Blit bitmap onto the screen
                g.DrawImageUnscaled(memoryBitmap, 0, 0);
            }

            // Don't forget to end the paint operation!
            User32.EndPaint(m.HWnd, ref ps);
        }
Ejemplo n.º 40
0
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            if (mapper == null)
            {
                ExceptionHelper.ArgumentNullException("mapper");
            }
            if (annObject == null)
            {
                ExceptionHelper.ArgumentNullException("annObject");
            }

            base.Render(mapper, annObject);
            AnnRichTextObject annRichTextObject = annObject as AnnRichTextObject;

            if (annRichTextObject != null && !String.IsNullOrEmpty(annRichTextObject.Rtf))
            {
                AnnWinFormsRenderingEngine engine = RenderingEngine as AnnWinFormsRenderingEngine;
                if (engine != null && engine.Context != null)
                {
                    AnnRectangleObject tempRect = new AnnRectangleObject();
                    tempRect.Points.Clear();
                    foreach (LeadPointD pt in GetRenderPoints(mapper, annRichTextObject))
                    {
                        tempRect.Points.Add(pt);
                    }

                    double rotation = tempRect.Angle;
                    if (rotation == 180)
                    {
                        rotation = 0;
                    }

                    LeadRectD          boundsPixels   = tempRect.Rect.Clone();
                    AnnContainerMapper identityMapper = mapper.Clone();
                    identityMapper.UpdateTransform(LeadMatrix.Identity);
                    identityMapper.MapResolutions(mapper.SourceDpiX, mapper.SourceDpiY, mapper.SourceDpiX, mapper.SourceDpiY);
                    boundsPixels = identityMapper.RectFromContainerCoordinates(boundsPixels, annRichTextObject.FixedStateOperations);
                    if (tempRect.Stroke != null)
                    {
                        boundsPixels.Inflate(-tempRect.Stroke.StrokeThickness.Value, -tempRect.Stroke.StrokeThickness.Value);
                    }

                    string rtf = annRichTextObject.Rtf;
                    IntPtr hemfDC;
                    if (_richTextBox == null)
                    {
                        _richTextBox = new InternalRichTextEdit();
                    }

                    try
                    {
                        _richTextBox.Rtf = rtf;
                    }
                    catch
                    {
                        using (RichTextBox richTextBox = new RichTextBox())
                        {
                            richTextBox.Text      = rtf;
                            annRichTextObject.Rtf = richTextBox.Rtf;
                            _richTextBox.Rtf      = richTextBox.Rtf;
                        }
                    }

                    Graphics graphics = engine.Context;
                    double   dpiX     = 96;
                    double   dpiY     = 96;

                    _richTextBox.Location = new Point((int)boundsPixels.Location.X, (int)boundsPixels.Location.Y);
                    _richTextBox.Size     = new Size((int)boundsPixels.Size.Width, (int)boundsPixels.Size.Height);
                    IntPtr hdc = graphics.GetHdc();

                    Win32.RECT rc = new Win32.RECT();

                    rc.left   = _richTextBox.ClientRectangle.Left;
                    rc.top    = _richTextBox.ClientRectangle.Top;
                    rc.right  = (int)boundsPixels.Width;
                    rc.bottom = (int)boundsPixels.Height;

                    int iWidthMM    = SafeNativeMethods.GetDeviceCaps(hdc, Win32.HORZSIZE);
                    int iHeightMM   = SafeNativeMethods.GetDeviceCaps(hdc, Win32.VERTSIZE);
                    int iWidthPels  = SafeNativeMethods.GetDeviceCaps(hdc, Win32.HORZRES);
                    int iHeightPels = SafeNativeMethods.GetDeviceCaps(hdc, Win32.VERTRES);

                    rc.left   = (rc.left * iWidthMM * 100) / iWidthPels;
                    rc.top    = (rc.top * iHeightMM * 100) / iHeightPels;
                    rc.right  = (rc.right * iWidthMM * 100) / iWidthPels;
                    rc.bottom = (rc.bottom * iHeightMM * 100) / iHeightPels;

                    hemfDC = SafeNativeMethods.CreateEnhMetaFile(hdc, null, ref rc, null);

                    Win32.RECT emfRect = new Win32.RECT();
                    emfRect.right  = (int)boundsPixels.Width;
                    emfRect.bottom = (int)boundsPixels.Height;

                    IntPtr brush = SafeNativeMethods.GetStockObject(5);
                    SafeNativeMethods.SetBkMode(hemfDC, 1);
                    SafeNativeMethods.FillRect(hemfDC, ref emfRect, brush);
                    SafeNativeMethods.DeleteObject(brush);

                    Print(_richTextBox, _richTextBox.ClientRectangle, hemfDC, (int)dpiX, (int)dpiY, false);
                    IntPtr hemf = SafeNativeMethods.CloseEnhMetaFile(hemfDC);

                    using (Metafile metaFile = new Metafile(hemf, true))
                    {
                        graphics.ReleaseHdc();
                        GraphicsState state = graphics.Save();

                        //the mapper transform dosent contain dpi effect so we will add dpi effect .
                        LeadMatrix matrix = mapper.Transform;
                        //add dpi effect to the transform
                        matrix.Scale((float)(mapper.TargetDpiX / mapper.SourceDpiX), (float)(mapper.TargetDpiY / mapper.SourceDpiY));

                        if ((annRichTextObject.FixedStateOperations & AnnFixedStateOperations.Scrolling) == AnnFixedStateOperations.Scrolling)
                        {
                            matrix.Translate(-matrix.OffsetX, -matrix.OffsetY);
                        }

                        if ((annRichTextObject.FixedStateOperations & AnnFixedStateOperations.Zooming) == AnnFixedStateOperations.Zooming)
                        {
                            double offsetX = matrix.OffsetX;
                            double offsetY = matrix.OffsetY;
                            double scaleX  = 1.0;
                            double scaleY  = 1.0;
                            if (matrix.M11 != 0 && matrix.M22 != 0)
                            {
                                scaleX = 1.0 / Math.Abs(matrix.M11);
                                scaleY = 1.0 / Math.Abs(matrix.M22);
                            }

                            matrix.Scale(scaleX, scaleY);
                        }

                        using (Matrix transform = new Matrix((float)matrix.M11, (float)matrix.M12, (float)matrix.M21, (float)matrix.M22, (float)matrix.OffsetX, (float)matrix.OffsetY))
                        {
                            graphics.MultiplyTransform(transform);
                            graphics.DrawImage(metaFile, new Point((int)boundsPixels.Left, (int)boundsPixels.Top));
                        }
                        graphics.Restore(state);
                    }
                }

                //EndDraw(graphics, gState);
            }
        }
Ejemplo n.º 41
0
 public static int Height(this Win32.RECT rect) => rect.Bottom - rect.Top;
Ejemplo n.º 42
0
        private bool CreateWindowPane(int x, int y, int w, int h, bool fs)
        {
            windowSize = new Vec2d(w, h);
            windowPos  = new Vec2d(x, y);

            mWndProcDelegate = MyWndProc;
            Win32.WNDCLASSEX wcex = new Win32.WNDCLASSEX
            {
                style         = (int)Win32.ClassStyles.CS_DBLCLKS,
                lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(mWndProcDelegate),
                lpszClassName = CLASS_NAME,
                cbSize        = Marshal.SizeOf(typeof(Win32.WNDCLASSEX)),
                cbClsExtra    = 0,
                cbWndExtra    = 0,
                hIcon         = Win32.LoadIcon(IntPtr.Zero, (IntPtr)Win32.SystemIcons.IDI_APPLICATION),
                hCursor       = Win32.LoadCursor(IntPtr.Zero, (int)Win32.IDC_ARROW),
                hIconSm       = IntPtr.Zero,
                hbrBackground = (IntPtr)(Win32.COLOR_WINDOW + 1),
                lpszMenuName  = null
            };

            ushort regReturn = Win32.RegisterClassEx(ref wcex);

            if (regReturn == 0)
            {
                return(false);
            }

            uint dwExStyle = (uint)(Win32.WindowStylesEx.WS_EX_APPWINDOW | Win32.WindowStylesEx.WS_EX_WINDOWEDGE);
            uint dwStyle   = (uint)(Win32.WindowStyles.WS_CAPTION | Win32.WindowStyles.WS_SYSMENU | Win32.WindowStyles.WS_VISIBLE);

            if (fs)
            {
                dwExStyle = 0;
                dwStyle   = (uint)(Win32.WindowStyles.WS_VISIBLE | Win32.WindowStyles.WS_POPUP);
                IntPtr hmon = Win32.MonitorFromWindow(m_hWnd, Win32.MONITOR_DEFAULTTONEAREST);
                Win32.MonitorInfoEx mon_info = new Win32.MonitorInfoEx();
                mon_info.Size = (int)Marshal.SizeOf(mon_info);
                if (!Win32.GetMonitorInfo(hmon, ref mon_info))
                {
                    return(false);
                }
                windowSize  = new Vec2d(mon_info.Monitor.Right, mon_info.Monitor.Bottom);
                windowPos.X = 0;
                windowPos.Y = 0;
            }

            Win32.RECT rWndRect = new Win32.RECT(0, 0, (int)windowSize.X, (int)windowSize.Y);
            Win32.AdjustWindowRectEx(ref rWndRect, dwStyle, false, dwExStyle);
            int width  = rWndRect.Right - rWndRect.Left;
            int height = rWndRect.Bottom - rWndRect.Top;

            m_hWnd = Win32.CreateWindowEx(
                dwExStyle,
                regReturn,
                Title,
                dwStyle,
                (int)windowPos.X,
                (int)windowPos.Y,
                width,
                height,
                IntPtr.Zero,
                IntPtr.Zero,
                wcex.hInstance,
                IntPtr.Zero);

            mapKeys[0x00] = KeyUtil.Key.NONE;
            mapKeys[0x41] = KeyUtil.Key.A; mapKeys[0x42] = KeyUtil.Key.B; mapKeys[0x43] = KeyUtil.Key.C; mapKeys[0x44] = KeyUtil.Key.D; mapKeys[0x45] = KeyUtil.Key.E;
            mapKeys[0x46] = KeyUtil.Key.F; mapKeys[0x47] = KeyUtil.Key.G; mapKeys[0x48] = KeyUtil.Key.H; mapKeys[0x49] = KeyUtil.Key.I; mapKeys[0x4A] = KeyUtil.Key.J;
            mapKeys[0x4B] = KeyUtil.Key.K; mapKeys[0x4C] = KeyUtil.Key.L; mapKeys[0x4D] = KeyUtil.Key.M; mapKeys[0x4E] = KeyUtil.Key.N; mapKeys[0x4F] = KeyUtil.Key.O;
            mapKeys[0x50] = KeyUtil.Key.P; mapKeys[0x51] = KeyUtil.Key.Q; mapKeys[0x52] = KeyUtil.Key.R; mapKeys[0x53] = KeyUtil.Key.S; mapKeys[0x54] = KeyUtil.Key.T;
            mapKeys[0x55] = KeyUtil.Key.U; mapKeys[0x56] = KeyUtil.Key.V; mapKeys[0x57] = KeyUtil.Key.W; mapKeys[0x58] = KeyUtil.Key.X; mapKeys[0x59] = KeyUtil.Key.Y;
            mapKeys[0x5A] = KeyUtil.Key.Z;

            mapKeys[(int)Win32.VK.F1] = KeyUtil.Key.F1; mapKeys[(int)Win32.VK.F2] = KeyUtil.Key.F2; mapKeys[(int)Win32.VK.F3] = KeyUtil.Key.F3; mapKeys[(int)Win32.VK.F4] = KeyUtil.Key.F4;
            mapKeys[(int)Win32.VK.F5] = KeyUtil.Key.F5; mapKeys[(int)Win32.VK.F6] = KeyUtil.Key.F6; mapKeys[(int)Win32.VK.F7] = KeyUtil.Key.F7; mapKeys[(int)Win32.VK.F8] = KeyUtil.Key.F8;
            mapKeys[(int)Win32.VK.F9] = KeyUtil.Key.F9; mapKeys[(int)Win32.VK.F10] = KeyUtil.Key.F10; mapKeys[(int)Win32.VK.F11] = KeyUtil.Key.F11; mapKeys[(int)Win32.VK.F12] = KeyUtil.Key.F12;

            mapKeys[(int)Win32.VK.DOWN]   = KeyUtil.Key.DOWN; mapKeys[(int)Win32.VK.LEFT] = KeyUtil.Key.LEFT; mapKeys[(int)Win32.VK.RIGHT] = KeyUtil.Key.RIGHT; mapKeys[(int)Win32.VK.UP] = KeyUtil.Key.UP;
            mapKeys[(int)Win32.VK.RETURN] = KeyUtil.Key.ENTER;             //mapKeys[VK_RETURN] = KeyUtil.Key.RETURN;

            mapKeys[(int)Win32.VK.BACK]   = KeyUtil.Key.BACK; mapKeys[(int)Win32.VK.ESCAPE] = KeyUtil.Key.ESCAPE; mapKeys[(int)Win32.VK.RETURN] = KeyUtil.Key.ENTER; mapKeys[(int)Win32.VK.PAUSE] = KeyUtil.Key.PAUSE;
            mapKeys[(int)Win32.VK.SCROLL] = KeyUtil.Key.SCROLL; mapKeys[(int)Win32.VK.TAB] = KeyUtil.Key.TAB; mapKeys[(int)Win32.VK.DELETE] = KeyUtil.Key.DEL; mapKeys[(int)Win32.VK.HOME] = KeyUtil.Key.HOME;
            mapKeys[(int)Win32.VK.END]    = KeyUtil.Key.END; mapKeys[(int)Win32.VK.PRIOR] = KeyUtil.Key.PGUP; mapKeys[(int)Win32.VK.NEXT] = KeyUtil.Key.PGDN; mapKeys[(int)Win32.VK.INSERT] = KeyUtil.Key.INS;
            mapKeys[(int)Win32.VK.SHIFT]  = KeyUtil.Key.SHIFT; mapKeys[(int)Win32.VK.CONTROL] = KeyUtil.Key.CTRL;
            mapKeys[(int)Win32.VK.SPACE]  = KeyUtil.Key.SPACE;

            mapKeys[0x30] = KeyUtil.Key.K0; mapKeys[0x31] = KeyUtil.Key.K1; mapKeys[0x32] = KeyUtil.Key.K2; mapKeys[0x33] = KeyUtil.Key.K3; mapKeys[0x34] = KeyUtil.Key.K4;
            mapKeys[0x35] = KeyUtil.Key.K5; mapKeys[0x36] = KeyUtil.Key.K6; mapKeys[0x37] = KeyUtil.Key.K7; mapKeys[0x38] = KeyUtil.Key.K8; mapKeys[0x39] = KeyUtil.Key.K9;

            mapKeys[(int)Win32.VK.NUMPAD0]  = KeyUtil.Key.NP0; mapKeys[(int)Win32.VK.NUMPAD1] = KeyUtil.Key.NP1; mapKeys[(int)Win32.VK.NUMPAD2] = KeyUtil.Key.NP2; mapKeys[(int)Win32.VK.NUMPAD3] = KeyUtil.Key.NP3; mapKeys[(int)Win32.VK.NUMPAD4] = KeyUtil.Key.NP4;
            mapKeys[(int)Win32.VK.NUMPAD5]  = KeyUtil.Key.NP5; mapKeys[(int)Win32.VK.NUMPAD6] = KeyUtil.Key.NP6; mapKeys[(int)Win32.VK.NUMPAD7] = KeyUtil.Key.NP7; mapKeys[(int)Win32.VK.NUMPAD8] = KeyUtil.Key.NP8; mapKeys[(int)Win32.VK.NUMPAD9] = KeyUtil.Key.NP9;
            mapKeys[(int)Win32.VK.MULTIPLY] = KeyUtil.Key.NP_MUL; mapKeys[(int)Win32.VK.ADD] = KeyUtil.Key.NP_ADD; mapKeys[(int)Win32.VK.DIVIDE] = KeyUtil.Key.NP_DIV; mapKeys[(int)Win32.VK.SUBTRACT] = KeyUtil.Key.NP_SUB; mapKeys[(int)Win32.VK.DECIMAL] = KeyUtil.Key.NP_DECIMAL;

            return(true);
        }
Ejemplo n.º 43
0
 /// <summary>
 /// calculates the new clientsize
 /// </summary>
 protected virtual void OnCalcSize(ref Win32.RECT clientbounds)
 {
     clientbounds.Inflate(-1, -1);
     clientbounds.Top += HeaderHeight - 1;
 }
Ejemplo n.º 44
0
        public void WndActivate(object sender, CbtEventArgs e)
        {
            IntPtr hMsgBox = e.wParam;

            // try to find a howner for this message box
            if (hOwner == IntPtr.Zero)
            {
                hOwner = Win32.Function.GetActiveWindow();
            }

            // get the MessageBox window rect
            Win32.RECT rectDlg = new Win32.RECT();
            Win32.Function.GetWindowRect(hMsgBox, ref rectDlg);

            // get the owner window rect
            Win32.RECT rectForm = new Win32.RECT();
            Win32.Function.GetWindowRect(hOwner, ref rectForm);

            // get the biggest screen area
            Rectangle rectScreen = TrueScreenRect;

            // if no parent window, center on the primary screen
            if (rectForm.right == rectForm.left)
            {
                rectForm.right = rectForm.left = Screen.PrimaryScreen.WorkingArea.Width / 2;
            }
            if (rectForm.bottom == rectForm.top)
            {
                rectForm.bottom = rectForm.top = Screen.PrimaryScreen.WorkingArea.Height / 2;
            }

            // center on parent
            int dx = ((rectDlg.left + rectDlg.right) - (rectForm.left + rectForm.right)) / 2;
            int dy = ((rectDlg.top + rectDlg.bottom) - (rectForm.top + rectForm.bottom)) / 2;

            rect = new Rectangle(
                rectDlg.left - dx,
                rectDlg.top - dy,
                rectDlg.right - rectDlg.left,
                rectDlg.bottom - rectDlg.top);

            // place in the screen
            if (rect.Right > rectScreen.Right)
            {
                rect.Offset(rectScreen.Right - rect.Right, 0);
            }
            if (rect.Bottom > rectScreen.Bottom)
            {
                rect.Offset(0, rectScreen.Bottom - rect.Bottom);
            }
            if (rect.Left < rectScreen.Left)
            {
                rect.Offset(rectScreen.Left - rect.Left, 0);
            }
            if (rect.Top < rectScreen.Top)
            {
                rect.Offset(0, rectScreen.Top - rect.Top);
            }

            if (e.IsDialog)
            {
                // do the job when the WM_INITDIALOG message returns
                wndProcRetHook             = new WndProcRetHook(hMsgBox);
                wndProcRetHook.WndProcRet += new WndProcRetHook.WndProcEventHandler(WndProcRet);
                wndProcRetHook.Install();
            }
            else
            {
                Win32.Function.MoveWindow(hMsgBox, rect.Left, rect.Top, rect.Width, rect.Height, 1);
            }

            // uninstall this hook
            WindowsHook wndHook = (WindowsHook)sender;

            Debug.Assert(cbtHook == wndHook);
            cbtHook.Uninstall();
            cbtHook = null;
        }
Ejemplo n.º 45
0
        internal void Render(IntPtr hdc, RenderProfile prof, Color baseBackColor, int x, int y)
        {
            if (_text.Length == 0 || _text[0] == '\0')
            {
                return; //何も描かなくてよい。これはよくあるケース
            }
            float fx0 = (float)x;
            float fx1 = fx0;
            int   y1  = y;
            int   y2  = y1 + (int)prof.Pitch.Height;

            float pitch = prof.Pitch.Width;
            int   defaultBackColorArgb = baseBackColor.ToArgb();

            Win32.SetBkMode(hdc, Win32.TRANSPARENT);

            GWord word = _firstWord;

            while (word != null)
            {
                TextDecoration dec = word.Decoration;

                IntPtr hFont = prof.CalcHFONT_NoUnderline(dec, word.CharGroup);
                Win32.SelectObject(hdc, hFont);

                uint foreColorRef = DrawUtil.ToCOLORREF(prof.CalcTextColor(dec));
                Win32.SetTextColor(hdc, foreColorRef);

                Color bkColor  = prof.CalcBackColor(dec);
                bool  isOpaque = (bkColor.ToArgb() != defaultBackColorArgb);
                if (isOpaque)
                {
                    uint bkColorRef = DrawUtil.ToCOLORREF(bkColor);
                    Win32.SetBkColor(hdc, bkColorRef);
                }

                int nextOffset = GetNextOffset(word);

                float fx2 = fx0 + pitch * nextOffset;

                if (prof.CalcBold(dec) || CharGroupUtil.IsCJK(word.CharGroup))
                {
                    // It is not always true that width of a character in the CJK font is twice of a character in the ASCII font.
                    // Characters are drawn one by one to adjust pitch.

                    int   step      = CharGroupUtil.GetColumnsPerCharacter(word.CharGroup);
                    float charPitch = pitch * step;
                    int   offset    = word.Offset;
                    float fx        = fx1;
                    if (isOpaque)
                    {
                        // If background fill is required, we call ExtTextOut() with ETO_OPAQUE to draw the first character.
                        if (offset < nextOffset)
                        {
                            Win32.RECT rect = new Win32.RECT((int)fx1, y1, (int)fx2, y2);
                            char       ch   = _text[offset];
                            Debug.Assert(ch != GLine.WIDECHAR_PAD);
                            unsafe {
                                Win32.ExtTextOut(hdc, rect.left, rect.top, Win32.ETO_OPAQUE, &rect, &ch, 1, null);
                            }
                        }
                        offset += step;
                        fx     += charPitch;
                    }

                    for (; offset < nextOffset; offset += step)
                    {
                        char ch = _text[offset];
                        Debug.Assert(ch != GLine.WIDECHAR_PAD);
                        unsafe {
                            Win32.ExtTextOut(hdc, (int)fx, y1, 0, null, &ch, 1, null);
                        }
                        fx += charPitch;
                    }
                }
                else
                {
                    int offset        = word.Offset;
                    int displayLength = nextOffset - offset;
                    if (isOpaque)
                    {
                        Win32.RECT rect = new Win32.RECT((int)fx1, y1, (int)fx2, y2);
                        unsafe
                        {
                            fixed(char *p = &_text[offset])
                            {
                                Win32.ExtTextOut(hdc, rect.left, rect.top, Win32.ETO_OPAQUE, &rect, p, displayLength, null);
                            }
                        }
                    }
                    else
                    {
                        unsafe
                        {
                            fixed(char *p = &_text[offset])
                            {
                                Win32.ExtTextOut(hdc, (int)fx1, y1, 0, null, p, displayLength, null);
                            }
                        }
                    }
                }

                if (dec.Underline)
                {
                    DrawUnderline(hdc, foreColorRef, (int)fx1, y2 - 1, (int)fx2 - (int)fx1);
                }

                fx1  = fx2;
                word = word.Next;
            }
        }
Ejemplo n.º 46
0
 protected override void DoPaint(HCStyle aStyle, Win32.RECT aDrawRect, int aDataDrawTop, int aDataDrawBottom, int aDataScreenTop, int aDataScreenBottom, HCCanvas aCanvas, PaintInfo aPaintInfo)
 {
     base.DoPaint(aStyle, aDrawRect, aDataDrawTop, aDataDrawBottom, aDataScreenTop, aDataScreenBottom, aCanvas, aPaintInfo);
 }
Ejemplo n.º 47
0
        public static void DrawDragRectangles(Rectangle[] newRects, int indent)
        {
            if (newRects.Length > 0)
            {
                // Create the first region
                IntPtr newRegion = CreateRectangleRegion(newRects[0], indent);

                for(int index=1; index<newRects.Length; index++)
                {
                    // Create the extra region
                    IntPtr extraRegion = CreateRectangleRegion(newRects[index], indent);

                    // Remove the intersection of the existing and extra regions
                    Gdi32.CombineRgn(newRegion, newRegion, extraRegion, (int)Win32.CombineFlags.RGN_XOR);

                    // Remove unwanted intermediate objects
                    Gdi32.DeleteObject(extraRegion);
                }

                // Get hold of the DC for the desktop
                IntPtr hDC = User32.GetDC(IntPtr.Zero);

                // Define the area we are allowed to draw into
                Gdi32.SelectClipRgn(hDC, newRegion);

                Win32.RECT rectBox = new Win32.RECT();

                // Get the smallest rectangle that encloses region
                Gdi32.GetClipBox(hDC, ref rectBox);

                IntPtr brushHandler = GetHalfToneBrush();

                // Select brush into the device context
                IntPtr oldHandle = Gdi32.SelectObject(hDC, brushHandler);

                // Blit to screen using provided pattern brush and invert with existing screen contents
                Gdi32.PatBlt(hDC,
                             rectBox.left,
                             rectBox.top,
                             rectBox.right - rectBox.left,
                             rectBox.bottom - rectBox.top,
                             (uint)RasterOperations.PATINVERT);

                // Put old handle back again
                Gdi32.SelectObject(hDC, oldHandle);

                // Reset the clipping region
                Gdi32.SelectClipRgn(hDC, IntPtr.Zero);

                // Remove unwanted region object
                Gdi32.DeleteObject(newRegion);

                // Must remember to release the HDC resource!
                User32.ReleaseDC(IntPtr.Zero, hDC);
            }
        }
Ejemplo n.º 48
0
		protected override void OnPaint(PaintEventArgs e)
		{
			base.OnPaint(e);

			// Get window area
			Win32.RECT rc = new Win32.RECT();
			WindowsAPI.GetWindowRect(Handle, ref rc);

			// Convert to a client size rectangle
			Rectangle rect = new Rectangle(0, 0, rc.right - rc.left, rc.bottom - rc.top);

			Graphics g = e.Graphics;
			DrawBackground(g, rect);
			DrawBorder(g, rect);
			DrawForeground(g, rect);

		}
Ejemplo n.º 49
0
 private void DrawStringByOneChar2(IntPtr hdc, GWord word, int display_length, IntPtr bkbrush, float fx, int y, RenderProfile prof)
 {
     float pitch = prof.Pitch.Width;
     int nextoffset = WordNextOffset(word);
     if(bkbrush!=IntPtr.Zero) { //���ꂪ�Ȃ��Ɠ��{�ꕶ���s�b�`���������Ƃ��I����̂����܂��ł���ꍇ������
         Win32.RECT rect = new Win32.RECT();
         rect.left = (int)fx;
         rect.top  = y;
         rect.right = (int)(fx + pitch*display_length);
         rect.bottom = y + (int)prof.Pitch.Height;
         Win32.FillRect(hdc, ref rect, bkbrush);
     }
     for(int i=word.Offset; i<nextoffset; i++) {
         char ch = _text[i];
         if(ch=='\0') break;
         if(ch==GLine.WIDECHAR_PAD) continue;
         unsafe {
             Win32.TextOut(hdc, (int)fx, y, &ch, 1);
         }
         fx += pitch * CalcDisplayLength(ch);
     }
 }
Ejemplo n.º 50
0
 public static extern int DrawThemeBackground(IntPtr hTheme,
                                              IntPtr hDC,
                                              int partId,
                                              int stateId,
                                              ref Win32.RECT rect,
                                              IntPtr clip);
Ejemplo n.º 51
0
 public static extern int GetClipBox(IntPtr hDC, ref Win32.RECT rectBox);
Ejemplo n.º 52
0
        private IntPtr HookProc(IntPtr hdlg, int msg, IntPtr wParam, IntPtr lParam)
        {
            switch (msg)
            {
            case Win32.WM_INITDIALOG:
                // Center the dialog on its owner
                Win32.RECT sr     = new Win32.RECT();
                Win32.RECT cr     = new Win32.RECT();
                IntPtr     parent = Win32.GetParent(hdlg);
                Win32.GetWindowRect(parent, ref cr);

                Win32.GetWindowRect(Owner.Handle, ref sr);

                int x = (sr.Right + sr.Left - (cr.Right - cr.Left)) / 2;
                int y = (sr.Bottom + sr.Top - (cr.Bottom - cr.Top)) / 2;

                Win32.SetWindowPos(parent, IntPtr.Zero, x, y, cr.Right - cr.Left, cr.Bottom - cr.Top + 32, Win32.SWP_NOZORDER);

                IntPtr fileTypeWindow = Win32.GetDlgItem(parent, 0x441);
                IntPtr fontHandle     = Win32.SendMessage(fileTypeWindow, Win32.WM_GETFONT, IntPtr.Zero, IntPtr.Zero);

                //we now need to find the combo-box to position the new tick box under

                IntPtr     fileComboWindow = Win32.GetDlgItem(parent, 0x470);
                Win32.RECT aboveRect       = new Win32.RECT();
                Win32.GetWindowRect(fileComboWindow, ref aboveRect);

                Win32.POINT point = new Win32.POINT();
                point.X = aboveRect.Left;
                point.Y = aboveRect.Bottom;
                Win32.ScreenToClient(parent, ref point);

                Win32.POINT rightPoint = new Win32.POINT();
                rightPoint.X = aboveRect.Right;
                rightPoint.Y = aboveRect.Top;

                Win32.ScreenToClient(parent, ref rightPoint);

                //we create the new combobox

                IntPtr comboHandle = Win32.CreateWindowEx(0, "BUTTON", "", Win32.WS_VISIBLE | Win32.WS_CHILD | Win32.WS_TABSTOP | Win32.BS_AUTOCHECKBOX, point.X, point.Y + 8, rightPoint.X - point.X, 16, parent, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                fontHandle = Win32.SendMessage(fileTypeWindow, Win32.WM_GETFONT, IntPtr.Zero, IntPtr.Zero);

                Win32.SendMessage(comboHandle, Win32.WM_SETFONT, fontHandle, IntPtr.Zero);
                Win32.SendMessage(comboHandle, Win32.WM_SETTEXT, IntPtr.Zero, Messages.EXPORT_VM_VERIFY_POST_INSTALL);
                Win32.SendMessage(comboHandle, Win32.BM_SETCHECK, (IntPtr)(Verify ? Win32.BST_CHECKED : Win32.BST_UNCHECKED), IntPtr.Zero);

                //remember the handles of the controls we have created so we can destroy them after
                ComboHandle = comboHandle;
                break;

            case Win32.WM_DESTROY:
                //destroy the handles we have created
                if (ComboHandle != IntPtr.Zero)
                {
                    Win32.DestroyWindow(ComboHandle);
                }
                break;

            case Win32.WM_NOTIFY:

                //we need to intercept the CDN_FILEOK message
                //which is sent when the user selects a filename

                Win32.NMHDR nmhdr = (Win32.NMHDR)Marshal.PtrToStructure(lParam, typeof(Win32.NMHDR));

                if (nmhdr.code == Win32.CDN_FILEOK)
                {
                    Verify = Win32.SendMessage(ComboHandle, Win32.BM_GETCHECK, IntPtr.Zero, IntPtr.Zero) == (IntPtr)Win32.BST_CHECKED;
                }
                else if (nmhdr.code == Win32.CDN_HELP)
                {
                    Help.HelpManager.Launch("ExportVMDialog");
                }
                break;
            }
            return(IntPtr.Zero);
        }
Ejemplo n.º 53
0
		protected void RefreshAllCommands()
		{
			Win32.RECT rectRaw = new Win32.RECT();

			// Grab the screen rectangle of the window
			WindowsAPI.GetWindowRect(this.Handle, ref rectRaw);

			// Convert from screen to client sizing
			Rectangle rectWin = new Rectangle(0, 0,
											  rectRaw.right - rectRaw.left,
											  rectRaw.bottom - rectRaw.top);

			using(Graphics g = Graphics.FromHwnd(this.Handle))
			{
				// Draw the background area
				DrawBackground(g, rectWin);

				// Draw the actual menu items
				DrawAllCommands(g);
			}
		}
Ejemplo n.º 54
0
		protected bool ParentWantsMouseMessage(ref Win32.MSG msg)
		{
			Win32.POINT screenPos;
			screenPos.x = (int)((uint)msg.lParam & 0x0000FFFFU);
			screenPos.y = (int)(((uint)msg.lParam & 0xFFFF0000U) >> 16);

			// Convert the mouse position to screen coordinates
			WindowsAPI.ClientToScreen(msg.hwnd, ref screenPos);

			// Special case the MOUSEMOVE so if we are part of a MenuControl
			// then we should always allow mousemoves to be processed
			if ((msg.message == (int)Msg.WM_MOUSEMOVE) && (_parentControl != null))
			{
				Win32.RECT rectRaw = new Win32.RECT();

				// Grab the screen rectangle of the parent control
				WindowsAPI.GetWindowRect(_parentControl.Handle, ref rectRaw);

				if ((screenPos.x >= rectRaw.left) &&
					(screenPos.x <= rectRaw.right) &&
					(screenPos.y >= rectRaw.top) &&
					(screenPos.y <= rectRaw.bottom))
					return true;
			}

			if (_parentMenu != null)
				return _parentMenu.WantMouseMessage(screenPos);
			else
				return false;
		}
Ejemplo n.º 55
0
        /*
        static void
            ScreenSaverCreateChildren(IntPtr hWndParent)
        {
            RECT rc;
            g_iMonitor = 0;

            switch (iMultiMonPosition) {
                case MULTIMON_PERMONITOR:
                    EnumDisplayMonitors(NULL, NULL, ScreenSaverCreateChildrenCb,
                                        (LPARAM)hWndParent);
                    return;

                case MULTIMON_PRIMARY:
                    SetRect(&rc, 0, 0,
                            GetSystemMetrics(SM_CXSCREEN),
                            GetSystemMetrics(SM_CYSCREEN));
                    break;

                case MULTIMON_ALLMONITORS:
                default:
                    GetClientRect(hWndParent, &rc);
                    break;
            }

            ScreenSaverCreateChild(hWndParent, &rc, 0, NULL);
        }

        int ScreenSaverCreateChildrenCb(IntPtr hMonitor, IntPtr hdcMonitor,
                                        Win32.RECT lprcMonitor, IntPtr dwData)
        {
            IntPtr hWndParent = dwData;
            Win32.RECT rcMonitorChild=new Win32.RECT();

            Win32.User.MONITORINFOEX mi;
            memset(&mi, 0, sizeof mi);
            mi.cbSize = sizeof mi;
            Win32.User.GetMonitorInfo(hMonitor, (MONITORINFO *)&mi);
            _RPT1(_CRT_WARN, "Found monitor: %s\n", mi.szDevice);

            rcMonitorChild = *lprcMonitor;
            ScreenToClient(hWndParent, ((POINT*)&rcMonitorChild) + 0);
            ScreenToClient(hWndParent, ((POINT*)&rcMonitorChild) + 1);

            ScreenSaverCreateChild(hWndParent, &rcMonitorChild, g_iMonitor++, mi.szDevice);
            return TRUE;
        }*/
        /*static void
            ScreenSaverCreateChild(HWND hWndParent, RECT *rc, int iMonitor, char *device)
        {
            char szName[20];
            FlurryAnimateChildInfo *child;

            wsprintf(szName, "flurryMon%d", iMonitor);
            _RPT2(_CRT_WARN, "Creating child %s on device %s:\n", szName, device);

            child = new FlurryAnimateChildInfo;
            memset(child, 0, sizeof *child);
            child->id = iMonitor;
            child->rc = *rc;
            child->device = device ? strdup(device) : NULL;
            child->fps.startTime = timeGetTime();

            #define RECTWIDTH(rc)  ((rc).right - (rc).left)
            #define RECTHEIGHT(rc) ((rc).bottom - (rc).top)

            // 200: n% / 100, and it counts on each size, so / 2 more
            InflateRect(&child->rc,
                        -(int)(iFlurryShrinkPercentage * RECTWIDTH(child->rc) / 200),
                        -(int)(iFlurryShrinkPercentage * RECTHEIGHT(child->rc) / 200));

            _RPT4(_CRT_WARN, "  position %d, %d, %d, %d\n",
                  child->rc.left, child->rc.top, RECTWIDTH(child->rc), RECTHEIGHT(child->rc));
            CreateWindow("FlurryAnimateChild", szName, WS_VISIBLE | WS_CHILD,
                         child->rc.left, child->rc.top, RECTWIDTH(child->rc), RECTHEIGHT(child->rc),
                         hWndParent, NULL, NULL, child);
        }*/
        /*
         * FlurryAnimateChildWindowProc
         *
         * WndProc for the child windows that actually do the drawing.
         * We handle WM_CREATE (setup), various painting and timer messages for
         * animation, and forward mouse and keyboard messages to our parent.
         */
        /*int FlurryAnimateChildWindowProc(HWND hWnd, UINT message,
                                         WPARAM wParam, LPARAM lParam)
        {
            FlurryAnimateChildInfo *child = (FlurryAnimateChildInfo *)
                GetWindowLong(hWnd, GWL_USERDATA);
            #ifdef _DEBUG
            static int iFrameCounter = 0;
            #endif

            switch (message) {
                    case WM_CREATE: {
                        CREATESTRUCT *create = (CREATESTRUCT *)lParam;
                        // initialize per-child struct as window data
                        child = (FlurryAnimateChildInfo *)create->lpCreateParams;
                        child->hWnd = hWnd;
                        SetWindowLong(hWnd, GWL_USERDATA, (LONG)child);
                        // initialize flurry struct
                        int preset = child->id < g_multiMonPreset.size() ?
                            g_multiMonPreset[child->id] : iFlurryPreset;
                        child->flurry = new FlurryGroup(preset);
                        // prepare OpenGL context
                        AttachGLToWindow(child);
                        // prepare Flurry code --  must come after OpenGL initialization
                        child->flurry->PrepareToAnimate();
                        // set repaint timer
                        SetTimer(hWnd, 1, child->updateInterval, NULL);
                        // set up text parameters, in case we want to say anything
                        SetTextColor(child->hdc, 0xFFFFFF);
                        SetBkColor(child->hdc, 0x000000);
                        //SetBkMode(child->hdc, TRANSPARENT);
                        return 0;
                    }

                case WM_ERASEBKGND:
                    // Never erase, so we get that nice fade effect initially and
                    // between frames.
                    return 0;

                case WM_PAINT:
                    _RPT1(_CRT_WARN, "Start render frame %d\n", iFrameCounter);
                    if (wglMakeCurrent(child->hdc, child->hglrc)) {
                        PAINTSTRUCT ps;
                        BeginPaint(hWnd, &ps);
                        CopyFrontBufferToBack(hWnd);	// always call; may do nothing
                        child->flurry->AnimateOneFrame();
                        if (iSettingBufferMode > BUFFER_MODE_SINGLE) {
                            // ATI Radeon 9700s seem to get really upset if we call
                            // SwapBuffers in a single-buffered context when invoked
                            // with /p.  So be careful not to!
                            SwapBuffers(ps.hdc);
                        }
                        EndPaint(hWnd, &ps);
                    } else {
                        _RPT1(_CRT_WARN, "OnPaint: wglMakeCurrent failed, error %d\n",
                              GetLastError());
                    }
                    ScreenSaverUpdateFpsIndicator(child);
                    _RPT1(_CRT_WARN, "End render frame %d\n", iFrameCounter++);
                    return 0;

                case WM_TIMER:
                    InvalidateRect(hWnd, NULL, FALSE);
                    UpdateWindow(hWnd);
                    return 0;

                case WM_DESTROY:
                    DetachGLFromWindow(child);
                    delete child->flurry;
                    free(child->device);
                    free(child);
                    SetWindowLong(hWnd, GWL_USERDATA, 0);
                    return 0;

                case WM_MOUSEMOVE:
                case WM_LBUTTONDOWN:
                case WM_LBUTTONUP:
                case WM_RBUTTONDOWN:
                case WM_RBUTTONUP:
                case WM_KEYDOWN:
                case WM_KEYUP:
                case WM_SYSKEYDOWN:
                case WM_SYSKEYUP:
                    // forward input messages to parent, which will probably dismiss us
                    // note that the children don't actually get keyboard messages; the
                    // main window has the focus.
                    return SendMessage(GetParent(hWnd), message, wParam, lParam);
            }

            return DefWindowProc(hWnd, message, wParam, lParam);
        }*/
        /*
         * RegisterDialogClasses
         *
         * Scrnsave.lib entry point: called before ScreenSaverConfigureDialog when
         * invoked with /c.
         */
        /*int RegisterDialogClasses(HANDLE hInst)
        {
            _Module.Init(NULL, (HINSTANCE)hInst);
            return TRUE;
        }*/
        /*
         * ScreenSaverConfigureDialog
         *
         * Scrnsave.lib entry point: called when invoked with /c.
         */
        /*int ScreenSaverConfigureDialog(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
        {
            switch (message) {
                case WM_INITDIALOG:
                    ScreensaverCommonInit();
                    Settings_Read();
                    SettingsDialogInit(hWnd);
                    SettingsDialogEnableControls(hWnd);
                    SettingsToDialog(hWnd);
                    return TRUE;
                    break;

                case WM_COMMAND:
                    switch (LOWORD(wParam)) {
                            // command buttons:
                        case IDOK:
                            SettingsFromDialog(hWnd);
                            Settings_Write();
                            EndDialog(hWnd, 1);
                            return TRUE;
                        case IDCANCEL:
                            EndDialog(hWnd, 0);
                            return TRUE;
                        case IDC_CREDITS:
                            DialogBoxParam(NULL, MAKEINTRESOURCE(DLG_CREDITS), hWnd, CreditsDialog, 0);
                            return TRUE;
                        case IDC_ABOUT:
                            CAboutBox::AutomaticDoModal();
                            return TRUE;
                        case IDC_TEST:
                            SettingsFromDialog(hWnd);
                            DoTestScreenSaver();
                            return TRUE;

                            // radio buttons:
                        case IDC_POSITION_DESKTOP:
                        case IDC_POSITION_PRIMARY:
                        case IDC_POSITION_PER:
                            SettingsDialogEnableControls(hWnd);
                            break;
                    }
                    break; // from WM_COMMAND
                case WM_DESTROY:
                    _Module.Term();
                    break;
            }

            return FALSE;
        }

        static void
            SettingsDialogEnableControls(HWND hWnd)
        {
            // Configure button enabled only when relevant
            EnableWindow(GetDlgItem(hWnd, IDC_POSITION_PER_CONFIGURE),
                         IsDlgButtonChecked(hWnd, IDC_POSITION_PER));

            // but all multimon stuff enabled only on multimon system
            if (g_nMonitors <= 1) {
                EnableWindow(GetDlgItem(hWnd, IDC_POSITION_PRIMARY), FALSE);
                EnableWindow(GetDlgItem(hWnd, IDC_POSITION_PER), FALSE);
                EnableWindow(GetDlgItem(hWnd, IDC_POSITION_PER_CONFIGURE), FALSE);
            }

            // XXX and per-monitor flurry assignment isn't implemented yet anyway
            EnableWindow(GetDlgItem(hWnd, IDC_POSITION_PER_CONFIGURE), FALSE);
        }

        static void
            SettingsDialogInit(HWND hWnd)
        {
            HWND hPresetList = GetDlgItem(hWnd, IDC_VISUAL);
            for (int i = 0; i < g_visuals.size(); i++) {
                ComboBox_AddString(hPresetList, g_visuals[i]->name);
            }
        }

        static void
            SettingsToDialog(HWND hWnd)
        {
            // visual preset
            ComboBox_SetCurSel(GetDlgItem(hWnd, IDC_VISUAL), iFlurryPreset);

            // multimon options
            if (g_nMonitors <= 1) {
                iMultiMonPosition = MULTIMON_ALLMONITORS;
            }
            CheckRadioButton(hWnd, IDC_POSITION_DESKTOP, IDC_POSITION_PER,
                             IDC_POSITION_DESKTOP + iMultiMonPosition);

            // buffering mode
            CheckRadioButton(hWnd, IDC_DOUBLE_BUFFER_NONE, IDC_DOUBLE_BUFFER_PARANOID,
                             IDC_DOUBLE_BUFFER_NONE + iSettingBufferMode);
        }

        static void
            SettingsFromDialog(HWND hWnd)
        {
            // visual preset
            iFlurryPreset = ComboBox_GetCurSel(GetDlgItem(hWnd, IDC_VISUAL));

            // multimon options
            if (IsDlgButtonChecked(hWnd, IDC_POSITION_DESKTOP)) {
                iMultiMonPosition = MULTIMON_ALLMONITORS;
            } else if (IsDlgButtonChecked(hWnd, IDC_POSITION_PRIMARY)) {
                iMultiMonPosition = MULTIMON_PRIMARY;
            } else if (IsDlgButtonChecked(hWnd, IDC_POSITION_PER)) {
                iMultiMonPosition = MULTIMON_PERMONITOR;
            }

            // buffering mode
            if (IsDlgButtonChecked(hWnd, IDC_DOUBLE_BUFFER_NONE)) {
                iSettingBufferMode = BUFFER_MODE_SINGLE;
            } else if (IsDlgButtonChecked(hWnd, IDC_DOUBLE_BUFFER_OPTIMISTIC)) {
                iSettingBufferMode = BUFFER_MODE_FAST_DOUBLE;
            } else if (IsDlgButtonChecked(hWnd, IDC_DOUBLE_BUFFER_PARANOID)) {
                iSettingBufferMode = BUFFER_MODE_SAFE_DOUBLE;
            }
        }*/
        // WGL attach/detach code
        /*
        static void
            AttachGLToWindow(FlurryAnimateChildInfo *child)
        {
            // find current display settings on this monitor
            DEVMODE mode;
            EnumDisplaySettings(child->device, ENUM_CURRENT_SETTINGS, &mode);
            _RPT4(_CRT_WARN, "  current display settings %dx%dx%dbpp@%dHz\n",
                  mode.dmPelsWidth, mode.dmPelsHeight, mode.dmBitsPerPel, mode.dmDisplayFrequency);
            if (mode.dmDisplayFrequency == 0) {	// query failed
                mode.dmDisplayFrequency = 60;	// default to sane value
            }
            _RPT1(_CRT_WARN, "  refresh time = %d ms\n", 1000 / mode.dmDisplayFrequency);
            child->updateInterval = 1000 / mode.dmDisplayFrequency;

            // build a pixel format
            int iPixelFormat;
            RECT rc;
            PIXELFORMATDESCRIPTOR pfd = {
                sizeof(PIXELFORMATDESCRIPTOR),    // structure size
                1,                                // version number
                PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL, // flags: support OpenGL rendering to visible window
                PFD_TYPE_RGBA,                    // pixel format: RGBA
                mode.dmBitsPerPel,                // color depth, excluding alpha -- use whatever it's doing now
                0, 0, 0, 0, 0, 0, 8, 0,           // color bits ignored?
                0,                                // no accumulation buffer
                0, 0, 0, 0,                       // accum bits ignored
                16,                               // 16-bit z-buffer
                0,                                // no stencil buffer
                0,                                // no auxiliary buffer
                PFD_MAIN_PLANE,                   // main layer
                0,                                // reserved
                0, 0, 0                           // layer masks ignored
            };

            if (iSettingBufferMode > BUFFER_MODE_SINGLE) {
                pfd.dwFlags |= PFD_DOUBLEBUFFER;
            }

            // need a DC for the pixel format
            child->hdc = GetDC(child->hWnd);

            // apply pixel format to DC
            iPixelFormat = ChoosePixelFormat(child->hdc, &pfd);
            SetPixelFormat(child->hdc, iPixelFormat, &pfd);

            // then use this to create a rendering context
            child->hglrc = wglCreateContext(child->hdc);
            wglMakeCurrent(child->hdc, child->hglrc);

            // tell Flurry to use the whole window as viewport
            GetClientRect(child->hWnd, &rc);
            child->flurry->SetSize(rc.right - rc.left, rc.bottom - rc.top);

            // some nice debug output
            _RPT4(_CRT_WARN, "  child 0x%08x: hWnd 0x%08x, hdc 0x%08x, hglrc 0x%08x\n",
                  child, child->hWnd, child->hdc, child->hglrc);
            _RPT1(_CRT_WARN, "  GL vendor:     %s\n", glGetString(GL_VENDOR));
            _RPT1(_CRT_WARN, "  GL renderer:   %s\n", glGetString(GL_RENDERER));
            _RPT1(_CRT_WARN, "  GL version:    %s\n", glGetString(GL_VERSION));
            _RPT1(_CRT_WARN, "  GL extensions: %s\n", glGetString(GL_EXTENSIONS));
            _RPT0(_CRT_WARN, "\n");
        }

        static void
            DetachGLFromWindow(FlurryAnimateChildInfo *child)
        {
            if (child->hglrc == wglGetCurrentContext()) {
                _RPT1(_CRT_WARN, "Evicting context %d\n", child->id);
                wglMakeCurrent(NULL, NULL);
            }
            if (!wglDeleteContext(child->hglrc)) {
                _RPT2(_CRT_WARN, "Failed to delete context for %d: %d\n",
                      child->id, GetLastError());
            }
            ReleaseDC(child->hWnd, child->hdc);
        }
        */
        void CopyFrontBufferToBack(IntPtr hWnd)
        {
            bool bFirstTime = true;

            // copy front buffer to back buffer, to compensate for Windows'
            // possibly weird implementation of SwapBuffers().  As documented, it
            // reserves the right to leave the back buffer completely undefined
            // after each swap, but on both my ATI Radeon 8500 and NVidia GF4Ti4200
            // it works almost fine to just copy front to back once like this.

            if ((iSettingBufferMode == BUFFER.BUFFER_MODE_SAFE_DOUBLE) ||
                (iSettingBufferMode == BUFFER.BUFFER_MODE_FAST_DOUBLE && bFirstTime)) {
                Win32.RECT rc=new Win32.RECT();
                Win32.User.GetClientRect(hWnd, ref rc);

                Gl.glDisable(Gl.GL_ALPHA_TEST);
                if (!iBugWhiteout) {
                    // Found this by accident; Adam likes it.  Freakshow option #1.
                    Gl.glDisable(Gl.GL_BLEND);
                }
                Gl.glReadBuffer(Gl.GL_FRONT);
                Gl.glDrawBuffer(Gl.GL_BACK);
                Gl.glRasterPos2i(0, 0);
                Gl.glCopyPixels(0, 0, rc.Right, rc.Bottom, Gl.GL_COLOR);
                if (!iBugWhiteout) {
                    Gl.glEnable(Gl.GL_BLEND);
                }
                Gl.glEnable(Gl.GL_ALPHA_TEST);

                bFirstTime = false;
            }
        }
Ejemplo n.º 56
0
		protected bool WantMouseMessage(Win32.POINT screenPos)
		{
			Win32.RECT rectRaw = new Win32.RECT();

			// Grab the screen rectangle of the window
			WindowsAPI.GetWindowRect(this.Handle, ref rectRaw);

			bool want = ((screenPos.x >= rectRaw.left) &&
						 (screenPos.x <= rectRaw.right) &&
						 (screenPos.y >= rectRaw.top) &&
						 (screenPos.y <= rectRaw.bottom));

			if (!want && (_parentMenu != null))
				want = _parentMenu.WantMouseMessage(screenPos);

			return want;
		}
Ejemplo n.º 57
0
        void DrawTextBoxState(DrawState drawState)
        {
            // Get window area
              Win32.RECT rc = new Win32.RECT();
              WindowsAPI.GetWindowRect(Handle, ref rc);
              // Convert to Rectangle
              Rectangle rect = new Rectangle(0, 0, rc.right - rc.left, rc.bottom - rc.top);

              // Create DC for the whole edit window instead of just for the client area
              IntPtr hDC = WindowsAPI.GetWindowDC(Handle);

              using (Graphics g = Graphics.FromHdc(hDC))
              {
            // This rectangle is always drawn for any state
            using ( Pen windowPen = new Pen(SystemBrushes.Window) )
            {
              g.DrawRectangle(windowPen, rect.Left+1, rect.Top+1, rect.Width-3, rect.Height-3);
            }

            if ( drawState == DrawState.Normal )
            {
              // draw SystemColos.Window rectangle
              using ( Pen windowPen = new Pen(SystemBrushes.Window) )
              {
            g.DrawRectangle(windowPen, rect.Left, rect.Top, rect.Width-1, rect.Height-1);
              }
            }
            else if ( drawState == DrawState.Hot )
            {
              // draw highlighted rectangle
              g.DrawRectangle(SystemPens.Highlight, rect.Left, rect.Top, rect.Width-1, rect.Height-1);
            }
            else if ( drawState == DrawState.Disable )
            {
              // draw highlighted rectangle
              g.FillRectangle(SystemBrushes.Control, rect);
              Size textSize = TextUtil.GetTextSize(g, Text, Font);
              Point point = new Point(rect.Left+1, rect.Top + (rect.Height - textSize.Height)/2);
              if ( PasswordChar !=  0)
              {
            int length = Text.Length;
            string currentText = new String(PasswordChar, length);
            g.DrawString(currentText, Font, SystemBrushes.ControlDark, point);
              }
              else
            g.DrawString(Text, Font, SystemBrushes.ControlDark, point);
            }
              }

              // Release DC
              WindowsAPI.ReleaseDC(Handle, hDC);
        }
Ejemplo n.º 58
0
		protected void OnWM_PAINT(ref Message m)
		{
			// Paint message occurs after the window is created and we have
			// entered the message loop. So this is a good place to handle focus
			if (_grabFocus)
				GrabTheFocus();

			Win32.PAINTSTRUCT ps = new Win32.PAINTSTRUCT();

			// Have to call BeginPaint whenever processing a WM_PAINT message
			IntPtr hDC = WindowsAPI.BeginPaint(m.HWnd, ref ps);

			Win32.RECT rectRaw = new Win32.RECT();

			// Grab the screen rectangle of the window
			WindowsAPI.GetWindowRect(this.Handle, ref rectRaw);

			// Convert to a client size rectangle
			Rectangle rectWin = new Rectangle(0, 0,
				rectRaw.right - rectRaw.left,
				rectRaw.bottom - rectRaw.top);

			// Create a graphics object for drawing
			using(Graphics g = Graphics.FromHdc(hDC))
			{
				// Create bitmap for drawing onto
				using (Bitmap memoryBitmap = new Bitmap(rectWin.Width, rectWin.Height))
				{
				using(Graphics h = Graphics.FromImage(memoryBitmap))
				{
					// Draw the background area
					DrawBackground(h, rectWin);

					// Draw the actual menu items
					DrawAllCommands(h);
				}

				// Blit bitmap onto the screen
				g.DrawImageUnscaled(memoryBitmap, 0, 0);
			}
			}

			// Don't forget to end the paint operation!
			WindowsAPI.EndPaint(m.HWnd, ref ps);
		}
        private void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
        {
            // MINMAXINFO structure
            Win32.MINMAXINFO mmi = (Win32.MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(Win32.MINMAXINFO));

            // Get handle for nearest monitor to this window
            WindowInteropHelper wih = new WindowInteropHelper(this);
            IntPtr hMonitor         = Win32.MonitorFromWindow(wih.Handle, Win32.MONITOR_DEFAULTTONEAREST);

            // Get monitor info
            Win32.MONITORINFOEX monitorInfo = new Win32.MONITORINFOEX();
            monitorInfo.cbSize = Marshal.SizeOf(monitorInfo);
            Win32.GetMonitorInfo(new HandleRef(this, hMonitor), monitorInfo);

            // Get HwndSource
            HwndSource source = HwndSource.FromHwnd(wih.Handle);

            if (source == null)
            {
                // Should never be null
                throw new Exception("Cannot get HwndSource instance.");
            }
            if (source.CompositionTarget == null)
            {
                // Should never be null
                throw new Exception("Cannot get HwndTarget instance.");
            }

            // Get transformation matrix

            //取消了DPI相关转换
            //Matrix matrix = source.CompositionTarget.TransformFromDevice;

            // Convert working area
            Win32.RECT workingArea        = monitorInfo.rcWork;
            Point      dpiIndependentSize =
                new Point(//注释DPI转换相关
                    workingArea.Right - workingArea.Left,
                    workingArea.Bottom - workingArea.Top
                    );
            //Point dpiIndependentSize =
            //    matrix.Transform(new Point(
            //            workingArea.Right - workingArea.Left,
            //            workingArea.Bottom - workingArea.Top
            //            ));

            // Convert minimum size
            Point dpiIndenpendentTrackingSize = new Point(//取消DPI相关转换
                this.MinWidth,
                this.MinHeight
                );

            //Point dpiIndenpendentTrackingSize = matrix.Transform(new Point(
            //    this.MinWidth,
            //    this.MinHeight
            //    ));

            // Set the maximized size of the window
            mmi.ptMaxSize.x = (int)dpiIndependentSize.X;
            mmi.ptMaxSize.y = (int)dpiIndependentSize.Y;

            // Set the position of the maximized window
            mmi.ptMaxPosition.x = 0;
            mmi.ptMaxPosition.y = 0;

            // Set the minimum tracking size
            mmi.ptMinTrackSize.x = (int)dpiIndenpendentTrackingSize.X;
            mmi.ptMinTrackSize.y = (int)dpiIndenpendentTrackingSize.Y;

            Marshal.StructureToPtr(mmi, lParam, true);
        }
Ejemplo n.º 60
0
 public static extern bool GetWindowRect(IntPtr hWnd, ref Win32.RECT lpRect);