示例#1
0
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;
}
示例#2
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;
}
示例#3
0
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	case WM_PAINT:
		{
			hdc = BeginPaint(hwnd, &ps);

			RECT Rect;
			GetClientRect( hwnd, &Rect );
			HRGN bgRgn = CreateRectRgnIndirect(&Rect);
			HBRUSH hBrush = CreateSolidBrush(RGB(200,200,200));
			FillRgn(hdc, bgRgn, hBrush);
			HeatMap.DrawBitmap(hdc, GOLD_DROP, 0, 0, 1000, 1000);

			EndPaint(hwnd, &ps);
			break;
		}
	case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
        break;
	}
    return 0;
}
示例#4
0
文件: win32draw.c 项目: Kun-Qu/petsc
static PetscErrorCode PetscDrawPoint_Win32(PetscDraw draw,PetscReal x,PetscReal y,int color)
{       
  PetscDraw_Win32 *windraw = (PetscDraw_Win32*)draw->data;
  HBRUSH          hbrush;
  HRGN            hrgn;
  int             radius;
  int             x1,yone;
  HDC             hdc;
  
  PetscFunctionBegin;
  TranslateColor_Win32(draw,color);
  x1     = XTRANS(draw,windraw,x);   
  yone     = YTRANS(draw,windraw,y);
  hbrush = CreateSolidBrush(windraw->currentcolor);
  if(windraw->node->DoubleBuffered) {
    hdc = windraw->node->DoubleBuffer;
  } else {
    hdc = windraw->node->Buffer;
  }
  /* desired size is one logical pixel so just turn it on */
  if (windraw->pointdiameter == 1) {
    SetPixelV(hdc,x1,yone,windraw->currentcolor);
  } else {
    /* draw point around position determined */
    radius = windraw->pointdiameter/2; /* integer division */
    hrgn   = CreateEllipticRgn(x1-radius,yone-radius,x1+radius,yone+radius);
    FillRgn(hdc,hrgn,hbrush);
  }
  /* Forces a WM_PAINT and erases background */
  InvalidateRect(windraw->hWnd,NULL,TRUE);
  UpdateWindow(windraw->hWnd);
  PetscFunctionReturn(0);
}
示例#5
0
文件: painting.c 项目: GYGit/reactos
/*
 * @implemented
 */
BOOL
WINAPI
PaintRgn(
    _In_ HDC hdc,
    _In_ HRGN hrgn)
{
    return FillRgn(hdc, hrgn, GetCurrentObject(hdc, OBJ_BRUSH));
}
示例#6
0
void CProgressCtrl :: DrawPosition (UINT iPos)
{	
	HRGN hrgn = NULL;
	CDC *pCDC = NULL;
	HBRUSH hBrush = NULL;

	if (iPos == 0)		// Reset !
	{
		hrgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
		m_iDrawPos == 0;
	}		
	else                                        
	{
		UINT iX = UINT (iPos * m_dFaktor);
		if (iX == m_iDrawPos)		// keine Postionsänderung
			return;
		if (iX > m_iDrawPos && iX <= (UINT) rc.Width ())					
			m_iDrawPos = iX;
		else
		{
			if (iX > (UINT) rc.Width())
				m_iDrawPos = rc.right;		
			else
				return;			
		}	
		hrgn = CreateRectRgn(rc.left, rc.top, m_iDrawPos, rc.bottom);					
	}		
	
	if (hrgn)
	{
		pCDC = GetDC (); 	
		if (pCDC)
		{
			int iRgn = (int) SelectObject (pCDC -> m_hDC, hrgn);
			if (NULLREGION != iRgn && ERROR != iRgn)
			{
				if (iPos == 0)
					hBrush = CreateSolidBrush(RGB(iDelCol, iDelCol, iDelCol));	
				else
					hBrush = CreateSolidBrush(RGB(0, 0, iShowCol));					
				if (hBrush)
					FillRgn(pCDC -> m_hDC, hrgn, hBrush);		// Fläche füllen
			}
		}
	}
		
//	alles wieder freigeben		
	if (hrgn)		
		DeleteObject(hrgn);
	if (hBrush)
		DeleteObject (hBrush);
	if (pCDC)		
		ReleaseDC (pCDC);
		
//	Fenster nachzeichnen	
	UpdateWindow ();
}	
示例#7
0
BOOL CALLBACK ProgressProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
	switch(message)
	{
		case WM_INITDIALOG:		
			SetCursor(LoadCursor(NULL,IDC_WAIT));
			rcContext.hProgressWnd=hWnd;
			
			SetWindowLong(GetDlgItem(hWnd,IDC_STATIC1),GWL_WNDPROC,(LONG)Static1WndProc); 

			hWndGif= GetDlgItem(hWnd,IDC_STATIC2);
			if (hWndGif)
			{
				m_wndBanner.SubclassWindow(hWndGif);
				if (m_wndBanner.Load(MAKEINTRESOURCE(IDR_BUSY),_T("GIF"))){
					m_wndBanner.Draw();
				}
			};
			SetCursor(LoadCursor(NULL,IDC_ARROW));
			return TRUE;
		case WM_ERASEBKGND:
			{
				RECT bgRect;
				GetWindowRect(hWnd,&bgRect);
				HRGN bgRgn=CreateRectRgnIndirect(&bgRect);
				HWND hIDC1=GetDlgItem(hWnd,IDC_STATIC1);
				RECT idc1Rect;
				GetWindowRect(hIDC1,&idc1Rect);
				HRGN idc1Rgn=CreateRectRgnIndirect(&idc1Rect);
				if (!CombineRgn(bgRgn, bgRgn,idc1Rgn, RGN_XOR)) return FALSE;
				HBRUSH hBrush=CreateSolidBrush(GetSysColor(COLOR_3DFACE));
				POINT pt;
				HDC hdc=(HDC)wParam;
				GetWindowOrgEx(hdc,&pt);
				SetWindowOrgEx(hdc,bgRect.left,bgRect.top,NULL);
				FillRgn(hdc,bgRgn,hBrush);
				SetWindowOrgEx(hdc,pt.x,pt.y,NULL);
				DeleteObject(hBrush);
			}
			return FALSE;
		case WM_CTLCOLORSTATIC:
			SetBkMode((HDC)wParam,TRANSPARENT);
			return (BOOL)GetStockObject(NULL_BRUSH);
		case WM_DESTROY:
			SetCursor(LoadCursor(NULL,IDC_WAIT));
			CloseHandle(rcContext.hThread);
			rcContext.hProgressWnd=0;
			EndDialog(hWnd,0);
			SetCursor(LoadCursor(NULL,IDC_ARROW));
			return TRUE;
		default:
			return FALSE;
	}
}
示例#8
0
void DrawMapBoundsPoly (CMap* theMap, PolyObjectHdl MapPolyHdl, DrawSpecRecPtr drawSettings, Boolean erasePolygon)
{
	long numPts = (**MapPolyHdl).pointCount;
	POINT **pointsH = (POINT**)_NewHandle(numPts *sizeof(POINT));
	POINT *pointsPtr = (POINT*)_NewPtr(numPts *sizeof(POINT));
	LongPoint** thisPointsHdl=nil;
	Point pt;
	LongPoint wPt;
	long i;
	Boolean offQuickDrawPlane = false;
	RGBColor saveColor; // JLM ?? wouldn't compile without this
	if(!pointsH || !pointsPtr) {SysBeep(5); return;}
	
	thisPointsHdl = (LongPoint**) (**MapPolyHdl).objectDataHdl;
	for(i = 0; i< numPts;i++)
	{
		wPt = INDEXH(thisPointsHdl,i);
		pt = GetQuickDrawPt(wPt.h,wPt.v,&gRect,&offQuickDrawPlane);
		INDEXH(pointsH,i) = MakePOINT(pt.h,pt.v);
		(pointsPtr)[i] = MakePOINT(pt.h,pt.v);
		// code goes here, make sure this point does not equal previous point JLM
	}
	GetForeColor (&saveColor);		/* save original forecolor */

		if (erasePolygon)
		{
			RgnHandle newClip=0;
			HBRUSH whiteBrush;
			newClip = CreatePolygonRgn((const POINT*)pointsPtr,numPts,ALTERNATE);
			whiteBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
			//err = SelectClipRgn(currentHDC,savedClip);
			FillRgn(currentHDC, newClip, whiteBrush);
			//DeleteObject(newClip);
			DisposeRgn(newClip);
			//SelectClipRgn(currentHDC,0);
		}
		else
		{
			POINT p[2];
			p[0] = INDEXH(pointsH,numPts-1);
			p[1] = INDEXH(pointsH,0);
			RGBForeColor(&colors[BLACK]);
			if(numPts >= 2) 
			{
				Polyline(currentHDC,*pointsH,numPts);
				Polyline(currentHDC,p,2);	// close the polygon
			}
		}

	RGBForeColor (&saveColor);
	DisposeHandle((Handle)pointsH);
	if(pointsPtr) {_DisposePtr((Ptr)pointsPtr); pointsPtr = 0;}
}
示例#9
0
文件: painting.c 项目: AndreRH/wine
BOOL nulldrv_FrameRgn( PHYSDEV dev, HRGN rgn, HBRUSH brush, INT width, INT height )
{
    BOOL ret = FALSE;
    HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );

    if (tmp)
    {
        if (REGION_FrameRgn( tmp, rgn, width, height )) ret = FillRgn( dev->hdc, tmp, brush );
        DeleteObject( tmp );
    }
    return ret;
}
示例#10
0
文件: Region.c 项目: xpika/winhugs
static void hugsprim_FillRgn_10(HugsStackPtr hugs_root)
{
    HsPtr arg1;
    HsPtr arg2;
    HsPtr arg3;
    HsBool res1;
    arg1 = hugs->getPtr();
    arg2 = hugs->getPtr();
    arg3 = hugs->getPtr();
    res1 = FillRgn(arg1, arg2, arg3);
    hugs->putBool(res1);
    hugs->returnIO(hugs_root,1);
}
示例#11
0
VOID PenBrushDemo(HDC hdc)
{
	HPEN hPen = CreatePen(PS_DASHDOT, 3, myColor);
	SelectObject(hdc, hPen);
	MoveToEx(hdc, 100, 100, NULL);
	LineTo(hdc, 200, 200);
	Rectangle(hdc, 100, 200, 300, 300);
	Ellipse(hdc, 100, 200, 300, 300);
	HRGN hRegion = CreateEllipticRgn(100, 200, 300, 300);
	HBRUSH hbrush = CreateSolidBrush(RGB(23, 100, 40));
	FillRgn(hdc, hRegion, hbrush);
	Ellipse(hdc, 100, 200, 300, 300);
}
示例#12
0
void 
PF_FillPoly(PF_InData		*in_data,
			PF_ContextH		contextH,
			PolyHandle		poly)

{
#ifdef AE_OS_WIN
	HDC	hdc;
	HBRUSH Brush = GetStockObject(WHITE_BRUSH);
	PF_GET_CGRAF_DATA((*contextH)->cgrafptr, PF_CGrafData_HDC, &hdc);
	FillRgn(hdc, (HRGN)*poly, Brush);
#else
	FillPoly(poly, &in_data->qd_globals->gray);
#endif
}
示例#13
0
LRESULT _stdcall WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static HDC hDC = GetWindowDC(hWnd);
    static HRGN hRgn = CreateRectRgn(120, 70, 280, 230);

    switch(uMsg)
    {
    case WM_ERASEBKGND:
         {
             DefWindowProc(hWnd, uMsg, wParam, lParam);
             FillRgn(hDC, hRgn, CreateSolidBrush(RGB(255, 165, 0))); // Orange
             SelectObject(hDC, hRgn);
             return 0;
         }

     case WM_CREATE:
         {
             HRGN hRgn1 = CreateEllipticRgn(0, 0, 400, 300);
             HRGN hRgn2 = CreateEllipticRgn(150, 100, 250, 200);
             CombineRgn(hRgn1, hRgn1, hRgn2, RGN_XOR);
             SetWindowRgn(hWnd, hRgn1, TRUE);
             DeleteObject(hRgn1);
             DeleteObject(hRgn2);
             break;
         }

     case WM_LBUTTONDOWN:
         {
             SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
             break;
         }

     case WM_DESTROY:
         {
             DeleteObject(hRgn);
             ReleaseDC(hWnd, hDC);
             PostQuitMessage(0);
             break;
         }
     }
     return DefWindowProc(hWnd, uMsg, wParam, lParam);;
 }
//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
	}
}
示例#15
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : rc - 
//			fillr - 
//			fillg - 
//			fillb - 
//-----------------------------------------------------------------------------
void CDrawHelper::DrawTriangleMarker( RECT& rc, COLORREF fill, bool inverted /*= false*/ )
{
	POINT region[3];
	int cPoints = 3;

	if ( !inverted )
	{
		region[ 0 ].x = rc.left - m_x;
		region[ 0 ].y = rc.top - m_y;

		region[ 1 ].x = rc.right - m_x;
		region[ 1 ].y = rc.top - m_y;

		region[ 2 ].x = ( ( rc.left + rc.right ) / 2 ) - m_x;
		region[ 2 ].y = rc.bottom - m_y;
	}
	else
	{
		region[ 0 ].x = rc.left - m_x;
		region[ 0 ].y = rc.bottom - m_y;

		region[ 1 ].x = rc.right - m_x;
		region[ 1 ].y = rc.bottom - m_y;

		region[ 2 ].x = ( ( rc.left + rc.right ) / 2 ) - m_x;
		region[ 2 ].y = rc.top - m_y;
	}

	HRGN rgn = CreatePolygonRgn( region, cPoints, ALTERNATE );

	int oldPF = SetPolyFillMode( m_dcMemory, ALTERNATE );
	
	HBRUSH brFace = CreateSolidBrush( fill );

	FillRgn( m_dcMemory, rgn, brFace );

	DeleteObject( brFace );
	
	SetPolyFillMode( m_dcMemory, oldPF );

	DeleteObject( rgn );
}
示例#16
0
文件: app.cpp 项目: grakidov/Render3D
/*****************************Private*Routine******************************\
* VideoCd_OnPaint
*
\**************************************************************************/
void
VideoCd_OnPaint(
    HWND hwnd
    )
{
    PAINTSTRUCT ps;
    HDC         hdc;
    RECT        rc1;
    RECT        rc2;

    /*
    ** Draw a frame around the movie playback area.
    */
    GetClientRect(hwnd, &rc2);

    hdc = BeginPaint(hwnd, &ps);

    if(pMpegMovie)
    {
        long xPos, yPos, cx, cy;
        GetMoviePosition(hwnd, &xPos, &yPos, &cx, &cy);
        SetRect(&rc1, xPos, yPos, xPos + cx, yPos + cy);

        HRGN rgnClient = CreateRectRgnIndirect(&rc2);
        HRGN rgnVideo  = CreateRectRgnIndirect(&rc1);
        CombineRgn(rgnClient, rgnClient, rgnVideo, RGN_DIFF);

        HBRUSH hbr = GetSysColorBrush(COLOR_BTNFACE);
        FillRgn(hdc, rgnClient, hbr);
        DeleteObject(hbr);
        DeleteObject(rgnClient);
        DeleteObject(rgnVideo);

        pMpegMovie->RepaintVideo(hwnd, hdc);
    }
    else
    {
        FillRect(hdc, &rc2, (HBRUSH)(COLOR_BTNFACE + 1));
    }

    EndPaint(hwnd, &ps);
}
示例#17
0
void CCustomMenu::DrawTopMenuBk(CDC *pDC, CRect Rect, BOOL State)
{
	if (State)		//选中状态
	{
		CPen pen(PS_SOLID,1,RGB(49,106,197));
		pDC->SelectObject(&pen);
		pDC->Rectangle(&Rect);
		Rect.DeflateRect(1,1);
		pDC->FillSolidRect(Rect,m_SelTopColor);
		pen.DeleteObject();
	}
	else
	{
		HRGN nClientRgn =  GetClientMenuRgn();
		CBrush brush(m_BkColor);

		FillRgn(pDC->m_hDC,nClientRgn,brush);
		pDC->FillSolidRect(&Rect,m_BkColor);
		DeleteObject(nClientRgn);
		brush.DeleteObject();
	}
}
void MainWindow::OnPaint()
{
	PAINTSTRUCT ps;
	HDC hdc;

	hdc = BeginPaint(m_hwnd, &ps);

	if (m_pPlayer->State() != STATE_CLOSED && m_pPlayer->HasVideo())
	{
		// The player has video, so ask the player to repaint. 
		m_pPlayer->Repaint(hdc);
	}
	else
	{
		// The player does not have video. Fill in our client region, not 
		// including the area for the toolbar.

		RECT rcClient;
		RECT rcToolbar;

		GetClientRect(m_hwnd, &rcClient);
		GetClientRect(rebar.Window(), &rcToolbar);

		HRGN hRgn1 = CreateRectRgnIndirect(&rcClient);
		HRGN hRgn2 = CreateRectRgnIndirect(&rcToolbar);

		CombineRgn(hRgn1, hRgn1, hRgn2, RGN_DIFF);

		FillRgn(hdc, hRgn1, brush);

		DeleteObject(hRgn1);
		DeleteObject(hRgn2);
	}

	EndPaint(m_hwnd, &ps);
}
示例#19
0
文件: print.c 项目: RareHare/reactos
static LRESULT print_preview(HWND hwndPreview)
{
    HPEN hPen, oldPen;
    HDC hdc;
    HRGN back_rgn, excl_rgn;
    RECT window, background;
    PAINTSTRUCT ps;
    int x, y;

    hdc = BeginPaint(hwndPreview, &ps);
    GetClientRect(hwndPreview, &window);
    back_rgn = CreateRectRgnIndirect(&window);

    x = preview.spacing.cx - GetScrollPos(hwndPreview, SB_HORZ);
    y = preview.spacing.cy - GetScrollPos(hwndPreview, SB_VERT);

    /* draw page outlines */
    hPen = CreatePen(PS_SOLID|PS_INSIDEFRAME, 2, RGB(0,0,0));
    oldPen = SelectObject(hdc, hPen);
    background.left = x - 2;
    background.right = x + preview.bmScaledSize.cx + 2;
    background.top = y - 2;
    background.bottom = y + preview.bmScaledSize.cy + 2;
    Rectangle(hdc, background.left, background.top,
              background.right, background.bottom);
    excl_rgn = CreateRectRgnIndirect(&background);
    CombineRgn(back_rgn, back_rgn, excl_rgn, RGN_DIFF);
    if(preview.pages_shown > 1)
    {
        background.left += preview.bmScaledSize.cx + preview.spacing.cx;
        background.right += preview.bmScaledSize.cx + preview.spacing.cx;
        Rectangle(hdc, background.left, background.top,
                  background.right, background.bottom);
        SetRectRgn(excl_rgn, background.left, background.top,
                   background.right, background.bottom);
        CombineRgn(back_rgn, back_rgn, excl_rgn, RGN_DIFF);
    }
    SelectObject(hdc, oldPen);
    DeleteObject(hPen);
    FillRgn(hdc, back_rgn, GetStockObject(GRAY_BRUSH));
    DeleteObject(excl_rgn);
    DeleteObject(back_rgn);

    StretchBlt(hdc, x, y, preview.bmScaledSize.cx, preview.bmScaledSize.cy,
               preview.hdc, 0, 0, preview.bmSize.cx, preview.bmSize.cy, SRCCOPY);

    draw_margin_lines(hdc, x, y, preview.zoomratio);

    if(preview.pages_shown > 1)
    {
        if (!is_last_preview_page(preview.page)) {
            x += preview.spacing.cx + preview.bmScaledSize.cx;
            StretchBlt(hdc, x, y,
                       preview.bmScaledSize.cx, preview.bmScaledSize.cy,
                       preview.hdc2, 0, 0,
                       preview.bmSize.cx, preview.bmSize.cy, SRCCOPY);

            draw_margin_lines(hdc, x, y, preview.zoomratio);
        } else {
            background.left += 2;
            background.right -= 2;
            background.top += 2;
            background.bottom -= 2;
            FillRect(hdc, &background, GetStockObject(WHITE_BRUSH));
        }
    }

    preview.window = window;

    EndPaint(hwndPreview, &ps);

    return 0;
}
示例#20
0
	int CALLBACK ButtonX::windowProc(HWND hwnd , int message , WPARAM wParam, LPARAM lParam) {
		switch(message) {

		case WM_SETTEXT:
			ButtonX::fromHWND(hwnd)->_text = (char*) lParam;
			//break;
			return 0;
		case WM_GETTEXT:
			if (ButtonX::fromHWND(hwnd)->_duringPaint) {
				((char*)lParam)[0] = 0;
				return 0;
			}
			//break;
			//			strncpy((char*) lParam,ButtonX::fromHWND(hwnd)->_text , wParam);
			strncpy((char*) lParam,ButtonX::fromHWND(hwnd)->_text , wParam);
			return min(ButtonX::fromHWND(hwnd)->_text.length(), wParam-1);
		case WM_GETTEXTLENGTH:
			if (ButtonX::fromHWND(hwnd)->_duringPaint) return 0;
			//break;
			return ButtonX::fromHWND(hwnd)->_text.length();

		case WM_PAINT: {
			ButtonX * bt = ButtonX::fromHWND(hwnd);
			//if (!bt->_icon) break; // standardowa obs³uga...
			//int r = 1;
			HRGN hrgn=CreateRectRgn(0, 0, 0, 0);
			bt->_duringPaint=true;
			GetUpdateRgn(hwnd, hrgn, false);
			int r = 1;
			if (!bt->isFlat()) {
				r = CallWindowProc(ButtonX::buttonClassProc, hwnd, message, wParam, lParam);
			}
			InvalidateRgn(hwnd, hrgn, false);

			PAINTSTRUCT ps;
			HDC hdc;
			hdc = BeginPaint(hwnd, &ps);
			if (bt->isFlat()) {
				FillRgn(hdc, hrgn, GetSysColorBrush(COLOR_BTNFACE));
			}
			RECT rc = {0,0,0,0};
			bt->drawCaption(hdc, rc);
			EndPaint(hwnd, &ps);
			bt->_duringPaint=false;
			DeleteObject(hrgn);
			return r;}
		case WM_ENABLE: case WM_UPDATEUISTATE: {
			int r = CallWindowProc(ButtonX::buttonClassProc, hwnd, message, wParam, lParam);
			repaintWindow(hwnd);
			return r;}
		case WM_ERASEBKGND:
			return 0;

		case WM_SETFOCUS:
		//case BM_SETSTYLE:
		case BM_SETSTATE:
			// specjalnie dla W98
			repaintWindow(hwnd);
			break;

		case WM_SETCURSOR:
			if (fromHWND(hwnd)->isFlat()) {
				SetCursor( LoadCursor(0, IDC_HAND) );
				return true;
			}
			break;

#ifndef STAMINA_KISS
		case WM_LBUTTONDOWN: {
			ButtonX* b = fromHWND(hwnd);
			S_ASSERT(b);
			b->_pressed = true;
			b->evtMouseDown(b, wParam);
			break;}
		case WM_LBUTTONUP: {
			ButtonX* b = fromHWND(hwnd);
			S_ASSERT(b);
			if (b->_pressed) {
				b->evtMouseUp(b, wParam);
				if (getClientRect(hwnd).contains(Point::fromLParam(lParam))) {
					b->evtClick(b);
				}
			}
			b->_pressed = false;
			break;}
		case WM_LBUTTONDBLCLK: {
			//SendMessage(hwnd, BM_CLICK, 0, 0);
			ButtonX* b = fromHWND(hwnd);
			S_ASSERT(b);
			b->evtMouseDown(b, wParam);
			b->evtMouseUp(b, wParam);
			b->evtClick(b);
			break;}
		case WM_MOUSELEAVE:
			//fromHWND(hwnd)->_pressed = false;
			break;
		case WM_MOUSEMOVE:
			_tipTarget->attachButton(fromHWND(hwnd));
			ToolTipX::mouseMovement(GetParent(hwnd));
			//if (wParam == MK_LBUTTON) {
			//	fromHWND(hwnd)->_pressed = true;
			//}
			break;

#endif

		case WM_DESTROY:
			delete ButtonX::fromHWND(hwnd);
			break;

		};

		return CallWindowProc(ButtonX::buttonClassProc, hwnd, message, wParam, lParam);
	}
示例#21
0
void
TeamsWindow::UpdateMemoryImage(
     void
) {
     PaintRealWindow          prw(Handle());
     PaintCompatibleWindow    pcw_client(prw.DC());
     PaintCompatibleWindow    pcw_car(prw.DC());
     HPALETTE                 hOldPalette;
     HPALETTE                 hOldPalette2;
     Cursor                   cursor(IDC_WAIT);
     unsigned short           usX;
     unsigned short           usY;
     unsigned short           usTmpX;
     unsigned short           usTmpY;
     unsigned short           usTeamIndex;
     unsigned short           i;

     cursor.Select();
     {
          hOldPalette = SelectPalette(pcw_client.DC(), hPalette, FALSE);
          hOldPalette2 = SelectPalette(pcw_car.DC(), hPalette, FALSE);

          ASSERT(pClientBitmap != NULL);
          pcw_client.SelectBitmap(pClientBitmap);
          ASSERT(pF1CarSmallBitmap != NULL);
          pcw_car.SelectBitmap(pF1CarSmallBitmap);
          {
               RECT           rRect;
               SolidBrush     GrayBrush(RGB(192,192,192));

               rRect.left    = 0;
               rRect.right   = usClientWidth;
               rRect.top     = 0;
               rRect.bottom  = usClientHeight;
               pcw_client.FillRect(&rRect, &GrayBrush);

               usTeamIndex = 0;
               for (usY = 0; usY < TEAMS_NUM_Y; usY++) {
                    for (usX = 0; usX < TEAMS_NUM_X; usX++) {
                         usTmpX = (usX % TEAMS_NUM_X) * usMiniCarWidth;
                         usTmpY = (usY % TEAMS_NUM_Y) * usMiniCarHeight;

                         for (i = 0; i < NUM_ELEMENTS(car_regions); i++) {
                              (void) SelectObject(pcw_car.DC(), car_regions[i].hRgn);
                              SolidBrush  brush(PALETTEINDEX(team_colours[usTeamIndex].usRegionColour[i]));

                              (void) FillRgn(pcw_car.DC(), car_regions[i].hRgn, (HBRUSH) brush.Handle());
                         }

                         BitBlt(   pcw_client.DC(),
                                   usTmpX, usTmpY,
                                   pF1CarSmallBitmap->Width(), pF1CarSmallBitmap->Height(),
                                   pcw_car.DC(),
                                   0, 0,
                                   SRCCOPY
                              );

                         (void) FrameTeam(&pcw_client, usTeamIndex, usTeamIndex == usSelectedTeam);
                         ++usTeamIndex;
                    }
               }
          }
          pcw_client.DeselectBitmap();
          pcw_car.DeselectBitmap();
          (void) SelectPalette(pcw_client.DC(), hOldPalette, FALSE);
          (void) SelectPalette(pcw_car.DC(), hOldPalette2, FALSE);
     }
     cursor.Deselect();

     RepaintWindow();
}
示例#22
0
static LRESULT CALLBACK
MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    CvWindow* window = icvWindowByHWND( hwnd );
    if( !window )
        return DefWindowProc(hwnd, uMsg, wParam, lParam);

    switch(uMsg)
    {
    case WM_DESTROY:

        icvRemoveWindow(window);
        // Do nothing!!!
        //PostQuitMessage(0);
        break;

    case WM_GETMINMAXINFO:
        if( !(window->flags & CV_WINDOW_AUTOSIZE) )
        {
            MINMAXINFO* minmax = (MINMAXINFO*)lParam;
            RECT rect;
            LRESULT retval = DefWindowProc(hwnd, uMsg, wParam, lParam);

            minmax->ptMinTrackSize.y = 100;
            minmax->ptMinTrackSize.x = 100;

            if( window->toolbar.first )
            {
                GetWindowRect( window->toolbar.first->hwnd, &rect );
                minmax->ptMinTrackSize.y += window->toolbar.rows*(rect.bottom - rect.top);
                minmax->ptMinTrackSize.x = MAX(rect.right - rect.left + HG_BUDDY_WIDTH, HG_BUDDY_WIDTH*2);
            }
            return retval;
        }
        break;

    case WM_WINDOWPOSCHANGED:
        {
            WINDOWPOS* pos = (WINDOWPOS*)lParam;

            // Update the toolbar position/size
            if(window->toolbar.toolbar)
            {
                RECT rect;
                GetWindowRect(window->toolbar.toolbar, &rect);
                MoveWindow(window->toolbar.toolbar, 0, 0, pos->cx, rect.bottom - rect.top, TRUE);
            }

            if(!(window->flags & CV_WINDOW_AUTOSIZE))
                icvUpdateWindowPos(window);

            break;
        }

    case WM_ACTIVATE:
        if(LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE)
            SetFocus(window->hwnd);
        break;

    case WM_ERASEBKGND:
        {
            RECT cr, tr, wrc;
            HRGN rgn, rgn1, rgn2;
            int ret;
            HDC hdc = (HDC)wParam;
            GetWindowRect(window->hwnd, &cr);
            icvScreenToClient(window->frame, &cr);
            if(window->toolbar.toolbar)
            {
                GetWindowRect(window->toolbar.toolbar, &tr);
                icvScreenToClient(window->frame, &tr);
            }
            else
                tr.left = tr.top = tr.right = tr.bottom = 0;

            GetClientRect(window->frame, &wrc);

            rgn = CreateRectRgn(0, 0, wrc.right, wrc.bottom);
            rgn1 = CreateRectRgn(cr.left, cr.top, cr.right, cr.bottom);
            rgn2 = CreateRectRgn(tr.left, tr.top, tr.right, tr.bottom);
            ret = CombineRgn(rgn, rgn, rgn1, RGN_DIFF);
            ret = CombineRgn(rgn, rgn, rgn2, RGN_DIFF);

            if(ret != NULLREGION && ret != ERROR)
                FillRgn(hdc, rgn, (HBRUSH)icvGetClassLongPtr(hwnd, CV_HBRBACKGROUND));

            DeleteObject(rgn);
            DeleteObject(rgn1);
            DeleteObject(rgn2);
        }
        return 1;
    }

    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
示例#23
0
void CardWindow::PaintCardRgn(HDC hdc, int dx, int dy, int width, int height, int sx, int sy)
{
    RECT rect;

    //if just a solid background colour
    if(hbmBackImage == 0)
    {
        SetRect(&rect, dx, dy, dx+width, dy+height);

        /*if(GetVersion() < 0x80000000)
        {
            PaintRect(hdc, &rect, MAKE_PALETTERGB(crBackgnd));
        }
        else*/
        {
            HBRUSH hbr = CreateSolidBrush(MAKE_PALETTERGB(crBackgnd));
            FillRect(hdc, &rect, hbr);
            DeleteObject(hbr);
        }
    }
    //otherwise, paint using the bitmap
    else
    {
        // Draw whatever part of background we can
        BitBlt(hdc, dx, dy, width, height, hdcBackImage, sx, sy, SRCCOPY);

        // Now we need to paint any area outside the bitmap,
        // just in case the bitmap is too small to fill whole window
        if(0)//sx + width > bm.bmWidth || sy + height > bm.bmHeight)
        {
            // Find out size of bitmap
            BITMAP bm;
            GetObject(hbmBackImage, sizeof(bm), &bm);

            HRGN hr1 = CreateRectRgn(sx, sy, sx+width, sy+height);
            HRGN hr2 = CreateRectRgn(0, 0, bm.bmWidth, bm.bmHeight);
            HRGN hr3 = CreateRectRgn(0,0, 1, 1);
            HRGN hr4 = CreateRectRgn(0,0, 1, 1);

            CombineRgn(hr3, hr1, hr2, RGN_DIFF);

            GetClipRgn(hdc, hr4);

            CombineRgn(hr3, hr4, hr3, RGN_AND);
            SelectClipRgn(hdc, hr3);

            // Fill remaining space not filled with bitmap
            HBRUSH hbr = CreateSolidBrush(crBackgnd);
            FillRgn(hdc, hr3, hbr);
            DeleteObject(hbr);

            // Clean up
            SelectClipRgn(hdc, hr4);

            DeleteObject(hr1);
            DeleteObject(hr2);
            DeleteObject(hr3);
            DeleteObject(hr4);
        }
    }
}
示例#24
0
LRESULT CALLBACK _export BalloonProc(HWND hwnd, UINT message, WPARAM wParam,
                                     LPARAM lParam)
{
static DWORD lasttime;  // ??? should be a property
static POINT ttpos;
  RECT rect;
  POINT point;
  int x, y, width, height;
  SIZE size;
  LPSTR ptr;
  char text[256];

  switch (message) {
  case WM_CREATE: {
    HFONT hfont = CreateFont(-11, 0, 0, 0, FW_NORMAL, FALSE, 0, 0, DEFAULT_CHARSET,
                             OUT_DEFAULT_PRECIS, CLIP_CHARACTER_PRECIS,
                             PROOF_QUALITY, FF_DONTCARE, "MS Sans Serif");
    SetProp(hwnd,MAKEINTRESOURCE(atomFont),hfont);
    break;
  } /* case */

  case WM_DESTROY: {
    HFONT hfont = (HFONT)GetProp(hwnd,MAKEINTRESOURCE(atomFont));
    if (hfont)
      DeleteObject(hfont);
    RemoveProp(hwnd,MAKEINTRESOURCE(atomAlignStyle));
    RemoveProp(hwnd,MAKEINTRESOURCE(atomTailSize));
    RemoveProp(hwnd,MAKEINTRESOURCE(atomTimeout));
    RemoveProp(hwnd,MAKEINTRESOURCE(atomFont));
    break;
  } /* case */

  case WM_ERASEBKGND:
    return 0L;

  case WM_LBUTTONDOWN:
  case WM_RBUTTONDOWN:
  case WM_LBUTTONUP:
  case WM_RBUTTONUP:
    ShowWindow(hwnd, SW_HIDE);
    if (IsWindow(GetParent(hwnd)))
      PostMessage(GetParent(hwnd), BAN_VISIBLE, (WPARAM)hwnd, 0L);
    break;

  case WM_WINDOWPOSCHANGING:
  case WM_WINDOWPOSCHANGED:
    return 0L;

  case WM_PAINT: {
    PAINTSTRUCT ps;
    COLORREF clrBackgr;
    HBRUSH hbrBackgr;
    HRGN hrgn;
    int AlignStyle=(int)GetProp(hwnd,MAKEINTRESOURCE(atomAlignStyle));
    HFONT hfont = (HFONT)GetProp(hwnd,MAKEINTRESOURCE(atomFont));

    HDC hdc = BeginPaint(hwnd, &ps);
    GetClientRect(hwnd, &rect);

    clrBackgr=GetNearestColor(hdc, RGB(255,255,192));
    hbrBackgr = CreateSolidBrush(clrBackgr);
    #if defined __WIN32__
      hrgn=CreateRectRgn(0,0,1,1);
      GetWindowRgn(hwnd,hrgn);      /* Win32-only */
    #else
      #if BM_RADIUS==0
        hrgn=CreateRectRgn(rect.left, rect.top, rect.right, rect.bottom);
      #else
        hrgn=CreateRoundRectRgn(rect.left, rect.top, rect.right, rect.bottom, BM_RADIUS, BM_RADIUS);
      #endif
    #endif
    FillRgn(hdc,hrgn,hbrBackgr);
    FrameRgn(hdc,hrgn,GetStockObject(BLACK_BRUSH),1,1);
    DeleteObject(hbrBackgr);

    hfont = SelectObject(hdc, hfont);
    GetWindowText(hwnd, text, sizeof text);
    GetTextExtentPoint(hdc, text, lstrlen(text), &size);
    SetBkMode(hdc, TRANSPARENT);
    y=BM_MARGINTOP;
    if (AlignStyle==BAA_TOP) {
      int TailSize=(int)GetProp(hwnd,MAKEINTRESOURCE(atomTailSize));
      y+=TailSize;
    } /* if */
    for (ptr=strtok(text,"\n"); ptr!=NULL; ptr=strtok(NULL,"\n"), y+=size.cy) {
      GetTextExtentPoint(hdc, ptr, lstrlen(ptr), &size);
      x = ((rect.right-rect.left) - size.cx) / 2;
      TextOut(hdc, x, y, ptr, lstrlen(ptr));
    } /* for */
    SelectObject(hdc, hfont);

    EndPaint(hwnd, &ps);
    break;
  } /* case */

  case WM_TIMER: {
    DWORD timeout=(DWORD)GetProp(hwnd,MAKEINTRESOURCE(atomTimeout));
    DWORD curtime=GetTickCount();
    GetCursorPos(&point);
    if (timeout==0)
      break;
    if (curtime >= lasttime+timeout)
      SendMessage(hwnd, BAM_SHOW, 0, 0L);
    break;
  } /* if */

  case BAM_SETPOS:
    ttpos=*(LPPOINT)lParam;
    break;

  case BAM_SHOW:
    if (wParam) {
      HDC hdc;
      HRGN hrgn;
      int AlignStyle=(int)GetProp(hwnd,MAKEINTRESOURCE(atomAlignStyle));
      int TailSize=(int)GetProp(hwnd,MAKEINTRESOURCE(atomTailSize));
      HFONT hfont=(HFONT)GetProp(hwnd,MAKEINTRESOURCE(atomFont));
      ASSERT(lParam!=0);
      lstrcpy(text, (LPSTR)lParam);
      SetWindowText(hwnd, text);
      InvalidateRect(hwnd, NULL, FALSE);
      hdc = GetDC(hwnd);
      hfont = SelectObject(hdc, hfont);
      for (ptr=strtok(text,"\n"), width=height=0; ptr!=NULL; ptr=strtok(NULL,"\n")) {
        GetTextExtentPoint(hdc, ptr, lstrlen(ptr), &size);
        width = max(width, size.cx);
        height += size.cy;
      } /* for */
      SelectObject(hdc, hfont);
      ReleaseDC(hwnd, hdc);
      width += 2*BM_MARGINX;
      height += BM_MARGINTOP + BM_MARGINBOTTOM;
      #if 0
        // round width up to multiple of 16 pixels and height up to a multiple
        // of 8 pixels
        width+=16-1;
        width=width - (width%16);
        height+=8-1;
        height=height - (height%8);
      #endif
      // also add the tail size to the height
      height+=TailSize;
      // check alignment
      switch (AlignStyle) {
      case BAA_TOP:
        x = ttpos.x - width/4;
        y = ttpos.y;
        break;
      case BAA_BOTTOM:
        x = ttpos.x - width/4;
        y = ttpos.y - height;
        break;
      } /* switch */
      // check screen position against the screen size (width)
      if (x < 0)
        x = 0;
      else if (x+width >= GetSystemMetrics(SM_CXSCREEN)-1)
        x = GetSystemMetrics(SM_CXSCREEN) - width - 1;
      if (y < 0)
        y = 0;
      else if (y+height >= GetSystemMetrics(SM_CYSCREEN)-1)
        y = GetSystemMetrics(SM_CYSCREEN) - height - 1;
      GetWindowRect(hwnd,&rect);  // get first, check later (for new region)
      SetWindowPos(hwnd, HWND_TOPMOST, x, y, width, height, SWP_SHOWWINDOW|SWP_NOACTIVATE);
      hrgn=MakeBalloonRegion(width+1,height+1,BM_RADIUS,AlignStyle,TailSize,ttpos.x-x,ttpos.y-y);
      ASSERT(hrgn!=NULL);
      SetWindowRgn(hwnd, hrgn, TRUE);
      UpdateWindow(hwnd);
      lasttime=GetTickCount();
    } else {
      ShowWindow(hwnd, SW_HIDE);
      lasttime=GetTickCount();
    } /* if */
    break;

  default:
    return DefWindowProc(hwnd, message, wParam, lParam);
  } /* switch */
  return 0L;
}
示例#25
0
FIBITMAP* CaptureScreen  (HDC hDC,SIZE size,HWND hCapture){
//HDC GetDC			(NULL)		entire desktp
//HDC GetDC			(HWND hWnd)	client area of the specified window. (may include artifacts)
//HDC GetWindowDC	(HWND hWnd)	entire window.
	FIBITMAP *dib = NULL;
	HBITMAP hBitmap;					// handles to device-dependent bitmaps
	HDC hScrDC, hMemDC;					// screen DC and memory DC

	// create a DC for the screen and create
	// a memory DC compatible to screen DC
	if(!(hScrDC=hDC)) hScrDC=GetDC(hCapture);
	hMemDC = CreateCompatibleDC(hScrDC);
	// create a bitmap compatible with the screen DC
	hBitmap = CreateCompatibleBitmap(hScrDC,size.cx,size.cy);
	// select new bitmap into memory DC
	SelectObject(hMemDC, hBitmap);

	if(hCapture && hDC){
		PrintWindow(hCapture,hMemDC,0);
	}else{// bitblt screen DC to memory DC
		BitBlt(hMemDC,0,0,size.cx,size.cy,hScrDC,0,0,CAPTUREBLT|SRCCOPY);
	}
	dib = FIP->FI_CreateDIBFromHBITMAP(hBitmap);

	//alpha channel from window is always wrong and sometimes even for desktop (Win7, no aero)
	//coz GDI do not draw all in alpha mode.
	//we have to create our own new alpha channel.
	bool bFixAlpha=true;
	bool bInvert=false;
	HBRUSH hBr=CreateSolidBrush(RGB(255,255,255));//Create a SolidBrush object for non transparent area
	HBITMAP hMask=CreateBitmap(size.cx,size.cy,1,1,NULL);// Create monochrome (1 bit) B+W mask bitmap.
	HDC hMaskDC=CreateCompatibleDC(0);
	SelectBitmap(hMaskDC,hMask);
	HRGN hRgn=CreateRectRgn(0,0,0,0);
	if(hCapture && GetWindowRgn(hCapture,hRgn)==ERROR){
		if((GetWindowLongPtr(hCapture,GWL_EXSTYLE)&WS_EX_LAYERED)){
			BYTE bAlpha=0;
			COLORREF crKey=0;//0x00bbggrr
			DWORD dwFlags=0;
			if(GetLayeredWindowAttributes(hCapture,&crKey,&bAlpha,&dwFlags)) {
				//per window transparency (like fading in a whole window).
				if((dwFlags&LWA_COLORKEY)){
					SetBkColor(hMemDC,crKey);
					BitBlt(hMaskDC,0,0,size.cx,size.cy,hMemDC,0,0,SRCCOPY);
					bInvert=true;
				}else if((dwFlags&LWA_ALPHA)){
					bFixAlpha=false;
				}
			}else{//per-pixel transparency (won't use the WM_PAINT)
				bFixAlpha=false;
			}
		}else{//not layered - fill the window region
			SetRectRgn(hRgn,0,0,size.cx,size.cy);
			FillRgn(hMaskDC,hRgn,hBr);
		}
	}else{
		if(!hCapture) SetRectRgn(hRgn,0,0,size.cx,size.cy);//client area only, no transparency
		FillRgn(hMaskDC,hRgn,hBr);
	}
	DeleteObject(hRgn);
	if(bFixAlpha){
		FIBITMAP* dibMask = FIP->FI_CreateDIBFromHBITMAP(hMask);
		if(bInvert) FIP->FI_Invert(dibMask);
		FIBITMAP* dib8 = FIP->FI_ConvertTo8Bits(dibMask);
		//copy the dib8 alpha mask to dib32 main bitmap
		FIP->FI_SetChannel(dib,dib8,FICC_ALPHA);
		FIP->FI_Unload(dibMask);
		FIP->FI_Unload(dib8);
	}
	DeleteDC(hMaskDC);
	DeleteObject(hMask);
	DeleteObject(hBr);
	//clean up
	DeleteDC(hMemDC);
	DeleteObject(hBitmap);
	if(!hDC) ReleaseDC(NULL, hScrDC);

	#ifdef _DEBUG
	switch (FIP->FI_GetImageType(dib)){
		case FIT_UNKNOWN:
			OutputDebugStringA("FIBITMAP Typ: FIT_UNKNOWN\r\n" );
			break;
		case FIT_BITMAP:
			OutputDebugStringA("FIBITMAP Typ: FIT_BITMAP\r\n" );
			break;
		case FIT_UINT16:
			OutputDebugStringA("FIBITMAP Typ: FIT_UINT16\r\n" );
			break;
		case FIT_INT16:
			OutputDebugStringA("FIBITMAP Typ: FIT_INT16\r\n" );
			break;
		case FIT_UINT32:
			OutputDebugStringA("FIBITMAP Typ: FIT_UINT32\r\n" );
			break;
		case FIT_INT32:
			OutputDebugStringA("FIBITMAP Typ: FIT_INT32\r\n" );
			break;
		case FIT_FLOAT:
			OutputDebugStringA("FIBITMAP Typ: FIT_FLOAT\r\n" );
			break;
		case FIT_DOUBLE:
			OutputDebugStringA("FIBITMAP Typ: FIT_DOUBLE\r\n" );
			break;
		case FIT_COMPLEX:
			OutputDebugStringA("FIBITMAP Typ: FIT_COMPLEX\r\n" );
			break;
		case FIT_RGB16:
			OutputDebugStringA("FIBITMAP Typ: FIT_RGB16\r\n" );
			break;
		case FIT_RGBA16:
			OutputDebugStringA("FIBITMAP Typ: FIT_RGBA16\r\n" );
			break;
		case FIT_RGBF:
			OutputDebugStringA("FIBITMAP Typ: FIT_RGBF\r\n" );
			break;
		case FIT_RGBAF:
			OutputDebugStringA("FIBITMAP Typ: FIT_RGBAF\r\n" );
			break;
		default:
			OutputDebugStringA("FIBITMAP Typ: non detectable image type (error)\r\n" );
			break;
	}
	BOOL inf = FIP->FI_IsTransparent(dib);
	OutputDebugStringA(inf ? "FIBITMAP Transparent: true\r\n" : "FIBITMAP Transparent: false\r\n");
	#endif

	return dib;
}
示例#26
0
static void _AniAva_RenderAvatar(ANIAVA_WINDOWINFO * dat, HDC hdcParent /* = NULL*/, RECT * rcInParent /* = NULL */ )
{
	if (dat->bPaused>0)	{	dat->bPended=TRUE;	return; 	}
	else dat->bPended=FALSE;
	
	if ( IMMEDIATE_DRAW && hdcParent == NULL ) return;
	GdiFlush();
#ifdef _DEBUG
	__AniAva_DebugRenderStrip();
#endif
	if (dat->bPlaying && IsWindowVisible(dat->hWindow))
	{
		POINT ptWnd={0};
		SIZE szWnd={dat->rcPos.right-dat->rcPos.left,dat->rcPos.bottom-dat->rcPos.top};
		BLENDFUNCTION bf={AC_SRC_OVER, 0,g_CluiData.bCurrentAlpha*dat->bAlpha/256, AC_SRC_ALPHA };
		POINT pt_from={0,0};
		HDC hDC_animation=GetDC(NULL);
		HDC copyFromDC;
		RECT clistRect;
		HDC tempDC=NULL;
		HBITMAP hBmp;
		HBITMAP hOldBmp;

		/*
		int x=bf.SourceConstantAlpha;
		x=(49152/(383-x))-129;
		x=min(x,255);	x=max(x,0);
		bf.SourceConstantAlpha=x;
		*/
		if ( AniAva.bFlags == 0 ) //simple and fastest method - no borders, round corners and etc. just copy
		{
			pt_from.x=dat->ptFromPoint.x+dat->currentFrame*dat->sizeAvatar.cx;
			pt_from.y=dat->ptFromPoint.y;
			copyFromDC=AniAva.hAniAvaDC;
		}
		else
		{
			// ... need to create additional hDC_animation
			HRGN hRgn=NULL;
			int cornerRadius= AniAva.cornerRadius;
			tempDC	= CreateCompatibleDC( NULL );
			hBmp	= ske_CreateDIB32( szWnd.cx, szWnd.cy );
			hOldBmp	= (HBITMAP)SelectObject(tempDC,hBmp);
			if ( AniAva.bFlags & AAO_ROUND_CORNERS )
			{
				if (!cornerRadius)  //auto radius
					cornerRadius = min(szWnd.cx, szWnd.cy )/5;
			}
			if ( AniAva.bFlags & AAO_HAS_BORDER )
			{
				// if has borders - create region (round corners) and fill it, remember internal as clipping
				HBRUSH hBrush = CreateSolidBrush( AniAva.borderColor );
				HBRUSH hOldBrush = (HBRUSH)SelectObject( tempDC, hBrush );
				HRGN rgnOutside = CreateRoundRectRgn( 0, 0, szWnd.cx+1, szWnd.cy+1, cornerRadius<<1, cornerRadius<<1);
				hRgn=CreateRoundRectRgn( 1, 1, szWnd.cx, szWnd.cy, cornerRadius<<1, cornerRadius<<1);
				CombineRgn( rgnOutside,rgnOutside,hRgn,RGN_DIFF);
				FillRgn( tempDC, rgnOutside, hBrush);
				ske_SetRgnOpaque( tempDC, rgnOutside, TRUE);
				SelectObject(tempDC, hOldBrush);
				DeleteObject(hBrush);
				DeleteObject(rgnOutside);
			} 
			else if ( cornerRadius > 0 )
			{
				// else create clipping area (round corners)
				hRgn=CreateRoundRectRgn(0, 0, szWnd.cx+1, szWnd.cy+1, cornerRadius<<1, cornerRadius<<1);
			}
			else
			{
				hRgn=CreateRectRgn(0, 0, szWnd.cx+1, szWnd.cy+1);
			}
			// select clip area
			if ( hRgn )
				ExtSelectClipRgn(tempDC, hRgn, RGN_AND);

			if ( AniAva.bFlags & AAO_OPAQUE)
			{
				// if back color - fill clipping area
				HBRUSH hBrush = CreateSolidBrush( AniAva.bkgColor );
				HBRUSH hOldBrush = (HBRUSH)SelectObject( tempDC, hBrush );
				FillRgn( tempDC, hRgn, hBrush );
				ske_SetRgnOpaque( tempDC, hRgn, TRUE );
			}
			// draw avatar
			if ( !(AniAva.bFlags & AAO_OPAQUE) )
				BitBlt(tempDC,0, 0, szWnd.cx, szWnd.cy , AniAva.hAniAvaDC , dat->ptFromPoint.x+dat->sizeAvatar.cx*dat->currentFrame, dat->ptFromPoint.y, SRCCOPY);
			else
			{
				BLENDFUNCTION abf={AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
				ske_AlphaBlend(tempDC,0, 0, szWnd.cx, szWnd.cy , AniAva.hAniAvaDC, dat->ptFromPoint.x+dat->sizeAvatar.cx*dat->currentFrame, dat->ptFromPoint.y, szWnd.cx, szWnd.cy, abf);
			}
			// reset clip area
			if ( hRgn )
			{
				DeleteObject(hRgn);
				hRgn = CreateRectRgn(0, 0, szWnd.cx, szWnd.cy);
				SelectClipRgn(tempDC, hRgn);
				DeleteObject(hRgn);
			}

			if ( ( AniAva.bFlags & AAO_HAS_OVERLAY )
				  && ( dat->overlayIconIdx != -1 )
				  && ( AniAva.overlayIconImageList ) )
			{
				// if overlay - draw overlay icon
				// position - on avatar
				int x=szWnd.cx-ICON_WIDTH;
				int y=szWnd.cy-ICON_HEIGHT;
				ske_ImageList_DrawEx(AniAva.overlayIconImageList,
					dat->overlayIconIdx&0xFFFF,
					tempDC, x, y, ICON_WIDTH, ICON_HEIGHT,
					CLR_NONE, CLR_NONE, ILD_NORMAL);
			}
			copyFromDC=tempDC;
		}
		// intersect visible area
		// update layered window
		GetWindowRect(pcli->hwndContactTree, &clistRect);
		if (dat->rcPos.top<0)
		{
			pt_from.y+=-dat->rcPos.top;
			szWnd.cy+=dat->rcPos.top;
		}
		if (dat->rcPos.bottom>clistRect.bottom-clistRect.top)
		{
			szWnd.cy-=(dat->rcPos.bottom-(clistRect.bottom-clistRect.top));
		}
		ptWnd.x=dat->rcPos.left+clistRect.left;
		ptWnd.y=(dat->rcPos.top>0 ? dat->rcPos.top :0)+clistRect.top;
		if (szWnd.cy>0)
		{
			if ( hdcParent && rcInParent && IMMEDIATE_DRAW )
			{
				if ( AniAva.bFlags & AAO_OPAQUE )
					BitBlt( hdcParent, rcInParent->left, rcInParent->top, szWnd.cx, szWnd.cy, copyFromDC, pt_from.x, pt_from.y, SRCCOPY);
				else
				{
					BLENDFUNCTION abf={AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
					ske_AlphaBlend( hdcParent, rcInParent->left, rcInParent->top, szWnd.cx, szWnd.cy, copyFromDC, pt_from.x, pt_from.y, szWnd.cx, szWnd.cy, abf);
				}
			}
			else if (!g_proc_UpdateLayeredWindow(dat->hWindow, hDC_animation, &ptWnd, &szWnd, copyFromDC, &pt_from, RGB(0,0,0), &bf, ULW_ALPHA ))
			{
				LONG exStyle;
				exStyle=GetWindowLong(dat->hWindow,GWL_EXSTYLE);
				exStyle|=WS_EX_LAYERED;
				SetWindowLong(dat->hWindow,GWL_EXSTYLE,exStyle);
				if ( !IMMEDIATE_DRAW )
					SetWindowPos( pcli->hwndContactTree, dat->hWindow, 0, 0, 0, 0, SWP_ASYNCWINDOWPOS | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOSENDCHANGING );
				g_proc_UpdateLayeredWindow(dat->hWindow, hDC_animation, &ptWnd, &szWnd, copyFromDC, &pt_from, RGB(0,0,0), &bf, ULW_ALPHA );
			}

			g_CluiData.fAeroGlass = false;
			CLUI_UpdateAeroGlass();
		}
		else
		{
			dat->bPlaying=FALSE;
		}
		ReleaseDC(NULL,hDC_animation);
		if (tempDC)
		{
			SelectObject(tempDC, hOldBmp);
			DeleteObject(hBmp);
			DeleteDC(tempDC);
		}
	}
	if (!dat->bPlaying)
	{
		ShowWindow(dat->hWindow, SW_HIDE);
		KillTimer(dat->hWindow,2);  //stop animation till set pos will be called
	}
	GdiFlush();
}
示例#27
0
//рисуем картину приложения
void LinePicture(HWND hwnd, int Context)
{
//выбираем нужный контектс устройства для экрана
//---------------------------------------------
	HDC hdcWin;
	PAINTSTRUCT ps;
	//получаем контест устройства для экрана
	if(Context == 1)
		hdcWin = BeginPaint(hwnd, &ps);
	else
		hdcWin = GetDC(hwnd);
//-----------------------------------------------


//связываем размеры поля вывода с размерами клиентской области окна
//--------------------------------------------------------------------
	RECT rct;
	GetClientRect(hwnd,&rct);

	ne1 = rct.left+50; ne2 = rct.right -50;
	me1 = rct.bottom -50; me2 = rct.top + 50;
//------------------------------------------------------------------

//создаем контекст экрана
//------------------------------------------------------------
	HDC hdc = CreateCompatibleDC(hdcWin); //создаем контекст
                     //памяти связаный с контекстом экрана

   //памяти надо придать вид экрана - подходт битовая карта с форматом
   // как у экрана. В памяти будем рисовать на битовой карте
	HBITMAP hBitmap, hBitmapOld;
	hBitmap = CreateCompatibleBitmap(hdcWin, ne2, me1); //создаем
               //битовую карту совместмую с контекстом экрана
	hBitmapOld = (HBITMAP)SelectObject(hdc, hBitmap); //помещаем
                // битовую карту в контекст памяти
//--------------------------------------------------------------
	

//выводи значения углов в верхней части поля вывода
//--------------------------------------------------------	
	//создание прямоугольной области для вывода углов поворота
	HRGN hrgn2 = CreateRectRgn(ne1,me2-30,ne2,me1);

	//заливаем выделенную область серым цветом
	HBRUSH hBrush2 = CreateSolidBrush(RGB(0x80,0x80,0x80));
	HBRUSH hBrushOld = (HBRUSH)SelectObject(hdc,hBrush2); 
    FillRgn(hdc,hrgn2,hBrush2);

	SelectObject(hdc,hBrushOld);   
	DeleteObject(hBrush2);         
	DeleteObject(hrgn2);         

	
	//вычисление угловых коэффициентов поворота системы координат
	sf=sin(M_PI*angl.fi/180);
	cf=cos(M_PI*angl.fi/180);
	st=sin(M_PI*angl.teta/180);
	ct=cos(M_PI*angl.teta/180);


	//информация об углах поворота системы координат
	TCHAR ss[20];
	SetBkColor(hdc,RGB(0xC0,0xC0,0xC0));
	SetTextColor(hdc,RGB(0,0,0x80));
	swprintf_s(ss,20,L"fi = %4.0lf",angl.fi);
	TextOut(hdc,(ne1+ne2)/2-80,me2-25,ss,9);
	swprintf_s(ss,20,L"teta = %4.0lf",angl.teta);
	TextOut(hdc,(ne1+ne2)/2+20,me2-25,ss,11);
//------------------------------------------------

	
	


//выделение памяти под Z-буфер и начальное его заполнение
//-------------------------------------------------------------
	//вычисляем число пикселей в поле  вывода
	Np = ne2-ne1 + 1, Mp = me1-me2 +1, NM = Np*Mp;

	//выделяем память под Z-буфер для каждого пикселя
	zb = new ZbuffS [NM];

	//начальное заполнение z-буфера для каждого пикселя
	for ( long unsigned p=0; p<NM; p++)
	{
   		zb[p].z = -1000;
   		zb[p].c.R = 0xC0; zb[p].c.G = 0xC0; zb[p].c.B = 0xC0;
	}
//-----------------------------------------------------------

	

//"рисуем" магнитную пластинку заданным цветом заполняя Z-буфер	
//-----------------------------------------------------------------------
	//мировые координаты проецируемой точки
	double xt1,yt1,zt1;
	//видовые координаты проецируемой точки
	double xe,ye,ze1;
	//пиксельные координаты проецируемой точки
	int x1,y1;

	//пиксельные координаты 4-х углов пластинки
	int xp[4], yp[4];
	//видовые z-координаты 4-х углов пластинки
	double ze[4];

	for(int n=0; n<4; n++)
	{
		xt1 = Px[n]; yt1 = Py[n]; zt1 = Pz[n];
		xe = Xe(xt1, yt1, zt1);
		ye=Ye(xt1,yt1,zt1);
		ze1=Ze(xt1,yt1,zt1);
		x1=xn(xe);
		y1=ym(ye);
		xp[n] = x1; yp[n] = y1; ze[n] = ze1;
	}	
	//ZbufParallelogram(hdc,xp[0],yp[0],ze[0],xp[1],yp[1],ze[1],
		//xp[2],yp[2],ze[2],xp[3],yp[3],ze[3],RGB(255,255,0));
//------------------------------------------------------------------



//"рисуем" линии поля заполняя Z-буфер
//----------------------------------------------------------------
	for (int i = 0; i < 20; i++)
	{
		LineField(hdc,PointB[i],RGB(255,0,0),1);
		
	}
	
	for(int i=20; i<40; i++)
	{
		LineField(hdc,PointB[i],RGB(0,0,255), 1);
		
	}

	for (int i = 40; i<60; i++)
	{
		LineField(hdc, PointB[i], RGB(0, 255,0), 1);

	}
	
//-----------------------------------------------------------------------


//выводим содержимое Z-буфера в контекст памяти
//--------------------------------------------------------------------
	//двигаемся по всем пикселям окна вывода
	for (unsigned long ij=0; ij<NM; ij++)
	{
   		x1 = ne1 + ij%Np;
		y1 = me2 + ij/Np;
		SetPixel(hdc,x1,y1,RGB(zb[ij].c.R,zb[ij].c.G,zb[ij].c.B));

	}

	delete [] zb; //очищаем память под Z-буфером
//-------------------------------------------------------------



//рисуем координтные оси
//------------------------------------------------------------------------

	HPEN hPen = CreatePen(PS_SOLID,1,RGB(0,255,255));
	HPEN hPenOld = (HPEN)SelectObject(hdc,hPen);    
	
	int x2,y2;

//ось Ox
	xe=Xe(-xmax/3,0,0);
	ye=Ye(-xmax/3,0,0);
	x1=xn(xe);
	y1=ym(ye);
	xe=Xe(xmax,0,0);
	ye=Ye(xmax,0,0);
	x2=xn(xe);
	y2=ym(ye);
	
	MoveToEx(hdc,x1,y1,NULL);
	LineTo(hdc,x2,y2);

	SetBkColor(hdc,RGB(0xC0,0xC0,0xC0));
	SetTextColor(hdc,RGB(120,120,120));
	TextOut(hdc,x2, y2, _T("X"),1);

//Ось Oy
	xe=Xe(0,-ymax/3, 0);
	ye=Ye(0,-ymax/3,0);
	x1=xn(xe);
	y1=ym(ye);
	xe=Xe(0,ymax, 0);
	ye=Ye(0,ymax,0);
	x2=xn(xe);
	y2=ym(ye);
	
	MoveToEx(hdc,x1,y1,NULL);
	LineTo(hdc,x2,y2);

	SetBkColor(hdc,RGB(0xC0,0xC0,0xC0));
	SetTextColor(hdc,RGB(120,120,120));
	TextOut(hdc,x2, y2, _T("Y"),1);

//Ось Oz
	xe=Xe(0,0, 0);
	ye=Ye(0,0,-zmax/3);
	x1=xn(xe);
	y1=ym(ye);
	xe=Xe(0,0, 0);
	ye=Ye(0,0,zmax);
	x2=xn(xe);
	y2=ym(ye);

	MoveToEx(hdc,x1,y1,NULL);
	LineTo(hdc,x2,y2);

	SetBkColor(hdc,RGB(0xC0,0xC0,0xC0));
	SetTextColor(hdc,RGB(120,120,120));
	TextOut(hdc,x2, y2, _T("Z"),1);


	SelectObject(hdc,hPenOld); 
	DeleteObject(hPen);        
//-----------------------------------------------------------------------------


//рисуем куб
//----------------------------------------------------------------------
	hPen = CreatePen(PS_SOLID,1,RGB(160,160,160));
	hPenOld = (HPEN)SelectObject(hdc,hPen);    

	DrawBox(hwnd, hdc, angl);

	SelectObject(hdc,hPenOld); 
	DeleteObject(hPen);        
//------------------------------------------------------------------------


//копируем контекст памяти в контекст экрана
//-----------------------------------------------------------------------	
	BitBlt(hdcWin,ne1,me2-30,ne2,me1,hdc,ne1,me2-30,SRCCOPY); 
//----------------------------------------------------------------------


//завершаем работу с контекстами и памятью
//-------------------------------------------------------------------
	SelectObject(hdc, hBitmapOld); //востанавливаем контекст памяти
	DeleteObject(hBitmap); //убираем битовую карту
	DeleteDC(hdc);  //  освобождаем контекст памяти

	//освобождаем контекст экрана
	if(Context == 1)
		EndPaint(hwnd, &ps);
	else
		ReleaseDC(hwnd, hdcWin);   
}
示例#28
0
void CPianoCtrl::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CRect	cb;
	dc.GetClipBox(cb);
//printf("OnPaint cb %d %d %d %d\n", cb.left, cb.top, cb.right, cb.bottom);
	HFONT	hFont;
	if (m_Font != NULL)	// if user specified font
		hFont = m_Font;
	else	// font not specified
		hFont = m_KeyLabelFont;	// use auto-scaled font
	HGDIOBJ	hPrevFont = dc.SelectObject(hFont);
	DWORD	dwStyle = GetStyle();
	bool	ShowPressed = (dwStyle & PS_HIGHLIGHT_PRESS) != 0;
	UINT	nAlign;
	if (dwStyle & PS_VERTICAL) {	// if vertical orientation
		nAlign = TA_RIGHT | TA_TOP;
	} else {	// horizontal orientation
		if (dwStyle & PS_ROTATE_LABELS)	// if rotated labels
			nAlign = TA_LEFT | TA_TOP;
		else	// normal labels
			nAlign = TA_CENTER | TA_BOTTOM;
	}
	dc.SetTextAlign(nAlign);
	TEXTMETRIC	TextMetric;
	dc.GetTextMetrics(&TextMetric);
	dc.SetBkMode(TRANSPARENT);
	int	nKeys = GetKeyCount();
	for (int iKey = 0; iKey < nKeys; iKey++) {	// for each key
		CKey&	key = m_Key[iKey];
		if (key.m_Rgn.RectInRegion(cb)) {	// if key's region intersects clip box
			// fill key's region with appropriate brush for key color and state
			bool	IsPressed = key.m_IsPressed & ShowPressed;
			if ((dwStyle & PS_PER_KEY_COLORS) && key.m_Color >= 0) {
				SetDCBrushColor(dc, key.m_Color);
				FillRgn(dc, key.m_Rgn, (HBRUSH)GetStockObject(DC_BRUSH));
			} else	// default color scheme
				dc.FillRgn(&key.m_Rgn, &m_KeyBrush[key.m_IsBlack][IsPressed]);
			// outline key's region; this flickers slightly because it overlaps fill
			dc.FrameRgn(&key.m_Rgn, &m_OutlineBrush, OUTLINE_WIDTH, OUTLINE_WIDTH);
			if (iKey < m_KeyLabel.GetSize() && !m_KeyLabel[iKey].IsEmpty()) {
				COLORREF	TextColor;
				if (dwStyle & PS_PER_KEY_COLORS) {	// if per-key colors
					COLORREF	BkColor;
					int	BkMode = TRANSPARENT;
					if (key.m_Color >= 0) {	// if key has custom color
						// compute lightness, compensating for our sensitivity to green
						int	lightness = GetRValue(key.m_Color) 
							+ GetGValue(key.m_Color) * 2 + GetBValue(key.m_Color);
						if (lightness < 255 * 2)	// if lightness below threshold
							TextColor = RGB(255, 255, 255);	// white text
						else	// key is light enough
							TextColor = RGB(0, 0, 0);	// black text
						if (dwStyle & PS_INVERT_LABELS) {	// if inverting labels
							if (key.m_IsPressed) {	// if key pressed
								BkColor = TextColor;	// set background to text color
								TextColor ^= 0xffffff;	// invert text color
								BkMode = OPAQUE;
							} else	// key not pressed
								BkColor = key.m_Color;	// make background same as key
						} else	// not highlighting pressed keys
							BkColor = key.m_Color;	// make background same as key
					} else {	// default color scheme
						TextColor = m_KeyColor[!key.m_IsBlack][0];
						BkColor = m_KeyColor[key.m_IsBlack][key.m_IsPressed];
					}
					dc.SetBkColor(BkColor);	// set background color
					dc.SetBkMode(BkMode);	// set background mode
				} else	// default color scheme
					TextColor = m_KeyColor[!key.m_IsBlack][0];
				dc.SetTextColor(TextColor);	// set text color
				CRect	rKey;
				key.m_Rgn.GetRgnBox(rKey);
				CPoint	pt;
				if (dwStyle & PS_VERTICAL) {	// if vertical orientation
					pt.x = rKey.right - TextMetric.tmDescent * 2;
					pt.y = rKey.top + (rKey.Height() - TextMetric.tmHeight) / 2;
				} else {	// horizontal orientation
					if (dwStyle & PS_ROTATE_LABELS) {	// if vertical labels
						pt.x = rKey.left + (rKey.Width() - TextMetric.tmHeight) / 2;
						pt.y = rKey.bottom - TextMetric.tmDescent * 2;
					} else {	// horizontal labels
						pt.x = rKey.left + rKey.Width() / 2;
						pt.y = rKey.bottom - TextMetric.tmDescent;
					}
				}
				dc.TextOut(pt.x, pt.y, m_KeyLabel[iKey]);
			}
		}
	}
	dc.SelectObject(hPrevFont);
}
示例#29
0
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;
}
void mxExpressionSlider::DrawThumb( int barnum, HDC& dc )
{
	RECT rcThumb;

	GetThumbRect( barnum, rcThumb );

	// Draw it


	HPEN oldPen;

	HPEN shadow;
	HBRUSH face;
	HPEN hilight;

	shadow = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DDKSHADOW ) );
	hilight = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DHIGHLIGHT ) );
	
	switch ( barnum )
	{
	default:
	case MAGNITUDE_BAR:

		if ( m_flCurrent[ barnum ] != m_flMin[ barnum ] )
		{
			// float frac = ( m_flCurrent[ barnum ] - m_flMin[ barnum ] ) / (  m_flMax[ barnum ] - m_flMin[ barnum ] );
			float frac;
			if (m_flCurrent[ barnum ] < 0)
			{
				frac = m_flCurrent[ barnum ] / m_flMin[ barnum ];
			}
			else
			{
				frac = m_flCurrent[ barnum ] / m_flMax[ barnum ];
			}
			frac = min( 1.0f, frac );
			frac = max( 0.0f, frac );

			COLORREF clr = GetSysColor( COLOR_3DFACE );
			int r, g, b;
			r = GetRValue( clr );
			g = GetRValue( clr );
			b = GetRValue( clr );

			// boost colors
			r = (int)( (1-frac) * b );
			b = min( 255, (int)(r + ( 255 - r ) * frac ) );
			g = (int)( (1-frac) * g );

			face = CreateSolidBrush( RGB( r, g, b ) );
		}
		else
		{
			face = CreateSolidBrush( GetSysColor( COLOR_3DFACE ) );
		}
		break;
	case BALANCE_BAR:
		{
			float frac = ( m_flCurrent[ barnum ] - m_flMin[ barnum ] ) / (  m_flMax[ barnum ] - m_flMin[ barnum ] );
			frac = min( 1.0f, frac );
			frac = max( 0.0f, frac );

			COLORREF clr = GetSysColor( COLOR_3DFACE );
			int r, g, b;
			r = GetRValue( clr );
			g = GetRValue( clr );
			b = GetRValue( clr );

			// boost colors toward red if we are not at 0.5
			float boost = 2.0 * ( fabs( frac - 0.5f ) );

			r = r + ( 255 - r ) * boost;
			g = ( 1 - boost ) * g;
			b = ( 1 - boost ) * b;

			face = CreateSolidBrush( RGB( r, g, b ) );
		}
		break;
	}

	//rcThumb.left += 1;
	//rcThumb.right -= 1;
	//rcThumb.top += 1;
	//rcThumb.bottom -= 1;

	//FillRect( dc, &rcThumb, face );
	POINT region[3];
	int cPoints = 3;

	InflateRect( &rcThumb, -2, 0 );

//	int height = rcThumb.bottom - rcThumb.top;
//	int offset = height / 2 + 1;
	int offset = 2;

	switch ( barnum )
	{
	case MAGNITUDE_BAR:
	default:
		{
			region[ 0 ].x = rcThumb.left;
			region[ 0 ].y = rcThumb.top;
			
			region[ 1 ].x = rcThumb.right;
			region[ 1 ].y = rcThumb.top;
			
			region[ 2 ].x = ( rcThumb.left + rcThumb.right ) / 2;
			region[ 2 ].y = rcThumb.bottom - offset;
		}
		break;
	case BALANCE_BAR:
		{
			region[ 0 ].x = ( rcThumb.left + rcThumb.right ) / 2;
			region[ 0 ].y = rcThumb.top + offset;

			region[ 1 ].x = rcThumb.left;
			region[ 1 ].y = rcThumb.bottom;

			region[ 2 ].x = rcThumb.right;
			region[ 2 ].y = rcThumb.bottom;

		}
		break;
	}

	HRGN rgn = CreatePolygonRgn( region, cPoints, ALTERNATE );

	int oldPF = SetPolyFillMode( dc, ALTERNATE );
	FillRgn( dc, rgn, face );
	SetPolyFillMode( dc, oldPF );

	DeleteObject( rgn );

	oldPen = (HPEN)SelectObject( dc, hilight );

	MoveToEx( dc, region[0].x, region[0].y, NULL );
	LineTo( dc, region[1].x, region[1].y );
	SelectObject( dc, shadow );
	LineTo( dc, region[2].x, region[2].y );
	SelectObject( dc, hilight );
	LineTo( dc, region[0].x, region[0].y );

	SelectObject( dc, oldPen );

	DeleteObject( face );
	DeleteObject( shadow );
	DeleteObject( hilight );
}