private void drawScrollBar() { SCROLLBARINFO sbi = new SCROLLBARINFO(); RECT tr = new RECT(); cStoreDc tempDc = new cStoreDc(); int offset = 0; int width = 0; int section = 0; GetWindowRect(_hScrollBarWnd, ref tr); OffsetRect(ref tr, -tr.Left, -tr.Top); tempDc.Width = tr.Right; tempDc.Height = tr.Bottom; SB_HITEST hitTest = scrollbarHitTest(); sbi.cbSize = Marshal.SizeOf(sbi); SendMessage(_hScrollBarWnd, SBM_GETSCROLLBARINFO, 0, ref sbi); if (Direction == Orientation.Horizontal) { // draw the track using (StretchImage si = new StretchImage(_cTrackDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, _cTrackDc.Width, _cTrackDc.Height), new Rectangle(_iArrowCx, 0, tr.Right - (2 * _iArrowCx), tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { } // draw the arrows section = 7; width = _cArrowDc.Width / section; // left arrow if (hitTest == SB_HITEST.leftArrow) { if (leftKeyPressed()) offset = 2; else offset = 1; } else { offset = 0; } using (StretchImage si = new StretchImage(_cArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cArrowDc.Height), new Rectangle(0, 0, _iArrowCx, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { } // right arrow if (hitTest == SB_HITEST.rightArrow) { if (leftKeyPressed()) offset = 5; else offset = 4; } else { offset = 3; } using (StretchImage si = new StretchImage(_cArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cArrowDc.Height), new Rectangle(tr.Right - _iArrowCx, 0, _iArrowCx, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { } // draw the thumb section = 3; width = _cThumbDc.Width / section; if (hitTest == SB_HITEST.button) { if (leftKeyPressed()) offset = 2; else offset = 1; } else { offset = 0; } Point pst = getScrollBarThumb(); using (StretchImage si = new StretchImage(_cThumbDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cThumbDc.Height), new Rectangle(pst.X, 0, pst.Y - pst.X, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { } } else { // draw the track using (StretchImage si = new StretchImage(_cTrackDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, _cTrackDc.Width, _cTrackDc.Height), new Rectangle(0, _iArrowCy, tr.Right, tr.Bottom - (2 * _iArrowCy)), 2, StretchModeEnum.STRETCH_HALFTONE)) { } section = 6; width = _cArrowDc.Width / section; // top arrow if (hitTest == SB_HITEST.topArrow) { if (leftKeyPressed()) offset = 2; else offset = 1; } else { offset = 0; } using (StretchImage si = new StretchImage(_cArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cArrowDc.Height), new Rectangle(0, 0, tr.Right, _iArrowCy), 2, StretchModeEnum.STRETCH_HALFTONE)) { } // bottom arrow if (hitTest == SB_HITEST.bottomArrow) { if (leftKeyPressed()) offset = 5; else offset = 4; } else { offset = 3; } using (StretchImage si = new StretchImage(_cArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cArrowDc.Height), new Rectangle(0, tr.Bottom - _iArrowCy, tr.Right, _iArrowCy), 2, StretchModeEnum.STRETCH_HALFTONE)) { } // draw the thumb section = 3; width = _cThumbDc.Width / section; if (hitTest == SB_HITEST.button) { if (leftKeyPressed()) offset = 2; else offset = 1; } else { offset = 0; } Point pst = getScrollBarThumb(); using (StretchImage si = new StretchImage(_cThumbDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cThumbDc.Height), new Rectangle(0, pst.X, _iArrowCx, pst.Y - pst.X), 2, StretchModeEnum.STRETCH_HALFTONE)) { } } IntPtr hdc = GetDC(_hMaskWnd); BitBlt(hdc, 0, 0, tr.Right, tr.Bottom, tempDc.Hdc, 0, 0, 0xCC0020); ReleaseDC(_hMaskWnd, hdc); tempDc.Dispose(); }
private void drawCombo() { int offset = 0; int width = _oComboboxBitmap.Width / 4; RECT tr = new RECT(); GetWindowRect(_hComboWnd, ref tr); OffsetRect(ref tr, -tr.Left, -tr.Top); Rectangle cr = new Rectangle(0, 0, tr.Right, tr.Bottom); ComboBox cb = (ComboBox)Control.FromHandle(_hComboWnd); // get button size tr = comboButton(); // backfill and border using (Graphics g = Graphics.FromHwnd(_hComboWnd)) { using (Brush flatBrush = new SolidBrush(cb.Enabled ? Color.White : Color.FromKnownColor(KnownColor.InactiveBorder))) g.FillRectangle(flatBrush, cr); cr.Height--; cr.Width--; using (Pen borderPen = new Pen(Color.FromKnownColor(KnownColor.ControlLight), 0.5f)) { g.DrawLine(borderPen, cr.X, cr.Y + 1, cr.X, cr.Height); g.DrawLine(borderPen, cr.X, cr.Height, cr.Width, cr.Height); } using (Pen borderPen = new Pen(Color.FromKnownColor(KnownColor.ControlDark), 0.5f)) { g.DrawLine(borderPen, cr.X, cr.Y, cr.Width, cr.Y); g.DrawLine(borderPen, cr.Width, cr.Y, cr.Width, cr.Height - 1); } } if (!cb.Enabled) { offset = width * 3; } else { if (cb.DroppedDown) offset = width * 1; else if (cb.Focused || _bMoved) offset = width * 2; else offset = 0; } // draw the image IntPtr hdc = GetDC(_hComboWnd); using (StretchImage si = new StretchImage(_cComboboxDc.Hdc, hdc, new Rectangle(offset, 0, width, _cComboboxDc.Height), new Rectangle(tr.Left, tr.Top, tr.Right - tr.Left, tr.Bottom - tr.Top), 2, StretchModeEnum.STRETCH_HALFTONE)) { } ReleaseDC(_hComboWnd, hdc); }
private void drawHeader() { RECT tr = new RECT(); RECT wr = new RECT(); cStoreDc tempDc = new cStoreDc(); int offset = 0; // set up the temp dc GetWindowRect(_hHeaderWnd, ref wr); OffsetRect(ref wr, -wr.Left, -wr.Top); tempDc.Height = wr.Bottom; tempDc.Width = wr.Right; int width = _cHeaderDc.Width / 4; for (int i = 0; i < ColumnCount; i++) { if (!Enabled()) { offset = width * 3; } else if (i == focusedColumn()) { if (leftKeyPressed()) offset = width * 2; else offset = width; } else { offset = 0; } SendMessage(_hHeaderWnd, HDM_GETITEMRECT, i, ref tr); using (StretchImage st = new StretchImage(_cHeaderDc.Hdc, tempDc.Hdc, new Rectangle(offset, 0, width, _cHeaderDc.Height), new Rectangle(tr.Left, tr.Top, tr.Right - tr.Left, tr.Bottom - tr.Top), 3, StretchModeEnum.STRETCH_HALFTONE)) { } // button, icon, sort arrows and text if (hasButton(i)) drawButton(tempDc.Hdc, i, tr); if (hasSort(i)) drawSortArrow(tempDc.Hdc, i, tr); if (hasIcon(i)) drawIcon(tempDc.Hdc, i, tr); drawText(tempDc.Hdc, i, tr); } // draw the end piece SendMessage(_hHeaderWnd, HDM_GETITEMRECT, columnAtIndex(ColumnCount - 1), ref tr); int left = tr.Right; GetWindowRect(_hHeaderWnd, ref tr); OffsetRect(ref tr, -tr.Left, -tr.Top); tr.Left = left; tr.Right += 10; using (StretchImage st = new StretchImage(_cHeaderDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, (_cHeaderDc.Width / 3) - 2, _cHeaderDc.Height), new Rectangle(tr.Left, tr.Top, tr.Right - tr.Left + 2, tr.Bottom - tr.Top), 3, StretchModeEnum.STRETCH_HALFTONE)) { } // blit the temp dc IntPtr hdc = GetDC(_hHeaderWnd); BitBlt(hdc, 0, 0, wr.Right, wr.Bottom, tempDc.Hdc, 0, 0, 0xCC0020); ReleaseDC(_hHeaderWnd, hdc); tempDc.Dispose(); }
private void drawScrollBar() { RECT tr = new RECT(); Point pst = new Point(); cStoreDc tempDc = new cStoreDc(); IntPtr hdc = IntPtr.Zero; int offset = 0; int width = 0; int section = 0; SCROLLBARINFO sb = new SCROLLBARINFO(); sb.cbSize = Marshal.SizeOf(sb); if (hasHorizontal()) { GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb); tr = sb.rcScrollBar; OffsetRect(ref tr, -tr.Left, -tr.Top); tempDc.Width = tr.Right; tempDc.Height = tr.Bottom; SB_HITEST hitTest = scrollbarHitTest(Orientation.Horizontal); // draw the track using (StretchImage si = new StretchImage(_cHorizontalTrackDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, _cHorizontalTrackDc.Width, _cHorizontalTrackDc.Height), new Rectangle(_iArrowCx, 0, tr.Right - (2 * _iArrowCx), tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { } // draw the arrows section = 7; width = _cHorizontalArrowDc.Width / section; // left arrow if (hitTest == SB_HITEST.leftArrow) { if (leftKeyPressed()) offset = 2; else offset = 1; } else { offset = 0; } using (StretchImage si = new StretchImage(_cHorizontalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cHorizontalArrowDc.Height), new Rectangle(0, 0, _iArrowCx, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { } // right arrow if (hitTest == SB_HITEST.rightArrow) { if (leftKeyPressed()) offset = 5; else offset = 4; } else { offset = 3; } using (StretchImage si = new StretchImage(_cHorizontalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cHorizontalArrowDc.Height), new Rectangle(tr.Right - _iArrowCx, 0, _iArrowCx, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { } // draw the thumb section = 3; width = _cHorizontalThumbDc.Width / section; if (hitTest == SB_HITEST.button) { if (leftKeyPressed()) offset = 2; else offset = 1; } else { offset = 0; } pst.X = sb.xyThumbTop; pst.Y = sb.xyThumbBottom; using (StretchImage si = new StretchImage(_cHorizontalThumbDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cHorizontalThumbDc.Height), new Rectangle(pst.X, 2, pst.Y - pst.X, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { } hdc = GetDC(_hHorizontalMaskWnd); BitBlt(hdc, 0, 0, tr.Right, tr.Bottom, tempDc.Hdc, 0, 0, 0xCC0020); ReleaseDC(_hHorizontalMaskWnd, hdc); } if (hasSizer()) { tempDc.Width = _iArrowCx; tempDc.Height = _iArrowCy; offset = 6; section = 7; width = _cHorizontalArrowDc.Width / section; using (StretchImage si = new StretchImage(_cHorizontalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cHorizontalArrowDc.Height), new Rectangle(0, 0, _iArrowCx, _iArrowCy), 0, StretchModeEnum.STRETCH_HALFTONE)) { } hdc = GetDC(_hSizerMaskWnd); BitBlt(hdc, 0, 0, _iArrowCx, _iArrowCy, tempDc.Hdc, 0, 0, 0xCC0020); ReleaseDC(_hSizerMaskWnd, hdc); } if (hasVertical()) { GetScrollBarInfo(_hControlWnd, OBJID_VSCROLL, ref sb); tr = sb.rcScrollBar; OffsetRect(ref tr, -tr.Left, -tr.Top); tempDc.Width = tr.Right; tempDc.Height = tr.Bottom; SB_HITEST hitTest = scrollbarHitTest(Orientation.Vertical); // draw the track using (StretchImage si = new StretchImage(_cVerticalTrackDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, _cVerticalTrackDc.Width, _cVerticalTrackDc.Height), new Rectangle(0, _iArrowCy, tr.Right, tr.Bottom - (2 * _iArrowCy)), 2, StretchModeEnum.STRETCH_HALFTONE)) { } section = 6; width = _cVerticalArrowDc.Width / section; // top arrow if (hitTest == SB_HITEST.topArrow) { if (leftKeyPressed()) offset = 2; else offset = 1; } else { offset = 0; } using (StretchImage si = new StretchImage(_cVerticalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cVerticalArrowDc.Height), new Rectangle(0, 0, tr.Right, _iArrowCy), 2, StretchModeEnum.STRETCH_HALFTONE)) { } // bottom arrow if (hitTest == SB_HITEST.bottomArrow) { if (leftKeyPressed()) offset = 5; else offset = 4; } else { offset = 3; } using (StretchImage si = new StretchImage(_cVerticalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cVerticalArrowDc.Height), new Rectangle(0, tr.Bottom - _iArrowCy, tr.Right, _iArrowCy), 2, StretchModeEnum.STRETCH_HALFTONE)) { } // draw the thumb section = 3; width = _cVerticalThumbDc.Width / section; if (hitTest == SB_HITEST.button) { if (leftKeyPressed()) offset = 2; else offset = 1; } else { offset = 0; } pst.X = sb.xyThumbTop; pst.Y = sb.xyThumbBottom; using (StretchImage si = new StretchImage(_cVerticalThumbDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cVerticalThumbDc.Height), new Rectangle(0, pst.X, _iArrowCx, pst.Y - pst.X), 2, StretchModeEnum.STRETCH_HALFTONE)) { } hdc = GetDC(_hVerticalMaskWnd); BitBlt(hdc, 0, 0, tr.Right, tr.Bottom, tempDc.Hdc, 0, 0, 0xCC0020); ReleaseDC(_hVerticalMaskWnd, hdc); } tempDc.Dispose(); }