int DrawSysButtonFrame(HDC hdc, RECT *pRect, COLORREF clrBorder, COLORREF clrBack, HRGN* hRgns) { HBRUSH hBackBrush; HBRUSH hBorderBrush; HRGN hRgn; int width = pRect->right - pRect->left; POINT prt[2][4] = { {{pRect->left, pRect->top}, {pRect->left + width*0.31, pRect->top}, {pRect->left + width*0.62, pRect->top}, {pRect->right, pRect->top}}, {{pRect->left, pRect->bottom}, {pRect->left + width*0.31, pRect->bottom}, {pRect->left + width*0.62, pRect->bottom}, {pRect->right, pRect->bottom}} }; int radius = 3; hBorderBrush = CreateSolidBrush(clrBorder); //hBorderBrush = GetSysColorBrush(COLOR_3DSHADOW); hBackBrush = CreateSolidBrush (clrBack); MoveToEx(hdc, prt[0][0].x, prt[0][0].y, NULL); BeginPath(hdc); LineTo(hdc, prt[1][0].x, prt[1][0].y - radius); AngleArc(hdc, prt[1][0].x + radius, prt[1][0].y - radius, radius,180, 90); LineTo(hdc, prt[1][1].x, prt[1][1].y); LineTo(hdc, prt[0][1].x, prt[0][1].y); CloseFigure(hdc); EndPath(hdc); hRgn = PathToRegion(hdc); FillRgn(hdc, hRgn, hBackBrush); FrameRgn(hdc, hRgn, hBorderBrush, 1, 1); hRgns[0] = hRgn; MoveToEx(hdc, prt[0][1].x, prt[0][1].y, NULL); BeginPath(hdc); LineTo(hdc, prt[1][1].x, prt[1][1].y); LineTo(hdc, prt[1][2].x, prt[1][2].y); LineTo(hdc, prt[0][2].x, prt[0][2].y); CloseFigure(hdc); EndPath(hdc); hRgn = PathToRegion(hdc); FillRgn(hdc, hRgn, hBackBrush); FrameRgn(hdc, hRgn, hBorderBrush, 1, 1); hRgns[1] = hRgn; MoveToEx(hdc, prt[0][2].x, prt[0][2].y, NULL); BeginPath(hdc); LineTo(hdc, prt[1][2].x, prt[1][2].y); LineTo(hdc, prt[1][3].x - radius, prt[1][3].y); AngleArc(hdc, prt[1][3].x - radius, prt[1][3].y - radius, radius,270, 90); LineTo(hdc, prt[0][3].x, prt[0][3].y); CloseFigure(hdc); EndPath(hdc); hRgn = PathToRegion(hdc); FillRgn(hdc, hRgn, hBackBrush); FrameRgn(hdc, hRgn, hBorderBrush, 1, 1); hRgns[2] = hRgn; //DeleteObject(hBorderBrush); DeleteObject(hBackBrush); return 0; }
HRGN DrawCloseButton(HDC hdc, const int x, const int y, COLORREF clrBorder, COLORREF clrBack ) { HGDIOBJ hPen = NULL; HGDIOBJ hOldPen; HBRUSH hBrush = NULL; HBRUSH hOldBrush; hPen = CreatePen(PS_SOLID, 2, clrBorder); hOldPen = SelectObject(hdc, hPen); hBrush = CreateSolidBrush (clrBack); hOldBrush = (HBRUSH__*)SelectObject(hdc, hBrush); BeginPath(hdc); AngleArc(hdc, x , y, 6, 0, 360); EndPath(hdc); HRGN hRgn = PathToRegion(hdc); FillRgn(hdc, hRgn, hBrush); DrawLine(hdc, x - 4, y - 4, x + 4, y + 4); DrawLine(hdc, x - 4, y + 4, x + 4, y - 4); SelectObject(hdc, hOldPen); DeleteObject(hPen); DeleteObject(hBrush); return hRgn; }
PHP_METHOD(WinGdiPath, toRegion) { wingdi_devicecontext_object *dc_obj; wingdi_region_object *reg_obj; wingdi_path_object *path_obj; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters_none() == FAILURE) return; WINGDI_RESTORE_ERRORS(); path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); // Create a Region object - we can then grab this from the object store // using its handle. object_init_ex(return_value, ce_wingdi_region); reg_obj = zend_object_store_get_object_by_handle(Z_OBJ_HANDLE_P(return_value) TSRMLS_CC); reg_obj->region_handle = PathToRegion(dc_obj->hdc); if (!reg_obj->region_handle) { wingdi_create_error(GetLastError(), ce_wingdi_exception TSRMLS_CC); return; } }
static GpStatus get_path_hrgn(GpPath *path, GpGraphics *graphics, HRGN *hrgn) { HDC new_hdc=NULL; GpGraphics *new_graphics=NULL; GpStatus stat; INT save_state; if (!path->pathdata.Count) /* PathToRegion doesn't support empty paths */ { *hrgn = CreateRectRgn( 0, 0, 0, 0 ); return *hrgn ? Ok : OutOfMemory; } if (!graphics) { new_hdc = CreateCompatibleDC(0); if (!new_hdc) return OutOfMemory; stat = GdipCreateFromHDC(new_hdc, &new_graphics); graphics = new_graphics; if (stat != Ok) { DeleteDC(new_hdc); return stat; } } else if (!graphics->hdc) { graphics->hdc = new_hdc = CreateCompatibleDC(0); if (!new_hdc) return OutOfMemory; } save_state = SaveDC(graphics->hdc); EndPath(graphics->hdc); SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE : WINDING)); stat = trace_path(graphics, path); if (stat == Ok) { *hrgn = PathToRegion(graphics->hdc); stat = *hrgn ? Ok : OutOfMemory; } RestoreDC(graphics->hdc, save_state); if (new_hdc) { DeleteDC(new_hdc); if (new_graphics) GdipDeleteGraphics(new_graphics); else graphics->hdc = NULL; } return stat; }
static GpStatus get_path_hrgn(GpPath *path, GpGraphics *graphics, HRGN *hrgn) { HDC new_hdc=NULL; GpGraphics *new_graphics=NULL; GpStatus stat; INT save_state; if (!graphics) { new_hdc = GetDC(0); if (!new_hdc) return OutOfMemory; stat = GdipCreateFromHDC(new_hdc, &new_graphics); graphics = new_graphics; if (stat != Ok) { ReleaseDC(0, new_hdc); return stat; } } else if (!graphics->hdc) { graphics->hdc = new_hdc = GetDC(0); if (!new_hdc) return OutOfMemory; } save_state = SaveDC(graphics->hdc); EndPath(graphics->hdc); SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE : WINDING)); stat = trace_path(graphics, path); if (stat == Ok) { *hrgn = PathToRegion(graphics->hdc); stat = *hrgn ? Ok : OutOfMemory; } RestoreDC(graphics->hdc, save_state); if (new_hdc) { ReleaseDC(0, new_hdc); if (new_graphics) GdipDeleteGraphics(new_graphics); else graphics->hdc = NULL; } return stat; }
void CHTMLContainerDlg::SetWindowEllispeFrame(int nWidthEllipse, int nHeightEllipse) { HDC hdc = ::GetDC(m_hWnd); HDC hdcMem = CreateCompatibleDC(hdc); ::ReleaseDC(m_hWnd, hdc); RECT rect; GetWindowRect(&rect); // 画一个圆角矩形。 BeginPath(hdcMem); RoundRect(hdcMem, 0, 0, rect.right - rect.left, rect.bottom - rect.top, nWidthEllipse, nHeightEllipse); EndPath(hdcMem); HRGN hRgn = PathToRegion(hdcMem); // 最后把路径转换为区域。 SetWindowRgn(hRgn, TRUE); }
HRGN DrawChromeFrame(HDC hdc, RECT *pRect, COLORREF clrBorder, COLORREF clrBack) { HBRUSH hBackBrush = NULL; HBRUSH hBorderBrush; HRGN hRgn; hBorderBrush = CreateSolidBrush(clrBorder); hBackBrush = CreateSolidBrush (clrBack); POINT lpts[4], rpts[4]; int spread, eigth, sixth, quarter; int width = pRect->right - pRect->left; int height = pRect->bottom - pRect->top; if (1){//bottom spread = ((float)height) * 2/3; eigth = ((float)height) * 1/8; sixth = ((float)height) * 1/6; quarter = ((float)height) * 1/4; }else{ spread = ((float)width) * 2/3; eigth = ((float)width) * 1/8; sixth = ((float)width) * 1/6; quarter = ((float)width) * 1/4; } pRect->right += spread; lpts[3].x = pRect->left; lpts[3].y = pRect->bottom; lpts[2].x = pRect->left + sixth; lpts[2].y = pRect->bottom - eigth; lpts[1].x = pRect->left + spread - quarter; lpts[1].y = pRect->top + eigth; lpts[0].x = pRect->left + spread; lpts[0].y = pRect->top; rpts[3].x = pRect->right - spread; rpts[3].y = pRect->top; rpts[2].x = pRect->right - spread + quarter; rpts[2].y = pRect->top + eigth; rpts[1].x = pRect->right - sixth; rpts[1].y = pRect->bottom - eigth; rpts[0].x = pRect->right; rpts[0].y = pRect->bottom; MoveToEx(hdc, lpts[3].x, lpts[3].y, NULL); BeginPath(hdc); PolyBezier(hdc, lpts, sizeof(lpts)/sizeof(POINT)); //MoveToEx(hdc, lpts[0].x, lpts[0].y, NULL); LineTo(hdc, rpts[3].x, rpts[3].y); PolyBezier(hdc, rpts, sizeof(rpts)/sizeof(POINT)); //MoveToEx(hdc, rpts[0].x, rpts[0].y, NULL); LineTo(hdc, lpts[3].x, lpts[3].y); CloseFigure(hdc); EndPath(hdc); //StrokePath (hdc); FlattenPath(hdc); hRgn = PathToRegion(hdc); FillRgn(hdc, hRgn, hBackBrush); FrameRgn(hdc, hRgn, hBorderBrush, 1, 1); DeleteObject(hBorderBrush); DeleteObject(hBackBrush); HGDIOBJ hPen = NULL; HGDIOBJ hOldPen; hPen = CreatePen(PS_SOLID, 2, clrBack); hOldPen = SelectObject(hdc, hPen); DrawLine(hdc, rpts[0].x, rpts[0].y, lpts[3].x, lpts[3].y); SelectObject(hdc, hOldPen); DeleteObject(hPen); pRect->left += spread; pRect->right -= spread; return hRgn; }
// // InitWindowRegion // // We display the video in a window that has a region selected into it that // matches the word we are passed in. By doing this we let Windows manage // all the clipping and mouse technology. The trick is in creating a region // that matches the word, which is done by using paths. We create a path for // a temporary HDC, draw the word and then end the path. After that, we can then // ask Windows for a region that describes that path. That gives us a region // for the outside of the word, so we bitwise "not" it to get the word region. // HRESULT CVideoText::InitWindowRegion(TCHAR *pStringName) { ASSERT(pStringName); OSVERSIONINFO VersionInfo; VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); EXECUTE_ASSERT(GetVersionEx(&VersionInfo)); // Set a window region according to the OS capabilities if ((VersionInfo.dwPlatformId & VER_PLATFORM_WIN32_NT) == 0) { m_Size.cx = 320; m_Size.cy = 240; return NOERROR; } // Get the text extents the word passed in will require based on the // font and bitmap selected in the current device context. For it to // be displayed in a different font it must be selected into the HDC HDC hdc = CreateCompatibleDC(m_hdc); HFONT hFont = CreateVideoFont(); SelectObject(hdc,hFont); GetTextExtentPoint32((HDC) hdc, // The output device context pStringName, // The string we'll be using lstrlen(pStringName), // Number of characters in it (LPSIZE) &m_Size); // Filled in with the extents // Create a bitmap that matches the current format HBITMAP hMaskBitmap = CreateCompatibleBitmap(hdc,m_Size.cx,m_Size.cy); if (hMaskBitmap == NULL) { ASSERT(hMaskBitmap); return E_UNEXPECTED; } // Select the monochrome bitmap into the device context HBITMAP hBitmap = (HBITMAP) SelectObject(hdc,hMaskBitmap); EXECUTE_ASSERT(BeginPath(hdc)); // Draw the string into the monochrome bitmap ExtTextOut((HDC) hdc, // Target device context (int) 0, // x coordinate reference (int) 0, // Likewise y coordinate (DWORD) 0, // No special flags to set NULL, // No clipping rectangle pStringName, // Pointer to text words lstrlen(pStringName), // Number of characters NULL); // Intercharacter spacing EXECUTE_ASSERT(EndPath(hdc)); HRGN hOutside = PathToRegion(hdc); HRGN hFullWindow = CreateRectRgn(0,0,m_Size.cx,m_Size.cy); HRGN hWordRegion = CreateRectRgn(0,0,1,1); CombineRgn(hWordRegion,hFullWindow,hOutside,RGN_DIFF); SetWindowRgn(m_hwnd,hWordRegion,TRUE); // Clear up the regions we created DeleteObject(hWordRegion); DeleteObject(hOutside); DeleteObject(hFullWindow); // Delete the HDC and text bitmap SelectObject(hdc,hBitmap); HFONT hDefault = (HFONT) GetStockObject(SYSTEM_FONT); SelectObject(hdc,hDefault); DeleteObject(hFont); DeleteObject(hMaskBitmap); DeleteDC(hdc); return NOERROR; } // InitWindowRegion
BOOL CFavUrlMenuDlg::OnInitDialog() { CDialog::OnInitDialog(); SetFont(&m_font); if (m_bAddFav) { ITEM item; item.type = ITEM_TYPE_BTN_ADD; item.strName = "添加到收藏夹"; item.strPath = m_strParentPath; m_arrItems.Add(item); item.type = ITEM_TYPE_SEPARATOR; m_arrItems.Add(item); GetUrls(m_strParentPath, m_arrItems); }else { ITEM item; item.type = ITEM_TYPE_BTN_OPEN; item.strName = "打开"; item.strPath = m_strParentPath; m_arrItems.Add(item); item.type = ITEM_TYPE_BTN_REMOE; item.strName = "删除"; item.strPath = m_strParentPath; m_arrItems.Add(item); } // 获取最长字符串所占宽度 CClientDC dc(this); int nTextWidthMax = 0; CSize size; dc.SelectObject(&m_font); for (INT_PTR i=0; i<m_arrItems.GetSize(); i++) { CString strText = m_arrItems.GetAt(i).strName; size = dc.GetTextExtent(strText); if (size.cx > nTextWidthMax) nTextWidthMax = size.cx; } nTextWidthMax = nTextWidthMax < 90 ? nTextWidthMax+100: nTextWidthMax+30; size.cx = nTextWidthMax; m_rctFirsItem = CRect(CPoint(m_nBorderWidth, m_nBorderWidth), CSize(size.cx+m_nSpacingHeigth*2, size.cy+m_nSpacingHeigth)); m_rctFirsItem.top += 6; m_rctFirsItem.bottom +=10; CRect rctWnd(0, 0, 0, 0); rctWnd.right = m_nBorderWidth*2 + m_rctFirsItem.Width(); rctWnd.bottom= m_nBorderWidth*2 + m_rctFirsItem.Height()*m_arrItems.GetSize() ; if (m_nBorderWidth % 2) { rctWnd.right += 2; rctWnd.bottom += 2; } dc.BeginPath(); dc.RoundRect(rctWnd, CPoint(m_nBorderWidth, m_nBorderWidth)); dc.EndPath(); HRGN hRgn = PathToRegion(dc.m_hDC); SetWindowRgn(hRgn, FALSE); GetRgnBox(hRgn, &rctWnd); SetWindowPos(NULL, 0, 0, rctWnd.Width(), rctWnd.Height(), SWP_NOMOVE); return TRUE; // 除非设置了控件的焦点,否则返回 TRUE }