private void drawProgressBar() { ProgressBar pb = (ProgressBar)Control.FromHandle(_hProgressBarWnd); RECT ctlRect = new RECT(); cStoreDc tempDc = new cStoreDc(); GetWindowRect(_hProgressBarWnd, ref ctlRect); OffsetRect(ref ctlRect, -ctlRect.Left, -ctlRect.Top); tempDc.Height = ctlRect.Bottom; tempDc.Width = ctlRect.Right; float length = (float)ctlRect.Right / ((float)pb.Maximum / (float)pb.Value); // draw the background alphaBlit(tempDc.Hdc, 0, 0, ctlRect.Right, ctlRect.Bottom, _cBufferDc.Hdc, 0, 0, _cBufferDc.Width, _cBufferDc.Height, 240); // draw the progress bar using (StretchMode mode = new StretchMode(tempDc.Hdc, StretchModeEnum.STRETCH_HALFTONE)) StretchBlt(tempDc.Hdc, 1, 1, (int)length - 1, ctlRect.Bottom - 2, _cProgressBarDc.Hdc, 0, 0, _cProgressBarDc.Width, _cProgressBarDc.Height, 0xCC0020); Graphics g = Graphics.FromHwnd(_hProgressBarWnd); BitBlt(g.GetHdc(), 0, 0, ctlRect.Right, ctlRect.Bottom, tempDc.Hdc, 0, 0, 0xCC0020); g.ReleaseHdc(); g.Dispose(); tempDc.Dispose(); }
private void DrawWindow() { int imageWidth = 0; int imageHeight = 0; int drawWidth = 0; int drawHeight = 0; RECT windowRect = new RECT(); GetWindowRect(ParentWnd, ref windowRect); OffsetRect(ref windowRect, -windowRect.Left, -windowRect.Top); int offset = Focused ? 0 : 1; if (Focused) { } cStoreDc windowDc = new cStoreDc(); windowDc.Height = windowRect.Bottom; windowDc.Width = windowRect.Right; using (StretchMode mode = new StretchMode(windowDc.Hdc, StretchModeEnum.STRETCH_HALFTONE)) { if ((ExcludeLeftEnd == 0) && (ExcludeRightEnd == 0)) { // top imageWidth = _cCaptionBarDc.Width; imageHeight = (_cCaptionBarDc.Height / 2); drawWidth = windowRect.Right - ((_cLeftFrameDc.Width / 2) + (_cRightFrameDc.Width / 2)); drawHeight = (_cCaptionBarDc.Height / 2); StretchBlt(windowDc.Hdc, (_cLeftFrameDc.Width / 2), 0, drawWidth, drawHeight, _cCaptionBarDc.Hdc, 0, (imageHeight * offset), imageWidth, imageHeight, 0xCC0020); } else { int pieceOffset = 0; int centerLength = windowDc.Width - ((_cLeftFrameDc.Width / 2) + (_cRightFrameDc.Width / 2)); // left exclusion area if (ExcludeLeftEnd > 0) { // draw the start if (ExcludeLeftStart > 0) { drawWidth = ExcludeLeftStart; drawHeight = (_cCaptionBarDc.Height / 2); pieceOffset = (_cLeftFrameDc.Width / 2); StretchBlt(windowDc.Hdc, pieceOffset, 0, drawWidth, drawHeight, _cCaptionBarDc.Hdc, 0, (imageHeight * offset), drawWidth, drawHeight, 0xCC0020); } imageWidth = ExcludeLeftEnd - ExcludeLeftStart; imageHeight = (_cCaptionBarDc.Height / 2); pieceOffset = (_cLeftFrameDc.Width / 2) + ExcludeLeftStart; BitBlt(windowDc.Hdc, pieceOffset, 0, imageWidth, imageHeight, _cCaptionBarDc.Hdc, ExcludeLeftStart, (imageHeight * offset), 0xCC0020); centerLength -= ExcludeLeftEnd; } // right exclusion area if (ExcludeRightEnd > 0) { imageWidth = ExcludeRightEnd - ExcludeRightStart; imageHeight = (_cCaptionBarDc.Height / 2); pieceOffset = windowDc.Width - ((_cRightFrameDc.Width / 2) + (_cCaptionBarDc.Width - ExcludeRightStart)); //if (pieceOffset > 0) BitBlt(windowDc.Hdc, pieceOffset, 0, imageWidth, imageHeight, _cCaptionBarDc.Hdc, ExcludeRightStart, (imageHeight * offset), 0xCC0020); centerLength -= imageWidth; } // draw the end if (ExcludeRightEnd < _cCaptionBarDc.Width) { drawWidth = _cCaptionBarDc.Width - ExcludeRightEnd; drawHeight = (_cCaptionBarDc.Height / 2); pieceOffset += (ExcludeRightEnd - ExcludeRightStart); StretchBlt(windowDc.Hdc, pieceOffset, 0, drawWidth, drawHeight, _cCaptionBarDc.Hdc, 0, (imageHeight * offset), drawWidth, drawHeight, 0xCC0020); centerLength -= drawWidth; } // draw the center if (ExcludeRightStart > 0) imageWidth = _cCaptionBarDc.Width - (ExcludeRightStart - ExcludeLeftEnd); else imageWidth = _cCaptionBarDc.Width - ExcludeLeftEnd; imageHeight = (_cCaptionBarDc.Height / 2); pieceOffset = (_cLeftFrameDc.Width / 2) + ExcludeLeftEnd; drawWidth = centerLength; drawHeight = (_cCaptionBarDc.Height / 2); StretchBlt(windowDc.Hdc, pieceOffset, 0, drawWidth, drawHeight, _cCaptionBarDc.Hdc, ExcludeLeftEnd, (imageHeight * offset), imageWidth, imageHeight, 0xCC0020); } // left imageWidth = (_cLeftFrameDc.Width / 2); imageHeight = _cLeftFrameDc.Height - ((_cCaptionBarDc.Height / 2) + (_cBottomFrameDc.Height / 2)); drawWidth = (_cLeftFrameDc.Width / 2); drawHeight = windowRect.Bottom - ((_cCaptionBarDc.Height / 2) + (_cBottomFrameDc.Height / 2)); StretchBlt(windowDc.Hdc, 0, (_cCaptionBarDc.Height / 2), drawWidth, drawHeight, _cLeftFrameDc.Hdc, (imageWidth * offset), (_cCaptionBarDc.Height / 2), imageWidth, imageHeight, 0xCC0020); //right imageWidth = (_cRightFrameDc.Width / 2); imageHeight = _cRightFrameDc.Height - ((_cCaptionBarDc.Height / 2) + (_cBottomFrameDc.Height / 2)); drawWidth = (_cRightFrameDc.Width / 2); drawHeight = windowRect.Bottom - ((_cCaptionBarDc.Height / 2) + (_cBottomFrameDc.Height / 2)); StretchBlt(windowDc.Hdc, (windowRect.Right - imageWidth), (_cCaptionBarDc.Height / 2), drawWidth, drawHeight, _cRightFrameDc.Hdc, (imageWidth * offset), (_cCaptionBarDc.Height / 2), imageWidth, imageHeight, 0xCC0020); // bottom imageWidth = _cBottomFrameDc.Width; imageHeight = (_cBottomFrameDc.Height / 2); drawWidth = windowRect.Right - ((_cLeftFrameDc.Width / 2) + (_cRightFrameDc.Width / 2)); drawHeight = (_cBottomFrameDc.Height / 2); StretchBlt(windowDc.Hdc, (_cLeftFrameDc.Width / 2), windowRect.Bottom - (_cBottomFrameDc.Height / 2), drawWidth, drawHeight, _cBottomFrameDc.Hdc, 0, (imageHeight * offset), imageWidth, imageHeight, 0xCC0020); } // top left imageWidth = (_cLeftFrameDc.Width / 2); imageHeight = (_cCaptionBarDc.Height / 2); BitBlt(windowDc.Hdc, 0, 0, imageWidth, imageHeight, _cLeftFrameDc.Hdc, (imageWidth * offset), 0, 0xCC0020); // top right imageWidth = (_cRightFrameDc.Width / 2); imageHeight = (_cCaptionBarDc.Height / 2); BitBlt(windowDc.Hdc, (windowRect.Right - imageWidth), 0, imageWidth, imageHeight, _cRightFrameDc.Hdc, (imageWidth * offset), 0, 0xCC0020); // bottom left imageWidth = (_cLeftFrameDc.Width / 2); imageHeight = (_cBottomFrameDc.Height / 2); BitBlt(windowDc.Hdc, 0, (windowRect.Bottom - imageHeight), imageWidth, imageHeight, _cLeftFrameDc.Hdc, (imageHeight * offset), (_cLeftFrameDc.Height - imageHeight), 0xCC0020); // bottom right imageWidth = (_cRightFrameDc.Width / 2); imageHeight = (_cBottomFrameDc.Height / 2); BitBlt(windowDc.Hdc, (windowRect.Right - imageWidth), (windowRect.Bottom - imageHeight), imageWidth, imageHeight, _cRightFrameDc.Hdc, (imageHeight * offset), (_cRightFrameDc.Height - imageHeight), 0xCC0020); RECT captionRect = new RECT(0, 0, windowDc.Width, _cCaptionBarDc.Height / 2); DrawButtons(windowDc.Hdc, captionRect); DrawIcon(windowDc.Hdc, captionRect); DrawTitle(windowDc.Hdc, captionRect); // exclude client area imageWidth = (_cLeftFrameDc.Width / 2); imageHeight = (_cCaptionBarDc.Height / 2); //drawWidth = windowRect.Right - ((_leftFrameDc.Width / 2) + (_rightFrameDc.Width / 2)); //drawHeight = windowRect.Bottom - ((_captionBarDc.Height / 2) + (_bottomFrameDc.Height / 2)); drawWidth = ((_cLeftFrameDc.Width / 2) + (_cRightFrameDc.Width / 2)); drawHeight = ((_cCaptionBarDc.Height / 2) + (_cBottomFrameDc.Height / 2)); IntPtr hdc = GetWindowDC(ParentWnd); RECT clientRect = new RECT(); GetWindowRect(ParentWnd, ref clientRect); OffsetRect(ref clientRect, -clientRect.Left, -clientRect.Top); OffsetRect(ref clientRect, -drawWidth, -drawHeight); ExcludeClipRect(hdc, imageWidth, imageHeight, clientRect.Right + imageWidth, clientRect.Bottom + imageHeight); // blit to window BitBlt(hdc, 0, 0, windowRect.Right, windowRect.Bottom, windowDc.Hdc, 0, 0, 0xCC0020); // clean up ReleaseDC(ParentWnd, hdc); windowDc.Dispose(); }
private void drawPushbutton(object sender, Graphics g, int state) { int width = _oPushbuttonBitmap.Width / 5; int offset = state * width; IntPtr hdc = g.GetHdc(); Button btn = (Button)sender; RECT bounds = new RECT(0, 0, btn.Width, btn.Height); // back fill IntPtr hbrush = CreateSolidBrush(GetPixel(hdc, 0, 0)); FillRect(hdc, ref bounds, hbrush); DeleteObject(hbrush); using (StretchMode mode = new StretchMode(hdc, StretchModeEnum.STRETCH_HALFTONE)) { // blit the corners: top left BitBlt(hdc, 0, 0, 4, 4, _cPushbuttonDc.Hdc, offset, 0, 0xCC0020); // bottom left BitBlt(hdc, 0, bounds.Bottom - 4, 4, 4, _cPushbuttonDc.Hdc, offset, _cPushbuttonDc.Height - 4, 0xCC0020); // top right BitBlt(hdc, bounds.Right - 4, 0, 4, 4, _cPushbuttonDc.Hdc, (offset + width) - 4, 0, 0xCC0020); // bottom right BitBlt(hdc, bounds.Right - 4, bounds.Bottom - 4, 4, 4, _cPushbuttonDc.Hdc, (offset + width) - 4, _cPushbuttonDc.Height - 4, 0xCC0020); // fill in the sides: left StretchBlt(hdc, 0, 4, 4, bounds.Bottom - 8, _cPushbuttonDc.Hdc, offset, 4, 4, _cPushbuttonDc.Height - 8, 0xCC0020); // right StretchBlt(hdc, bounds.Right - 4, 4, 4, bounds.Bottom - 8, _cPushbuttonDc.Hdc, (offset + width) - 4, 4, 4, _cPushbuttonDc.Height - 8, 0xCC0020); // top StretchBlt(hdc, 4, 0, bounds.Right - 8, 4, _cPushbuttonDc.Hdc, offset + 4, 0, width - 8, 4, 0xCC0020); // bottom StretchBlt(hdc, 4, bounds.Bottom - 4, bounds.Right - 8, 4, _cPushbuttonDc.Hdc, offset + 4, _cPushbuttonDc.Height - 4, width - 8, 4, 0xCC0020); // draw the center StretchBlt(hdc, 4, 4, bounds.Right - 8, bounds.Bottom - 8, _cPushbuttonDc.Hdc, offset + 4, 4, width - 8, _cPushbuttonDc.Height - 8, 0xCC0020); } g.ReleaseHdc(); // draw the image if (btn.Image != null) { int imgwidth = btn.Image.Width; int imgheight = btn.Image.Height; // image alignment: bottom if (btn.ImageAlign == ContentAlignment.BottomCenter) g.DrawImage(btn.Image, new Point((bounds.Right - (imgwidth + 4)) / 2, bounds.Bottom - (imgheight + 4))); else if (btn.ImageAlign == ContentAlignment.BottomLeft) g.DrawImage(btn.Image, new Point(4, bounds.Bottom - (imgheight + 4))); else if (btn.ImageAlign == ContentAlignment.BottomRight) g.DrawImage(btn.Image, new Point(bounds.Right - (imgwidth + 4), bounds.Bottom - (imgheight + 4))); //middle else if (btn.ImageAlign == ContentAlignment.MiddleCenter) g.DrawImage(btn.Image, new Point((bounds.Right - (imgwidth + 4)) / 2, (bounds.Bottom - (imgheight + 4)) / 2)); else if (btn.ImageAlign == ContentAlignment.MiddleLeft) g.DrawImage(btn.Image, new Point(4, (bounds.Bottom - (imgheight + 4)) / 2)); else if (btn.ImageAlign == ContentAlignment.MiddleRight) g.DrawImage(btn.Image, new Point(bounds.Right - (imgwidth + 4), (bounds.Bottom - (imgheight + 4)) / 2)); // top else if (btn.ImageAlign == ContentAlignment.TopCenter) g.DrawImage(btn.Image, new Point((bounds.Right - (imgwidth + 4)) / 2, 4)); else if (btn.ImageAlign == ContentAlignment.TopLeft) g.DrawImage(btn.Image, new Point(4, 4)); else if (btn.ImageAlign == ContentAlignment.TopRight) g.DrawImage(btn.Image, new Point(bounds.Right - (imgwidth + 4), 4)); } // draw the text using (StringFormat sf = new StringFormat()) { sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; sf.FormatFlags = StringFormatFlags.DisplayFormatControl; // text alignment: bottom if (btn.TextAlign == ContentAlignment.BottomCenter) { sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Far; } else if (btn.TextAlign == ContentAlignment.BottomLeft) { sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Far; } else if (btn.TextAlign == ContentAlignment.BottomRight) { sf.Alignment = StringAlignment.Far; sf.LineAlignment = StringAlignment.Far; } // middle else if (btn.TextAlign == ContentAlignment.MiddleCenter) { sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; } else if (btn.TextAlign == ContentAlignment.MiddleLeft) { sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; } else if (btn.TextAlign == ContentAlignment.MiddleRight) { sf.Alignment = StringAlignment.Far; sf.LineAlignment = StringAlignment.Center; } // top else if (btn.TextAlign == ContentAlignment.TopCenter) { sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Near; } else if (btn.TextAlign == ContentAlignment.TopLeft) { sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Near; } else if (btn.TextAlign == ContentAlignment.TopRight) { sf.Alignment = StringAlignment.Far; sf.LineAlignment = StringAlignment.Near; } if (btn.RightToLeft == RightToLeft.Yes) sf.FormatFlags = StringFormatFlags.DirectionRightToLeft; Brush ht = new SolidBrush(btn.ForeColor); g.DrawString(btn.Text, btn.Font, ht, new RectangleF(0, 0, bounds.Right - 4, bounds.Bottom - 4), sf); ht.Dispose(); } }