Example #1
0
HRGN RegionFromSkinWithOffset(HBITMAP hBmp, COLORREF crMask, int offset, int bWidth){
	
	HRGN		hRgn = CreateRectRgn(0, 0, 0, 0);
	int			x = offset;
	BITMAP		bmp;
	HDC			hdcMem;
	HBITMAP		hbOld;

	bWidth += offset;
	hdcMem = CreateCompatibleDC(GetDC(0));
	hbOld = SelectBitmap(hdcMem, hBmp);
	GetObject(hBmp, sizeof(bmp), &bmp);
	for(int y = 0; y < bmp.bmHeight; y++){
		do{
			while(x < bWidth && GetPixel(hdcMem, x, y) == crMask)
				x++;
			int leftX = x;
			while(x < bWidth && GetPixel(hdcMem, x, y) != crMask)
				++x;
			HRGN rgnTemp = CreateRectRgn(leftX, y, x, y + 1);
			CombineRgn(hRgn, hRgn, rgnTemp, RGN_OR);
			DeleteRgn(rgnTemp);
		}while(x < bWidth);
		x = offset;
	}
	SelectBitmap(hdcMem, hbOld);
	DeleteDC(hdcMem);
	return hRgn;
}
Example #2
0
/**
 * @param hdc - drawing conImage.
 * @param prcPaint - the rectangle where the painting is requested.
 */
void CImageView::DrawImageView(HDC hdc, const RECT* prcPaint)
{
	_ASSERTE(g_pResManager != NULL);
	RECT rcClient;
	GetClientRect(m_hwnd, &rcClient);
	if (prcPaint == NULL)
		prcPaint = &rcClient;
	if (IsRectEmpty(prcPaint))
		return;

#ifdef USE_MEM_DC
	int nClientWidth = prcPaint->right - prcPaint->left;
	int nClientHeight = prcPaint->bottom - prcPaint->top;
	HBITMAP hbmpMem;
	hbmpMem = CreateCompatibleBitmap(hdc, nClientWidth, nClientHeight);
	if (hbmpMem == NULL)
		return;
	HDC hdcMem;
	hdcMem = CreateCompatibleDC(hdc);
	if (hdcMem == NULL)
	{
		DeleteBitmap(hbmpMem);
		return;
	}
	SetViewportOrgEx(hdcMem, -prcPaint->left, -prcPaint->top, NULL);
	HBITMAP hbmpSafe = SelectBitmap(hdcMem, hbmpMem);
#else
	// CS_PARENTDC sets the clipping rectangle of the child window to that of the parent window
	// so that the child can draw on the parent. Text view inherits this style from sub-classed
	// static control. This causes problems with unclipped TabbedTextOut() output.
	HRGN hrgn = CreateRectRgnIndirect(prcPaint);
	SelectClipRgn(hdc, hrgn);
	DeleteRgn(hrgn);
	HDC hdcMem = hdc;
#endif

	FillRect(hdcMem, prcPaint, g_pResManager->m_hbrWindowBrush);
	HDC hdcTemp = CreateCompatibleDC(hdc);
	if (hdcTemp)
	{
		HBITMAP hbmpSafe2 = SelectBitmap(hdcTemp, m_hAdjustedBitmap);
		int nHorPos = GetScrollPos(m_hwnd, SB_HORZ);
		int nVertPos = GetScrollPos(m_hwnd, SB_VERT);
		int nImageLeft = rcClient.right > m_szAjustedBitmapSize.cx ? (rcClient.right - m_szAjustedBitmapSize.cx) / 2 : -nHorPos;
		int nImageTop = rcClient.bottom > m_szAjustedBitmapSize.cy ? (rcClient.bottom - m_szAjustedBitmapSize.cy) / 2 : -nVertPos;
		BitBlt(hdcMem, nImageLeft, nImageTop, m_szAjustedBitmapSize.cx, m_szAjustedBitmapSize.cy, hdcTemp, 0, 0, SRCCOPY);
		SelectBitmap(hdcTemp, hbmpSafe2);
		DeleteDC(hdcTemp);
	}

#ifdef USE_MEM_DC
	BitBlt(hdc, prcPaint->left, prcPaint->top, nClientWidth, nClientHeight, hdcMem, prcPaint->left, prcPaint->top, SRCCOPY);
	SelectBitmap(hdcMem, hbmpSafe);
	DeleteDC(hdcMem);
	DeleteBitmap(hbmpMem);
#endif
}
Example #3
0
// This function clears the graphics screen (with the background color) and
// moves the current point to (0,0)
//
void cleardevice( )
{
    HDC hDC;
    WindowData* pWndData = BGI__GetWindowDataPtr( );
    int color;          // Background color to fill with
    RECT rect;          // The rectangle to fill
    HRGN hRGN;          // The clipping region (if any)
    int is_rgn;         // Whether or not a clipping region is present
    POINT p;            // Upper left point of window (convert from device to logical points)
    HBRUSH hBrush;      // Brush in the background color

    // Convert from BGI color to RGB color
    color = converttorgb( pWndData->bgColor );

    hDC = BGI__GetWinbgiDC( );
    // Even though a viewport may be set, this function clears the entire screen.
    // Compute the origin in logical coordinates.
    p.x = 0;
    p.y = 0;
    DPtoLP( hDC, &p, 1 );
    rect.left = p.x;
    rect.top = p.y;
    rect.right = pWndData->width;
    rect.bottom = pWndData->height;

    // Get the current clipping region, if any.  The region object must first
    // be created with some valid region.  If the GetClipRgn function
    // succeeds, the region info will be updated to reflect the new region.
    // However, this does not create a new region object.  That is, this
    // simply overwrites the memory of the old region object and we don't have
    // to worry about deleting the old region.
    hRGN = CreateRectRgn( 0, 0, 5, 5 );
    is_rgn = GetClipRgn( hDC, hRGN );
    // If there is a clipping region, select none
    if ( is_rgn != 0 )
        SelectClipRgn( hDC, NULL );
    
    // Fill hDC with background color
    hBrush = CreateSolidBrush( color );
    FillRect( hDC, &rect, hBrush );
    DeleteObject( hBrush );
    // Move the CP back to (0,0) (NOT viewport relative)
    moveto( p.x, p.y );

    // Select the old clipping region back into the device context
    if ( is_rgn != 0 )
        SelectClipRgn( hDC, hRGN );
    // Delete the region
    DeleteRgn( hRGN );
    BGI__ReleaseWinbgiDC( );
    
    RefreshWindow( NULL );
}
//Call this function when the toolbar recieves a WM_MOVE or WM_SIZE
void WindowMagnetizer::OnToolbarBoundsChanged()
{
	//No need to erase the last focus rect, the toolbar already covers it
	lastFocusRect.left=INT_MIN;
	//Eventually move the toolbar
	CheckToolbarPos();
	BOOL dfw;
	SystemParametersInfo(SPI_GETDRAGFULLWINDOWS,0,&dfw,0);
	if(!dfw)
	{
		//Completely repaint the toolbar
		InvalidateRect(toolbar,NULL,TRUE);
		RECT tbRect;
		GetWindowRect(toolbar,&tbRect);
		HRGN refRgn = CreateRectRgnIndirect(&tbRect);
		FORWARD_WM_NCPAINT(toolbar,refRgn,SendMessage);
		DeleteRgn(refRgn);
	}
}
//WM_DRAWITEM
void PBSettings_OnDrawItem(HWND hwnd, const DRAWITEMSTRUCT * lpDrawItem)
{
	//Get the PBSDP
	PenBrushSettingsDlgParam * pbsdp=(PenBrushSettingsDlgParam *)(LONG_PTR)GetWindowLongPtr(hwnd,GWLP_USERDATA);
	switch(lpDrawItem->CtlID) //Controls switch
	{
	case IDC_PB_PREVIEW: //Preview pane
		{
			RECT fillRct=lpDrawItem->rcItem;
			HRGN fillRgn=CreateRectRgnIndirect(&fillRct);
			ArrowSettings tas=UITC->GetTool<UIArrowline>(IDC_TB_ARROWLINE)->GetArrowSettings();
			//Paint the background with a white brush
			FillRgn(lpDrawItem->hDC,fillRgn,(HBRUSH)GetStockObject(WHITE_BRUSH));
			//Select the pen and the brush and set the appropriate settigns
			BEGIN_SELOBJ(lpDrawItem->hDC,pbsdp->GetPreviewPaneFGCU().GetPen(),hDC_pen);
			BEGIN_SELOBJ(lpDrawItem->hDC,pbsdp->GetPreviewPaneBGCU().GetBrush(),hDC_brush);
			pbsdp->GetPreviewPaneFGCU().ApplyACUPs(lpDrawItem->hDC);
			//Draw a filled rectangle in the left part of the rectangle
			Rectangle(lpDrawItem->hDC,fillRct.left+5,fillRct.top+5,(fillRct.right-fillRct.left)/2-5,fillRct.bottom-5);
			//Draw a filled arrow in the top right part of the rectangle
			MoveToEx(lpDrawItem->hDC,(fillRct.right-fillRct.left)/2+5,fillRct.top+5,NULL);
			tas.drawSecondArrow=true;
			ArrowTo(lpDrawItem->hDC,fillRct.right-5,fillRct.bottom-25,&tas);
			//Draw a line in the bottom right part of the rectangle
			MoveToEx(lpDrawItem->hDC,(fillRct.right-fillRct.left)/2+5,fillRct.bottom-15,NULL);
			LineTo(lpDrawItem->hDC,fillRct.right-5,fillRct.bottom-5);
			//Deselect the pen and the brush
			END_SELOBJ(lpDrawItem->hDC,hDC_brush);
			END_SELOBJ(lpDrawItem->hDC,hDC_pen);
			DeleteRgn(fillRgn);
			break;
		} //End IDC_PB_PREVIEW
	case IDC_PB_B_COLOR: //Color panes
	case IDC_PB_H_COLORP:
		{
			HBRUSH hbr=CreateSolidBrush((lpDrawItem->CtlID==IDC_PB_B_COLOR?pbsdp->GetCurrentCU().GetColor():pbsdp->GetCurrentCU().GetACUPs().bgColor));
			FillRect(lpDrawItem->hDC,&lpDrawItem->rcItem,hbr);
			DeleteBrush(hbr);
			break;
		} //End IDC_PB_B_COLOR
	}
}
Example #6
0
/**
 * @param hdc - drawing context.
 * @param prcPaint - the rectangle in which the painting is requested.
 */
void CTextView::DrawTextView(HDC hdc, RECT* prcPaint)
{
	_ASSERTE(g_pResManager != NULL);
	if (prcPaint == NULL)
	{
		RECT rcClient;
		GetClientRect(m_hwnd, &rcClient);
		prcPaint = &rcClient;
	}
	if (IsRectEmpty(prcPaint))
		return;

#ifdef USE_MEM_DC
	int nClientWidth = prcPaint->right - prcPaint->left;
	int nClientHeight = prcPaint->bottom - prcPaint->top;
	HBITMAP hbmpMem;
	hbmpMem = CreateCompatibleBitmap(hdc, nClientWidth, nClientHeight);
	if (hbmpMem == NULL)
		return;
	HDC hdcMem;
	hdcMem = CreateCompatibleDC(hdc);
	if (hdcMem == NULL)
	{
		DeleteBitmap(hbmpMem);
		return;
	}
	SetViewportOrgEx(hdcMem, -prcPaint->left, -prcPaint->top, NULL);
	HBITMAP hbmpSafe = SelectBitmap(hdcMem, hbmpMem);
#else
	// CS_PARENTDC sets the clipping rectangle of the child window to that of the parent window
	// so that the child can draw on the parent. Text view inherits this style from sub-classed
	// static control. This causes problems with unclipped TabbedTextOut() output.
	HRGN hrgn = CreateRectRgnIndirect(prcPaint);
	SelectClipRgn(hdc, hrgn);
	DeleteRgn(hrgn);
	HDC hdcMem = hdc;
#endif

	FillRect(hdcMem, prcPaint, g_pResManager->m_hbrWindowBrush);

	COLORREF rgbOldTextColor = SetTextColor(hdcMem, GetSysColor(COLOR_WINDOWTEXT));
	COLORREF rgbOldBackground = SetBkColor(hdcMem, GetSysColor(COLOR_WINDOW));
	HFONT hOldFont = g_pResManager->m_hFixedFont ? SelectFont(hdcMem, g_pResManager->m_hFixedFont) : NULL;
	TEXTMETRIC tmetr;
	::GetTextMetrics(hdcMem, &tmetr);

	DWORD dwNumLines = m_arrLines.GetCount();
	DWORD dwTopLineNum = GetScrollPos(m_hwnd, SB_VERT);
	DWORD dwTopVisLineNum = dwTopLineNum + prcPaint->top / tmetr.tmHeight;

	if (dwTopVisLineNum < dwNumLines)
	{
		int nHorPos = tmetr.tmAveCharWidth - GetScrollPos(m_hwnd, SB_HORZ);
		int nVertPos = prcPaint->top - prcPaint->top % tmetr.tmHeight;
		DWORD dwNumVisLines = prcPaint->bottom / tmetr.tmHeight;
		if (prcPaint->bottom % tmetr.tmHeight)
			++dwNumVisLines;
		DWORD dwBottomVisLineNum = dwTopLineNum + dwNumVisLines - 1;
		if (dwBottomVisLineNum >= dwNumLines)
			dwBottomVisLineNum = dwNumLines - 1;

		for (DWORD dwLineNum = dwTopVisLineNum; dwLineNum <= dwBottomVisLineNum; ++dwLineNum)
		{
			CacheLine(dwLineNum);
			const CLineInfo& rLineInfo = m_arrLines[(int)dwLineNum];
			int nTextWidth = LOWORD(TabbedTextOut(hdcMem, nHorPos, nVertPos, m_pTextCache + rLineInfo.m_dwTextStart, rLineInfo.m_dwLength, 0, NULL, -nHorPos));
			if (rLineInfo.m_bTruncated)
				TextOut(hdcMem, nHorPos + nTextWidth, nVertPos, g_szEllipsis, g_dwEllipsisLength);
			nVertPos += tmetr.tmHeight;
		}
	}

	SetTextColor(hdcMem, rgbOldTextColor);
	SetBkColor(hdcMem, rgbOldBackground);
	if (hOldFont)
		SelectFont(hdcMem, hOldFont);

#ifdef USE_MEM_DC
	BitBlt(hdc, prcPaint->left, prcPaint->top, nClientWidth, nClientHeight, hdcMem, prcPaint->left, prcPaint->top, SRCCOPY);
	SelectBitmap(hdcMem, hbmpSafe);
	DeleteDC(hdcMem);
	DeleteBitmap(hbmpMem);
#endif
}