Example #1
2
void DrawBitmap(HDC hdc, int x, int y, HBITMAP hBitmap)
{
	HBITMAP hOldbm;
	HDC hMemDC;
	BITMAP bm;
	POINT ptSize, ptOrg;

	hMemDC = CreateCompatibleDC(hdc);
	hOldbm = (HBITMAP)SelectObject(hMemDC, hBitmap);
	if (hOldbm)
	{
		SetMapMode(hMemDC, GetMapMode(hdc));
		GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
		ptSize.x = bm.bmWidth;
		ptSize.y = bm.bmHeight;

		DPtoLP(hdc, &ptSize, 1);

		ptOrg.x = 0;
		ptOrg.y = 0;

		DPtoLP(hMemDC, &ptOrg, 1);

		BitBlt(hdc, x, y, ptSize.x, ptSize.y, hMemDC, ptOrg.x, ptOrg.y, SRCCOPY);

		SelectObject(hMemDC, hOldbm);
	}

	DeleteDC(hMemDC);
}
Example #2
0
void BDRAW_TransparentBlt (HDC hdc, COLORREF clrTran)
    {
//
// Method #1 -- By Jeff Prosise
//
    HDC hdcImage, hdcAnd, hdcXor, hdcTemp ;
    HBITMAP htAnd, htXor, htTemp ;
    HBITMAP htOldImage, htOldAnd, htOldXor, htOldTemp ;
    int nImage, nAnd, nXor, nTemp ;

    hdcImage   = CreateCompatibleDC (hdc) ;
    htOldImage = (HBITMAP) SelectObject (hdcImage, BoardCfg.htTemp) ;
    nImage     = SetMapMode (hdcImage, GetMapMode (hdc)) ;

    hdcAnd = CreateCompatibleDC (hdc) ;
    nAnd   = SetMapMode (hdcAnd, GetMapMode (hdc)) ;
    htAnd  = CreateBitmap (BoardCfg.nss, BoardCfg.nss, 1, 1, NULL) ;
    htOldAnd = (HBITMAP) SelectObject (hdcAnd, htAnd) ;

    SetBkColor (hdcImage, clrTran) ;
    BitBlt (hdcAnd, 0, 0, BoardCfg.nss, BoardCfg.nss, hdcImage, 0, 0, SRCCOPY) ;

    hdcXor   = CreateCompatibleDC (hdc) ;
    nXor     = SetMapMode (hdcXor, GetMapMode (hdc)) ;
    htXor    = CreateCompatibleBitmap (hdcImage, BoardCfg.nss, BoardCfg.nss) ;
    htOldXor = (HBITMAP) SelectObject (hdcXor, htXor) ;

    BitBlt (hdcXor, 0, 0, BoardCfg.nss, BoardCfg.nss, hdcImage, 0, 0, SRCCOPY ) ;
    BitBlt (hdcXor, 0, 0, BoardCfg.nss, BoardCfg.nss, hdcAnd,   0, 0, 0x220326) ;

    hdcTemp   = CreateCompatibleDC (hdc) ;
    nTemp     = SetMapMode (hdcTemp, GetMapMode (hdc)) ;
    htTemp    = CreateCompatibleBitmap (hdcImage, BoardCfg.nss, BoardCfg.nss) ;
    htOldTemp = (HBITMAP) SelectObject (hdcTemp, htTemp) ;

    BitBlt (hdcTemp, 0, 0, BoardCfg.nss, BoardCfg.nss, hdc,     0, 0, SRCCOPY  ) ;
    BitBlt (hdcTemp, 0, 0, BoardCfg.nss, BoardCfg.nss, hdcAnd,  0, 0, SRCAND   ) ;
    BitBlt (hdcTemp, 0, 0, BoardCfg.nss, BoardCfg.nss, hdcXor,  0, 0, SRCINVERT) ;
    BitBlt (hdc,     0, 0, BoardCfg.nss, BoardCfg.nss, hdcTemp, 0, 0, SRCCOPY  ) ;

    SetMapMode (hdcTemp,  nTemp ) ;
    SetMapMode (hdcXor,   nXor  ) ;
    SetMapMode (hdcAnd,   nAnd  ) ;
    SetMapMode (hdcImage, nImage) ;

    SelectObject (hdcTemp,  htOldTemp ) ;
    SelectObject (hdcXor,   htOldXor  ) ;
    SelectObject (hdcAnd,   htOldAnd  ) ;
    SelectObject (hdcImage, htOldImage) ;

    DeleteObject (hdcTemp ) ;
    DeleteObject (hdcXor  ) ;
    DeleteObject (hdcAnd  ) ;
    DeleteObject (hdcImage) ;

    DeleteObject (htTemp ) ;
    DeleteObject (htXor  ) ;
    DeleteObject (htAnd  ) ;
    }
Example #3
0
void Test_CreateCompatibleDC()
{
	HDC hdcScreen, hOldDC, hdc, hdc2;
	HPEN hOldPen;
	COLORREF color;

	/* Get screen DC */
	hdcScreen = GetDC(NULL);

	/* Test NULL DC handle */
	SetLastError(ERROR_SUCCESS);
	hdc = CreateCompatibleDC(NULL);
	ok(hdc != NULL, "CreateCompatibleDC(NULL) failed\n");
	ok(GetLastError() == ERROR_SUCCESS, "GetLastError() == %ld\n", GetLastError());
	if(hdc) DeleteDC(hdc);

	/* Test invalid DC handle */
	SetLastError(ERROR_SUCCESS);
	hdc = CreateCompatibleDC((HDC)0x123456);
	ok(hdc == NULL, "Expected NULL, got %p\n", hdc);
	ok(GetLastError() == ERROR_SUCCESS, "GetLastError() == %ld\n", GetLastError());
	if(hdc) DeleteDC(hdc);

	hdc = CreateCompatibleDC(hdcScreen);
	ok(hdc != NULL, "CreateCompatibleDC failed\n");

	// Test if first selected pen is BLACK_PEN (? or same as screen DC's pen?)
	hOldPen = SelectObject(hdc, GetStockObject(DC_PEN));
	ok (hOldPen == GetStockObject(BLACK_PEN), "hOldPen == %p\n", hOldPen);
	hOldPen = SelectObject(hdc, GetStockObject(BLACK_PEN));
	ok (hOldPen == GetStockObject(DC_PEN), "hOldPen == %p\n", hOldPen);

	/* Test for the starting Color == RGB(0,0,0) */
	color = SetDCPenColor(hdc, RGB(1,2,3));
	ok(color == RGB(0,0,0), "color == %lx\n", color);

	/* Check for reuse counter */
	hOldDC = hdc;
	DeleteDC(hdc);
	hdc = CreateCompatibleDC(hdcScreen);
	hdc2 = CreateCompatibleDC(hOldDC);
	ok(hdc2 == NULL, "Expected NULL, got %p\n", hdc);
	if (hdc2 != NULL) DeleteDC(hdc2);

    /* Check map mode */
	hdc = CreateCompatibleDC(hdcScreen);
	SetMapMode(hdc, MM_ISOTROPIC);
	hdc2 = CreateCompatibleDC(hdc);
    ok(GetMapMode(hdc2) == MM_TEXT, "GetMapMode(hdc2)==%d\n", GetMapMode(hdc2));

	/* cleanup */
	DeleteDC(hdc);

	ReleaseDC(NULL, hdcScreen);
}
Example #4
0
/*	WinDrawBitmap must be used for drawing bitmaps on screen.
	For reasons of efficiency it uses memory device context, BitBlt, and bitmap handle.
*/
void WinDrawBitmap (int w, int h, int destx, int desty,
					HBITMAP hbmp, OSPictContext context
				   )
{
	HDC compatibleDC;
	POINT size, origin, dest;
	HGDIOBJ prevObj;

	size.x   = w;
	size.y   = h;
	origin.x = 0;
	origin.y = 0;
	dest.x   = destx;
	dest.y   = desty;

	//	Create a compatible device context
	compatibleDC = CreateCompatibleDC (context->hDC);
	if (compatibleDC == NULL)
		rMessageBox (NULL,MB_APPLMODAL,"WinDrawBitmap","CreateCompatibleDC failed");

	//	Select bitmap into compatible device context
	prevObj = SelectObject (compatibleDC, hbmp);
	SetMapMode (compatibleDC, GetMapMode (context->hDC));
	DPtoLP (context->hDC, &size, 1);
	DPtoLP (context->hDC, &dest, 1);
	DPtoLP (compatibleDC, &origin, 1);

	BitBlt (context->hDC, dest.x, dest.y, size.x, size.y, compatibleDC, origin.x, origin.y, SRCCOPY);

	SelectObject (compatibleDC, prevObj);
	DeleteDC (compatibleDC);
}	/* WinDrawBitmap */
Example #5
0
LRESULT CDataView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	DataReader<NumericT>::Init();
	
	CWindow wnd(GetDesktopWindow());
	HDC hDC = wnd.GetDC();
	int width = GetDeviceCaps(hDC, HORZRES) + 10;
	int height = GetDeviceCaps(hDC, VERTRES) + 10;
	wnd.ReleaseDC(hDC);
	// TopDown形式
	m_hBMP = CreateDIB32(width, -height, m_bmi, m_pBits);
	m_pImage = gl::BuildBuffer2DFromBMP(m_bmi.bmiHeader, m_pBits);

	HDC dc = GetDC();
	m_memDC.CreateCompatibleDC(dc);
	m_memDC.SetMapMode(GetMapMode(dc));
	ReleaseDC(dc);
	m_memDC.SelectBitmap(m_hBMP);
	
	gl::SetupSlopeCorrectionTable(g_slopeCorrTable, SLOPE_CORR_TABLE_SIZE);
	gl::SetupFilterTable(g_filterTable, FILTER_TABLE_SIZE, 0.75);
	
	m_pSrcSetting = std::shared_ptr<ProcessSetting>(new ProcessSetting);
	m_pDataSetting = std::shared_ptr<DataSetting1D>(new DataSetting1D);
	m_scale = 1.0;

	return 0;
}
Example #6
0
void KTraceEMF::CompareDC(HDC hDC)
{
	Compare(m_value[0],  GetMapMode(hDC),						"MapMode      : %d\r\n");
	Compare(m_value[1],  GetGraphicsMode(hDC),					"GraphicsMode : %d\r\n");
	
	XFORM xm;
	GetWorldTransform(hDC, & xm);
	Compare(m_float[0],  xm.eM11,								"WT.eM11      : %8.5f\r\n");
	Compare(m_float[1],  xm.eM12,								"WT.eM12      : %8.5f\r\n");
	Compare(m_float[2],  xm.eM21,								"WT.eM21      : %8.5f\r\n");
	Compare(m_float[3],  xm.eM22,								"WT.eM22      : %8.5f\r\n");
	Compare(m_float[4],  xm.eDx,								"WT.eDx       : %8.5f\r\n");
	Compare(m_float[5],  xm.eDy,								"WT.eDy       : %8.5f\r\n");

	Compare(m_value[2],  GetBkMode(hDC),						"BkMode       : %d\r\n");
	Compare(m_value[3],  GetROP2(hDC),							"ROP2         : %d\r\n");
	Compare(m_value[4],  ((int)GetTextAlign(hDC)),				"TextAlign    : 0x%x\r\n");

	Compare(m_object[0], GetCurrentObject(hDC, OBJ_PEN),		"Pen          : 0x%08x\r\n");
	Compare(m_object[1], GetCurrentObject(hDC, OBJ_BRUSH),		"Brush        : 0x%08x\r\n");
	Compare(m_object[2], GetCurrentObject(hDC, OBJ_FONT),		"Font         : 0x%08x\r\n");
	Compare(m_object[3], GetCurrentObject(hDC, OBJ_PAL),		"Palette      : 0x%08x\r\n");
	Compare(m_object[4], GetCurrentObject(hDC, OBJ_COLORSPACE),	"ColorSpace   : 0x%08x\r\n");
	Compare(m_object[5], GetCurrentObject(hDC, OBJ_BITMAP),		"Bitmap       : 0x%08x\r\n");
}
Example #7
0
static void DrawBitmap(HDC hdc, HBITMAP hBitmap, int x, int y, int rop) {
    BITMAP bm;
    HDC hdcMem;
    POINT ptSize, ptOrg;
    HBITMAP tmp;

    ASSERT(hdc != NULL);
    ASSERT(hBitmap != NULL);
    hdcMem = CreateCompatibleDC(hdc);
    ASSERT(hdcMem != NULL);
    CHECK_RETURN(tmp = SelectObject(hdcMem, hBitmap));

    SetMapMode(hdcMem, GetMapMode(hdc));
    GetObject(hBitmap, sizeof(BITMAP), (LPVOID)&bm);
    ptSize.x = bm.bmWidth;
    ptSize.y = bm.bmHeight;
    DPtoLP(hdc, &ptSize, 1);

    ptOrg.x = 0;
    ptOrg.y = 0;

    DPtoLP(hdcMem, &ptOrg, 1);

    BitBlt(hdc, x, y, ptSize.x, ptSize.y,
           hdcMem, ptOrg.x, ptOrg.y, rop);

    SelectObject(hdcMem, tmp);
    DeleteDC(hdcMem);
}
Example #8
0
// petzold, pp 621-622
void DrawBitmap(HDC hdc, HBITMAP hBitmap, int xStart, int yStart)
	{
	BITMAP bm;
	HDC hdcMem;
	POINT ptSize, ptOrg;

	hdcMem = CreateCompatibleDC(hdc);
	SelectObject(hdcMem, hBitmap);
	SetMapMode(hdcMem, GetMapMode(hdc));

	GetObject(hBitmap, sizeof(BITMAP), (LPSTR) &bm);

	ptSize.x = bm.bmWidth;
	ptSize.y = bm.bmHeight;
	DPtoLP(hdc, &ptSize, 1);

	ptOrg.x = 0;
	ptOrg.y = 0;
	DPtoLP(hdcMem, &ptOrg, 1);

	BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, ptOrg.x, ptOrg.y,
			SRCCOPY);

	DeleteDC(hdcMem);
	}
Example #9
0
void RedrawClientArea(HWND hWnd, HDC hDC)
{
   HDC     hDCMem;

   if (hBitmap)
   {
      GetBitmapPosition(hWnd);

      hDCMem = CreateCompatibleDC(hDC);

      SelectObject (hDCMem, hBitmap);
      SetMapMode (hDCMem, GetMapMode(hDC));

      if (hPalette)
      {
         SelectPalette(hDC, hPalette, FALSE);
         RealizePalette(hDC);
         SelectPalette(hDCMem, hPalette, FALSE);
         RealizePalette(hDCMem);
      }
      
      BitBlt(hDC, offset_x, offset_y, pbmi->bmiHeader.biWidth, pbmi->bmiHeader.biHeight,
             hDCMem, 0, 0, SRCCOPY);

      DeleteDC(hDCMem);
   }

   return;
}
Example #10
0
void SetHIMETRICtoDP(HDC hdc, SIZE* sz)
{
	POINT pt;
	int nMapMode = GetMapMode(hdc);
	if (nMapMode < MM_ISOTROPIC && nMapMode != MM_TEXT) {
		// when using a constrained map mode, map against physical inch
		SetMapMode(hdc, MM_HIMETRIC);
		pt.x = sz->cx;
		pt.y = sz->cy;
		LPtoDP(hdc, &pt, 1);
		sz->cx = pt.x;
		sz->cy = pt.y;
		SetMapMode(hdc, nMapMode);
	}
	else {
		// map against logical inch for non-constrained mapping modes
		int cxPerInch, cyPerInch;
		cxPerInch = GetDeviceCaps(hdc, LOGPIXELSX);
		cyPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
		sz->cx = MulDiv(sz->cx, cxPerInch, HIMETRIC_INCH);
		sz->cy = MulDiv(sz->cy, cyPerInch, HIMETRIC_INCH);
	}

	pt.x = sz->cx;
	pt.y = sz->cy;
	DPtoLP(hdc, &pt, 1);
	sz->cx = pt.x;
	sz->cy = pt.y;
}
Example #11
0
static void MaskRegion( HDC hdc, RECT * rct, COLORREF cTransparentColor,
                        COLORREF cBackgroundColor )

{
   HDC        hdcTemp, hdcObject, hdcBack, hdcMem;
   POINT      ptSize;
   COLORREF   cColor;
   HBITMAP    bmAndObject, bmAndBack, bmBackOld, bmObjectOld,
              bmAndTemp, bmTempOld, bmAndMem, bmMemOld;
   HBRUSH     hBrush, hBrOld;

   ptSize.x = rct->right - rct->left + 1;
   ptSize.y = rct->bottom - rct->top + 1;

   hBrush      = CreateSolidBrush(cBackgroundColor);

   hdcTemp     = CreateCompatibleDC(hdc);
   hdcObject   = CreateCompatibleDC(hdc);
   hdcBack     = CreateCompatibleDC(hdc);
   hdcMem      = CreateCompatibleDC(hdc);

   bmAndTemp   = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
   bmAndMem    = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
   bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
   bmAndBack   = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

   bmTempOld   = SelectObject(hdcTemp, bmAndTemp);
   bmMemOld    = SelectObject(hdcMem, bmAndMem);
   bmBackOld   = SelectObject(hdcBack, bmAndBack);
   bmObjectOld = SelectObject(hdcObject, bmAndObject);

   hBrOld      = SelectObject(hdcMem, hBrush);

   BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdc, rct->left, rct->top, SRCCOPY);

   SetMapMode(hdcTemp, GetMapMode(hdc));

   cColor = SetBkColor(hdcTemp, cTransparentColor);

   BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);

   SetBkColor(hdcTemp, cColor);

   BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, NOTSRCCOPY);
   PatBlt(hdcMem, 0,0, ptSize.x, ptSize.y, PATCOPY);
   BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);
   BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);
   BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);
   BitBlt(hdc, rct->left, rct->top, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY);

   DeleteObject(SelectObject(hdcMem, hBrOld));
   DeleteObject(SelectObject(hdcTemp, bmTempOld));
   DeleteObject(SelectObject(hdcMem, bmMemOld));
   DeleteObject(SelectObject(hdcBack, bmBackOld));
   DeleteObject(SelectObject(hdcObject, bmObjectOld));
   DeleteDC(hdcMem);
   DeleteDC(hdcBack);
   DeleteDC(hdcObject);
   DeleteDC(hdcTemp);
}
Example #12
0
void CDC::HIMETRICtoDP(LPSIZE lpSize) const
{
	ASSERT(AfxIsValidAddress(lpSize, sizeof(SIZE)));

	int nMapMode;
	if (this != NULL && (nMapMode = GetMapMode()) < MM_ISOTROPIC &&
		nMapMode != MM_TEXT)
	{
		// when using a constrained map mode, map against physical inch
		((CDC*)this)->SetMapMode(MM_HIMETRIC);
		LPtoDP(lpSize);
		((CDC*)this)->SetMapMode(nMapMode);
	}
	else
	{
		// map against logical inch for non-constrained mapping modes
		int cxPerInch, cyPerInch;
		if (this != NULL)
		{
			ASSERT_VALID(this);
			ASSERT(m_hDC != NULL);  // no HDC attached or created?
			cxPerInch = GetDeviceCaps(LOGPIXELSX);
			cyPerInch = GetDeviceCaps(LOGPIXELSY);
		}
		else
		{
			cxPerInch = afxData.cxPixelsPerInch;
			cyPerInch = afxData.cyPixelsPerInch;
		}
		ASSERT(cxPerInch != 0 && cyPerInch != 0);
		lpSize->cx = MulDiv(lpSize->cx, cxPerInch, HIMETRIC_INCH);
		lpSize->cy = MulDiv(lpSize->cy, cyPerInch, HIMETRIC_INCH);
	}
}
Example #13
0
void MacPrinterCanvas::start(float scale) {
	static char szMsg[] = "NEURON";
	scale_ = scale;
	if (!get()) {
		return;
	}
	//if (!Escape(hdc, STARTDOC, sizeof szMsg-1, szMsg, NULL)) {
		//DebugMessage("STARTDOC failed\n");
	//	abort();
	//}
	DOCINFO di;
  di.cbSize      = sizeof(DOCINFO);
  di.lpszDocName = "NEURON";
  di.lpszOutput  = NULL;
	
	StartDoc(hdc, &di);
	StartPage(hdc);
//	SetMapMode(hdc, MM_TWIPS);
	int a = GetMapMode(hdc);
	SIZE b; GetViewportExtEx(hdc, &b);
	POINT c; GetViewportOrgEx(hdc, &c);
	XFORM d; GetWorldTransform(hdc, &d);
	if (a < -10) { return; }
	damage_all();
	RECT r;
	//SetRectRgn(&r, 0, 0, hres_/2, vres_/2);
	r.left = 0; r.top=0; r.right = hres_; r.bottom=vres_;
	beginPaint(hdc, r);
	//SelectClipRgn(hdc, NULL);

	//d.eM11 = d.eM22 *= 2.;	
	//SetWorldTransform(hdc, &d);
}
Example #14
0
void	DrawMinimizeBox ( TDialog *  Dialog, BOOL  pressed )
   {
	int		BitmapId ;


// Ne dessiner le bouton que si son état a changé
	if  ( pressed )
		BitmapId   = OBM_REDUCED ;
	else
		BitmapId   = OBM_REDUCE ;


// Charger la bitmap prédéfinie
	HDC		WindowDC,
			MemDC ;
	HBITMAP		HBitmap ;
	POINT		PObjectPlacement,
			PSize,
			POrigin ;
	BITMAP		BitmapInfo ;


	WindowDC = GetWindowDC ( Dialog -> HWindow ) ;
	MemDC    = CreateCompatibleDC ( WindowDC ) ;
	HBitmap  = LoadBitmap ( NULL, ( LPSTR ) BitmapId ) ;

	if  ( HBitmap  ==  NULL )
	   {
		DeleteDC  ( MemDC ) ;
		ReleaseDC ( Dialog -> HWindow, WindowDC ) ;
		return ;
	    }

	SelectObject ( MemDC, HBitmap ) ;
	SetMapMode   ( MemDC, GetMapMode ( WindowDC ) ) ;

	GetObject ( HBitmap, sizeof ( BITMAP ), ( LPSTR ) & BitmapInfo ) ;

	PSize. x  =  BitmapInfo. bmWidth ;
	PSize. y  =  BitmapInfo. bmHeight ;
	DPtoLP ( WindowDC, & PSize, 1 ) ;

	POrigin. x = POrigin. y = 0 ;
	DPtoLP ( MemDC, & POrigin, 1 ) ;

	GetObjectOrigin ( Dialog, WS_MINIMIZEBOX, PObjectPlacement, PSize ) ;

	BitBlt ( WindowDC, PObjectPlacement. x, PObjectPlacement. y,
			PSize. x, PSize. y,
		 MemDC, POrigin. x, POrigin. y, SRCCOPY ) ;

// Ménage
	DeleteDC      ( MemDC ) ;
	DeleteObject  ( HBitmap ) ;
	ReleaseDC     ( Dialog -> HWindow, WindowDC ) ;
    }
Example #15
0
void getResolutionC(OSPictContext context, int *xResP, int *yResP)
{
	int mapMode = GetMapMode(context->hDC);
	if (mapMode==MM_ISOTROPIC)
		{	*xResP = WinGetHorzResolution();
			*yResP = WinGetVertResolution();
		}
	  else
		{	*xResP = GetDeviceCaps(context->hDC,LOGPIXELSX);
			*yResP = GetDeviceCaps(context->hDC,LOGPIXELSY);
		};
/*	MW: currently, the MM_ISOTROPIC mapping mode is only used for printing with the emulation
	of the screen resolution. In that case the screen resolution will be returned.
*/
}	/* getResolutionC */
Example #16
0
// MW...
static int PointsToPix(HDC hdc, int size)
{
	// convert font size in points to pixels (which depends on the device resolution)

    int vRes;
	int mapMode = GetMapMode(hdc);
	if (mapMode==MM_ISOTROPIC)
		vRes = WinGetVertResolution();
	  else
		vRes = GetDeviceCaps(hdc, LOGPIXELSY);
	return (size * vRes) / 72;
/*	MW: currently, the MM_ISOTROPIC mapping mode is only used for printing with the emulation
	of the screen resolution. For that purpose, points are not subject to the scaling, which
	MM_ISOTROPIC performs.
*/
}
Example #17
0
///////////////////////////////////////////////////////////////////////////////
// Anzahl der Pixel/mm in beiden Koordinatenrichtungen für dieses Fenster -----
CSize GetDotsPerMM (HDC hDC) 
{
HDC hDCloc;
CSize dimD (0, 0);

	if (hDC != NULL) hDCloc = hDC;
	else			 hDCloc = ::GetDC(::GetDesktopWindow());

	switch (GetMapMode (hDCloc)) {
	default:		// MM_ANISOTROPIC/MM_ISOTROPIC
	case MM_TEXT:		// der bisherige Stand
		{
		int HorzSize = GetDeviceCaps (hDCloc, HORZSIZE);       // Breite in mm
		int VertSize = GetDeviceCaps (hDCloc, VERTSIZE);       // Höhe in mm
		int HorzRes = GetDeviceCaps (hDCloc, HORZRES);         // Breite in Dots
		int VertRes = GetDeviceCaps (hDCloc, VERTRES);         // Höhe in Dots

			dimD =  CSize(HorzRes/HorzSize, VertRes/VertSize);
		}
		break;

	case MM_HIMETRIC:	// [0.01 mm]
		dimD = CSize(100, 100);
		break;
		
	case MM_LOMETRIC:	// [0.1 mm]
		dimD = CSize(10, 10);
		break;
		
	case MM_HIENGLISH:	// [0.001 inch]
		dimD = CSize(40, 40);
		break;
		
	case MM_LOENGLISH:	// [0.01 inch]
		dimD = CSize(4, 4);
		break;
		
	case MM_TWIPS:
		dimD = CSize(57, 57);
		break;
	}

// DC bei Bedarf wieder freigeben
	if (hDC == NULL) ReleaseDC (GetDesktopWindow(), hDCloc);

return dimD;
}
Example #18
0
/* Open the win_ddb driver */
static int
win_ddb_open(gx_device * dev)
{
    int code = win_open(dev);
    HDC hdc;

    if (code < 0)
	return code;

    if (wdev->BitsPerPixel > 8)
	return gs_error_limitcheck;	/* don't support 24 bit/pixel */

    /* Create the backing bitmap. */
    code = win_ddb_alloc_bitmap((gx_device_win *) dev, dev);
    if (code < 0)
	return code;

    /* Create the bitmap and DC for copy_mono. */
    hdc = GetDC(wdev->hwndimg);
    wdev->hbmmono = CreateBitmap(bmWidthBits, bmHeight, 1, 1, NULL);
    wdev->hdcmono = CreateCompatibleDC(hdc);
    if (wdev->hbmmono == NULL || wdev->hdcmono == NULL) {
	win_ddb_free_bitmap((gx_device_win *) dev);
	ReleaseDC(wdev->hwndimg, hdc);
	return win_nomemory();
    }
    SetMapMode(wdev->hdcmono, GetMapMode(hdc));
    SelectObject(wdev->hdcmono, wdev->hbmmono);
    wdev->bm_id = gx_no_bitmap_id;
    ReleaseDC(wdev->hwndimg, hdc);

    /* create palette and tools for bitmap */
    if ((wdev->lpalette = win_makepalette((gx_device_win *) dev))
	== (LPLOGPALETTE) NULL)
	return win_nomemory();
    wdev->hpalette = CreatePalette(wdev->lpalette);
    (void)SelectPalette(wdev->hdcbit, wdev->hpalette, NULL);
    RealizePalette(wdev->hdcbit);
    win_maketools(wdev, wdev->hdcbit);

    wdev->hdctext = wdev->hdcbit;	/* draw text here */

    return 0;
}
Example #19
0
void ColorNode(HDC hDC, COLORREF rgb, COLORREF bgc, 
               int left, int top, int right, int bottom)
{
    WORD wWidth = right - left;
    WORD wHeight = bottom - top;

    if (GetDeviceCaps(hDC, NUMCOLORS) <= 2)
        PatBlt(hDC, left, top, wWidth, wHeight, DSTINVERT);
    else
    {
        HBRUSH hBrush = CreateSolidBrush(rgb);
        HDC hMemDC = CreateCompatibleDC(hDC);
        HBITMAP hBitmap;
        DWORD dwExt;
        POINT pt;
    
        SetMapMode(hMemDC, GetMapMode(hDC));
        dwExt = GetWindowExt(hDC);
        SetWindowExt(hMemDC, LOWORD(dwExt), HIWORD(dwExt));
        dwExt = GetViewportExt(hDC);
        SetViewportExt(hMemDC, LOWORD(dwExt), HIWORD(dwExt));
    
        pt.x = wWidth;
        pt.y = wHeight;
        LPtoDP(hMemDC, &pt, 1);

        hBitmap = CreateBitmap(pt.x, pt.y, 1, 1, NULL);
        SelectObject(hMemDC, hBitmap);
        
        SetBkColor(hDC, bgc);
        BitBlt(hMemDC, 0, 0, wWidth, wHeight, hDC, left, top, SRCCOPY);
        
        SetBkColor(hDC, rgb);
        BitBlt(hDC, left, top, wWidth, wHeight, hMemDC, 0, 0, SRCCOPY);
        
        DeleteDC(hMemDC);
        DeleteObject(hBitmap);
        SelectObject(hDC, GetStockObject(WHITE_BRUSH));
        DeleteObject(hBrush);
        
        SetBkColor(hDC, GetSysColor(COLOR_WINDOW));
    }
}
Example #20
0
bool DeviceNull::init_color_frame()
{
	BITMAPINFO	f_bmi		= {0};
	void *		f_buffer	= nullptr;

	// create a device independent bitmap of the correct format
	f_bmi.bmiHeader.biCompression    = BI_RGB;
	f_bmi.bmiHeader.biBitCount       = m_private->m_resolution.m_bits_per_pixel;
    f_bmi.bmiHeader.biSize           = sizeof(BITMAPINFOHEADER);
    f_bmi.bmiHeader.biWidth          = m_private->m_resolution.m_width;
    f_bmi.bmiHeader.biHeight         = m_private->m_resolution.m_height;
    f_bmi.bmiHeader.biPlanes         = 1;
    f_bmi.bmiHeader.biSizeImage      = GetBitmapSize(&f_bmi.bmiHeader);
    f_bmi.bmiHeader.biClrImportant   = 0;

	auto f_dib = CreateDIBSection(nullptr, &f_bmi, DIB_RGB_COLORS, &f_buffer, nullptr, 0);

	if (!f_dib)
		return false;
	
	// attach the DIB to a device context
	auto f_hdc = GetDC(nullptr);
	auto f_paintdc = CreateCompatibleDC(f_hdc);
	SetMapMode(f_paintdc, GetMapMode(f_hdc));
	SelectObject(f_paintdc, f_dib);

	// text properties
	SetBkColor  (f_paintdc, RGB (0,0,0));
	SetTextColor(f_paintdc, RGB(255,255,255));
	SetTextAlign(f_paintdc, TA_CENTER);

	// write the text to the DIB
	const wchar_t *f_msg = L"No Kinect available.";
	TextOut(f_paintdc, 160, 110, f_msg, wcslen(f_msg));

	// save the buffer
	memcpy(m_private->m_color_data.data(), f_buffer, m_private->m_color_data.size());

	// cleanup
	DeleteDC(f_paintdc);

	return true;
}
Example #21
0
static void DrawCenterBitmap(HDC hDC, int xStart, int yStart, HBITMAP hBitmap)
{
    BITMAP bm;
    HDC hMemDC;
    POINT pt;

    hMemDC = CreateCompatibleDC(hDC);
    SelectObject(hMemDC, hBitmap);
    SetMapMode(hMemDC, GetMapMode(hDC));

    GetObject(hBitmap, sizeof(BITMAP), (LPSTR) & bm);

    pt.x = bm.bmWidth;
    pt.y = bm.bmHeight;
    DPtoLP(hDC, &pt, 1);

    BitBlt(hDC, xStart - bm.bmWidth / 2, yStart - bm.bmWidth / 2,
           pt.x, pt.y, hMemDC, 0, 0, SRCCOPY);

    DeleteDC(hMemDC);
}
Example #22
0
void WinGetPictureScaleFactor(OSPictContext context, int *nh, int *dh, int *nv, int *dv)
{
	if (GetMapMode(context->hDC)==MM_TEXT)
	    {	*nh = 1;
			*dh = 1;
			*nv = 1;
			*dv = 1;
		}
	  else
		{	SIZE sRes,pRes;
			GetWindowExtEx  (context->hDC,&sRes);
			GetViewportExtEx(context->hDC,&pRes);
			*nh	= pRes.cx;
			*dh	= sRes.cx;
			*nv	= pRes.cy;
			*dv	= sRes.cy;
		};

	/*	MW: Microsoft decided, that most drawing operations should work well with the
		MM_ISOTROPIC mapping mode, but not the clipping operations. For these, the clipping
		coordinates have to be scaled
	*/
}	/* WinGetPictureScaleFactor */
Example #23
0
/*
 * display a bitmap on the given DC, at device coordinates x,y
 * make the bitmap the same size as the source bitmap
 */
static void DrawBitmap( HDC hdc, HBITMAP bitmap, short x, short y )
/*****************************************************************/
{
    BITMAP      bitmapbuff;
    HDC         memorydc;
    POINT       origin;
    POINT       size;

    memorydc = CreateCompatibleDC( hdc );
    SelectObject( memorydc, bitmap );
    SetMapMode( memorydc, GetMapMode( hdc ) );
    GetObject( bitmap, sizeof( BITMAP ), (LPSTR) &bitmapbuff );

    origin.x = x;
    origin.y = y;
    size.x = bitmapbuff.bmWidth;
    size.y = bitmapbuff.bmHeight;

    DPtoLP( hdc, &origin, 1 );
    DPtoLP( memorydc, &size, 1 );

    BitBlt( hdc, origin.x, origin.y, size.x, size.y, memorydc, 0, 0, SRCCOPY);
    DeleteDC( memorydc );
} /* DrawBitmap */
Example #24
0
File: draw.c Project: RPG-7/reactos
/*
 * @implemented
 */
BOOL WINAPI
RealDrawFrameControl(HDC hDC, LPRECT rc, UINT uType, UINT uState)
{
    if (GetMapMode(hDC) != MM_TEXT)
        return FALSE;

    switch(uType)
    {
        case DFC_BUTTON:
            return UITOOLS95_DrawFrameButton(hDC, rc, uState);
        case DFC_CAPTION:
            return UITOOLS95_DrawFrameCaption(hDC, rc, uState);
        case DFC_MENU:
            return UITOOLS95_DrawFrameMenu(hDC, rc, uState);
#if 0
        case DFC_POPUPMENU:
            UNIMPLEMENTED;
            break;
#endif
        case DFC_SCROLL:
            return UITOOLS95_DrawFrameScroll(hDC, rc, uState);
    }
    return FALSE;
}
Example #25
0
void rect_draw_some_item(HBITMAP src,RECT src_rect,HBITMAP dest,RECT dest_rect,
	short trans, short main_win) {
	HDC hdcMem,hdcMem2,hdcMem3,destDC;
	HBITMAP transbmp;
	COLORREF white = RGB(255,255,255),oldcolor;
	HBRUSH hbrush,old_brush;
	COLORREF x = RGB(17,17,17);
	HBITMAP store,store2;
	Boolean dlog_draw = FALSE;

	main_dc2 = CreateCompatibleDC(main_dc);
	SetMapMode(main_dc2,GetMapMode((HDC)mainPtr));
	main_dc3 = CreateCompatibleDC(main_dc);
	SetMapMode(main_dc3,GetMapMode((HDC)mainPtr));
	SetStretchBltMode(main_dc2,STRETCH_DELETESCANS);
	SetStretchBltMode(main_dc3,STRETCH_DELETESCANS);

	if (main_win == 2) {
		destDC = (HDC) dest;
		main_win = 1;
		dlog_draw = TRUE;
		hdcMem = CreateCompatibleDC(destDC);
		SelectObject(hdcMem, src);
		SetMapMode(hdcMem,GetMapMode((HDC)mainPtr));
		SetStretchBltMode(hdcMem,STRETCH_DELETESCANS);
		}
		else {
			destDC = main_dc;
			hdcMem = main_dc2;
			store = (HBITMAP)SelectObject(hdcMem,src);
			}


	SetStretchBltMode(destDC,STRETCH_DELETESCANS);
	SetStretchBltMode(hdcMem,STRETCH_DELETESCANS);
	if (trans != 1) {
		if (main_win == 0) { // Not transparent, into bitmap
			hdcMem2 = main_dc3;
			store2 = (HBITMAP)SelectObject(hdcMem2, dest);

			SetStretchBltMode(hdcMem2,STRETCH_DELETESCANS);

				StretchBlt(hdcMem2,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,(trans >= 0) ? SRCCOPY : SRCAND);
			SelectObject(hdcMem2,store2);
			}

		else { // Not transparent, onto screen
		if (trans == 2) {
			hbrush = CreateSolidBrush(x);
			old_brush = (HBRUSH)SelectObject(destDC,hbrush);
			//SelectObject(hdcMem,hbrush);
			}
		if (dlog_draw == FALSE)
			SetViewportOrgEx(destDC,ulx,uly,NULL);

		SetStretchBltMode(destDC,STRETCH_DELETESCANS);
		SetStretchBltMode(hdcMem,STRETCH_DELETESCANS);
		StretchBlt(destDC,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,(trans == 0) ? SRCCOPY : MERGECOPY);
			if (trans == 2) {
				SelectObject(destDC,old_brush);
				if (DeleteObject(hbrush) == 0)
					play_sound(1);
				}
		if (dlog_draw == FALSE)
			SetViewportOrgEx(destDC,0,0,NULL);


		}
		} // end of non-transparent draws
		else {
		if (main_win == 0) {
			hdcMem3 = CreateCompatibleDC(hdcMem);
			SelectObject(hdcMem3, dest);
			SetMapMode(hdcMem3,GetMapMode((HDC)mainPtr));
			transbmp = CreateBitmap(src_rect.right - src_rect.left,
						src_rect.bottom - src_rect.top,1,1,NULL);
		hdcMem2 = CreateCompatibleDC(destDC);
		SelectObject(hdcMem2, transbmp);
		oldcolor = SetBkColor(hdcMem, white);
		StretchBlt(hdcMem2,0,0,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,SRCCOPY);
		SetBkColor(hdcMem, oldcolor);

		StretchBlt(hdcMem3,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,SRCINVERT);
		StretchBlt(hdcMem3,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem2,0,0,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,SRCAND);
		StretchBlt(hdcMem3,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,SRCINVERT);
		DeleteDC(hdcMem3);
		DeleteDC(hdcMem2);

			DeleteObject(transbmp);
		}
		else {
			if (dlog_draw == FALSE)
				SetViewportOrgEx(destDC,ulx,uly,NULL);
			transbmp = CreateBitmap(src_rect.right - src_rect.left,
						src_rect.bottom - src_rect.top,1,1,NULL);
			hdcMem2 = CreateCompatibleDC(destDC);
			SelectObject(hdcMem2, transbmp);
			oldcolor = SetBkColor(hdcMem, white);
			StretchBlt(hdcMem2,0,0,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,SRCCOPY);

			SetBkColor(hdcMem, oldcolor);

			StretchBlt(destDC,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,SRCINVERT);
			StretchBlt(destDC,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem2,0,0,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,SRCAND);
			StretchBlt(destDC,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,SRCINVERT);
			if (dlog_draw == FALSE)
				SetViewportOrgEx(destDC,0,0,NULL);
			DeleteDC(hdcMem2);

				DeleteObject(transbmp);


			}
			}
	if (dlog_draw == TRUE)
		DeleteDC(hdcMem);
		else SelectObject(hdcMem,store);
	DeleteDC(main_dc2);
	DeleteDC(main_dc3);
}
Example #26
0
static INT_PTR CALLBACK PhotoDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	const unsigned long iPageId = 3;

	TCHAR szAvatarFileName[MAX_PATH], szTempPath[MAX_PATH], szTempFileName[MAX_PATH];
	PhotoDlgProcData* dat = (PhotoDlgProcData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch (msg) {
	case WM_INITDIALOG:
		if (!lParam) break; // Launched from userinfo
		TranslateDialogDefault(hwndDlg);
		SendDlgItemMessage(hwndDlg, IDC_LOAD, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_OPEN), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0));
		SendDlgItemMessage(hwndDlg, IDC_LOAD, BUTTONSETASFLATBTN, TRUE, 0);
		SendDlgItemMessage(hwndDlg, IDC_DELETE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_DELETE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0));
		SendDlgItemMessage(hwndDlg, IDC_DELETE, BUTTONSETASFLATBTN, TRUE, 0);
		ShowWindow(GetDlgItem(hwndDlg, IDC_SAVE), SW_HIDE);
		{
			dat = new PhotoDlgProcData;
			dat->ppro = (CJabberProto*)lParam;
			dat->hBitmap = NULL;
			dat->ppro->m_bPhotoChanged = FALSE;
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);
			dat->ppro->WindowSubscribe(hwndDlg);
		}
		SendMessage(hwndDlg, WM_JABBER_REFRESH_VCARD, 0, 0);
		break;

	case WM_JABBER_REFRESH_VCARD:
		if (dat->hBitmap) {
			DeleteObject(dat->hBitmap);
			dat->hBitmap = NULL;
			DeleteFile(dat->ppro->m_szPhotoFileName);
			dat->ppro->m_szPhotoFileName[0] = '\0';
		}
		EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), FALSE);
		dat->ppro->GetAvatarFileName(NULL, szAvatarFileName, _countof(szAvatarFileName));
		if (_taccess(szAvatarFileName, 0) == 0) {
			if (GetTempPath(_countof(szTempPath), szTempPath) <= 0)
				mir_tstrcpy(szTempPath, _T(".\\"));
			if (GetTempFileName(szTempPath, _T("jab"), 0, szTempFileName) > 0) {
				dat->ppro->debugLog(_T("Temp file = %s"), szTempFileName);
				if (CopyFile(szAvatarFileName, szTempFileName, FALSE) == TRUE) {
					if ((dat->hBitmap = Bitmap_Load(szTempFileName)) != NULL) {
						FIP->FI_Premultiply(dat->hBitmap);
						mir_tstrcpy(dat->ppro->m_szPhotoFileName, szTempFileName);
						EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), TRUE);
					}
					else DeleteFile(szTempFileName);
				}
				else DeleteFile(szTempFileName);
			}
		}

		dat->ppro->m_bPhotoChanged = FALSE;
		InvalidateRect(hwndDlg, NULL, TRUE);
		UpdateWindow(hwndDlg);
		break;

	case WM_JABBER_CHANGED:
		dat->ppro->SetServerVcard(dat->ppro->m_bPhotoChanged, dat->ppro->m_szPhotoFileName);
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_DELETE:
			if (dat->hBitmap) {
				DeleteObject(dat->hBitmap);
				dat->hBitmap = NULL;
				DeleteFile(dat->ppro->m_szPhotoFileName);
				dat->ppro->m_szPhotoFileName[0] = '\0';
				dat->ppro->m_bPhotoChanged = TRUE;
				EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), FALSE);
				InvalidateRect(hwndDlg, NULL, TRUE);
				UpdateWindow(hwndDlg);
				dat->ppro->m_vCardUpdates |= (1UL << iPageId);
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			}
			break;

		case IDC_LOAD:
			TCHAR szFilter[512], szFileName[MAX_PATH];
			Bitmap_GetFilter(szFilter, _countof(szFilter));

			OPENFILENAME ofn = { 0 };
			ofn.lStructSize = sizeof(ofn);
			ofn.hwndOwner = hwndDlg;
			ofn.lpstrFilter = szFilter;
			ofn.lpstrCustomFilter = NULL;
			ofn.lpstrFile = szFileName;
			ofn.nMaxFile = MAX_PATH;
			ofn.Flags = OFN_FILEMUSTEXIST | OFN_DONTADDTORECENT;
			szFileName[0] = '\0';
			if (GetOpenFileName(&ofn)) {
				struct _stat st;
				HBITMAP hNewBitmap;

				dat->ppro->debugLog(_T("File selected is %s"), szFileName);
				if (_tstat(szFileName, &st) < 0 || st.st_size > 40 * 1024) {
					MessageBox(hwndDlg, TranslateT("Only JPG, GIF, and BMP image files smaller than 40 KB are supported."), TranslateT("Jabber vCard"), MB_OK | MB_SETFOREGROUND);
					break;
				}
				if (GetTempPath(_countof(szTempPath), szTempPath) <= 0)
					mir_tstrcpy(szTempPath, _T(".\\"));
				
				if (GetTempFileName(szTempPath, _T("jab"), 0, szTempFileName) > 0) {
					dat->ppro->debugLog(_T("Temp file = %s"), szTempFileName);
					if (CopyFile(szFileName, szTempFileName, FALSE) == TRUE) {
						if ((hNewBitmap = Bitmap_Load(szTempFileName)) != NULL) {
							if (dat->hBitmap) {
								DeleteObject(dat->hBitmap);
								DeleteFile(dat->ppro->m_szPhotoFileName);
							}

							dat->hBitmap = hNewBitmap;
							mir_tstrcpy(dat->ppro->m_szPhotoFileName, szTempFileName);
							dat->ppro->m_bPhotoChanged = TRUE;
							EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), TRUE);
							InvalidateRect(hwndDlg, NULL, TRUE);
							UpdateWindow(hwndDlg);
							dat->ppro->m_vCardUpdates |= (1UL << iPageId);
							SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
						}
						else DeleteFile(szTempFileName);
					}
					else DeleteFile(szTempFileName);
				}
			}
			break;
		}
		break;

	case WM_PAINT:
		if (dat->hBitmap) {
			BITMAP bm;
			POINT ptSize, ptOrg, pt, ptFitSize;
			RECT rect;

			HWND hwndCanvas = GetDlgItem(hwndDlg, IDC_CANVAS);
			HDC hdcCanvas = GetDC(hwndCanvas);
			HDC hdcMem = CreateCompatibleDC(hdcCanvas);
			SelectObject(hdcMem, dat->hBitmap);
			SetMapMode(hdcMem, GetMapMode(hdcCanvas));
			GetObject(dat->hBitmap, sizeof(BITMAP), (LPVOID)&bm);
			ptSize.x = bm.bmWidth;
			ptSize.y = bm.bmHeight;
			DPtoLP(hdcCanvas, &ptSize, 1);
			ptOrg.x = ptOrg.y = 0;
			DPtoLP(hdcMem, &ptOrg, 1);
			GetClientRect(hwndCanvas, &rect);
			InvalidateRect(hwndCanvas, NULL, TRUE);
			UpdateWindow(hwndCanvas);
			if (ptSize.x <= rect.right && ptSize.y <= rect.bottom) {
				pt.x = (rect.right - ptSize.x) / 2;
				pt.y = (rect.bottom - ptSize.y) / 2;
				ptFitSize = ptSize;
			}
			else {
				if (((float)(ptSize.x - rect.right)) / ptSize.x > ((float)(ptSize.y - rect.bottom)) / ptSize.y) {
					ptFitSize.x = rect.right;
					ptFitSize.y = (ptSize.y*rect.right) / ptSize.x;
					pt.x = 0;
					pt.y = (rect.bottom - ptFitSize.y) / 2;
				}
				else {
					ptFitSize.x = (ptSize.x*rect.bottom) / ptSize.y;
					ptFitSize.y = rect.bottom;
					pt.x = (rect.right - ptFitSize.x) / 2;
					pt.y = 0;
				}
			}

			RECT rc;
			GetClientRect(hwndCanvas, &rc);
			if (IsThemeActive())
				DrawThemeParentBackground(hwndCanvas, hdcCanvas, &rc);
			else
				FillRect(hdcCanvas, &rc, (HBRUSH)GetSysColorBrush(COLOR_BTNFACE));

			if (bm.bmBitsPixel == 32) {
				BLENDFUNCTION bf = { 0 };
				bf.AlphaFormat = AC_SRC_ALPHA;
				bf.BlendOp = AC_SRC_OVER;
				bf.SourceConstantAlpha = 255;
				GdiAlphaBlend(hdcCanvas, pt.x, pt.y, ptFitSize.x, ptFitSize.y, hdcMem, ptOrg.x, ptOrg.y, ptSize.x, ptSize.y, bf);
			}
			else {
				SetStretchBltMode(hdcCanvas, COLORONCOLOR);
				StretchBlt(hdcCanvas, pt.x, pt.y, ptFitSize.x, ptFitSize.y, hdcMem, ptOrg.x, ptOrg.y, ptSize.x, ptSize.y, SRCCOPY);
			}

			DeleteDC(hdcMem);
		}
		break;

	case WM_NOTIFY:
		if (((LPNMHDR)lParam)->idFrom == 0) {
			switch (((LPNMHDR)lParam)->code) {
			case PSN_PARAMCHANGED:
				SendMessage(hwndDlg, WM_INITDIALOG, 0, ((PSHNOTIFY*)lParam)->lParam);
				break;

			case PSN_APPLY:
				dat->ppro->m_vCardUpdates &= ~(1UL << iPageId);
				dat->ppro->SaveVcardToDB(hwndDlg, iPageId);
				if (!dat->ppro->m_vCardUpdates)
					dat->ppro->SetServerVcard(dat->ppro->m_bPhotoChanged, dat->ppro->m_szPhotoFileName);
				break;
			}
		}
		break;

	case WM_DESTROY:
		DestroyIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_LOAD, BM_SETIMAGE, IMAGE_ICON, 0));
		DestroyIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_DELETE, BM_SETIMAGE, IMAGE_ICON, 0));
		dat->ppro->WindowUnsubscribe(hwndDlg);
		if (dat->hBitmap) {
			dat->ppro->debugLogA("Delete bitmap");
			DeleteObject(dat->hBitmap);
			DeleteFile(dat->ppro->m_szPhotoFileName);
		}
		delete dat;
		break;
	}
	return FALSE;
}
Example #27
0
void KDCAttributes::DumpDC(HDC hDC)
{
	POINT pnt;
	SIZE  size;

	m_List.DeleteAll();

	Add(_T("Technology"),  _T("%d"), GetDeviceCaps(hDC, TECHNOLOGY));
	Add(_T("width"),	   _T("%d"), GetDeviceCaps(hDC, HORZRES));
	Add(_T("height"),	   _T("%d"), GetDeviceCaps(hDC, VERTRES));

	GetDCOrgEx(hDC, & pnt); 
	Add(_T("DC Origin"), _T("{ %d, %d }"), pnt.x, pnt.y);

	TCHAR szTitle[MAX_PATH];

	szTitle[0] = 0;

	GetWindowText(WindowFromDC(hDC), szTitle, MAX_PATH);
	Add(_T("Window"),    _T("0x%X \"%s\""), WindowFromDC(hDC), szTitle);

	Add(_T("Bitmap"),        _T("0x%X"), GetCurrentObject(hDC, OBJ_BITMAP));

	Add(_T("Graphics Mode"), _T("%d"), GetGraphicsMode(hDC));
	Add(_T("Mapping Mode"),  _T("%d"), GetMapMode(hDC));

	GetViewportExtEx(hDC, & size);
	Add(_T("Viewport Extent"), _T("{ %d, %d }"), size.cx, size.cy);
	
	GetViewportOrgEx(hDC, & pnt);
	Add(_T("Viewport Origin"), _T("{ %d, %d }"), pnt.x, pnt.y);

	GetWindowExtEx(hDC, & size);
	Add(_T("Window Extent"), _T("{ %d, %d }"), size.cx, size.cy);
	
	GetWindowOrgEx(hDC, & pnt);
	Add(_T("Window Origin"), _T("{ %d, %d }"), pnt.x, pnt.y);

	XFORM xform;
	GetWorldTransform(hDC, & xform);

	Add(_T("World transformation"), _T("{ %f, %f, %f, %f, %f, %f }"),
		xform.eM11, xform.eM12, xform.eM21, xform.eM22, xform.eDx, xform.eDy);

	// transformation

	Add(_T("Background Color"), _T("0x%X"), GetBkColor(hDC));
	Add(_T("Text Color"),       _T("0x%X"), GetTextColor(hDC));
	Add(_T("Palette"),          _T("0x%X"), GetCurrentObject(hDC, OBJ_PAL));

	{
		COLORADJUSTMENT ca;
		GetColorAdjustment(hDC, & ca);
	
		Add(_T("Color Adjustment"), _T("{ %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d }"), 
			ca.caSize, ca.caFlags, ca.caIlluminantIndex,
			ca.caRedGamma, ca.caGreenGamma, ca.caBlueGamma, 
			ca.caReferenceBlack, ca.caReferenceWhite,
			ca.caContrast, ca.caBrightness, ca.caColorfulness, ca.caRedGreenTint);
	}

	Add(_T("Color Space"), _T("0x%X"), GetColorSpace(hDC));
	Add(_T("ICM Mode"),    _T("%d"),   SetICMMode(hDC, ICM_QUERY));

	{
		TCHAR szProfile[MAX_PATH];
		DWORD dwSize = MAX_PATH;

		szProfile[0] = 0;
		GetICMProfile(hDC, & dwSize, szProfile);

		Add(_T("ICM Profile"), _T("%s"), szProfile);
	}

	GetCurrentPositionEx(hDC, & pnt);
	Add(_T("Current Position"), _T("{ %d, %d }"), pnt.x, pnt.y);

	Add(_T("ROP2"),				_T("%d"),	GetROP2(hDC));
	Add(_T("Background Mode"),	_T("%d"),	GetBkMode(hDC));
	Add(_T("Logical Pen"),		_T("0x%X"), GetCurrentObject(hDC, OBJ_PEN));
	Add(_T("DC Pen Color"),     _T("0x%X"), GetDCPenColor(hDC));
	Add(_T("Arc Direction"),	_T("%d"),	GetArcDirection(hDC));

	FLOAT miter;
	GetMiterLimit(hDC, & miter);

	Add(_T("Miter Limit"),		_T("%f"),	miter);
	
	Add(_T("Logical Brush"),    _T("0x%X"), GetCurrentObject(hDC, OBJ_BRUSH));
	Add(_T("DC Brush Color"),   _T("0x%X"), GetDCBrushColor(hDC));

	GetBrushOrgEx(hDC, & pnt);
	Add(_T("Brush Origin"),     _T("{ %d, %d }"), pnt.x, pnt.y);

	Add(_T("Polygon Filling Mode"),   _T("%d"), GetPolyFillMode(hDC));
	Add(_T("Bitmap Stretching Mode"), _T("%d"), GetStretchBltMode(hDC));
	Add(_T("Logical Font"),			  _T("0x%X"), GetCurrentObject(hDC, OBJ_FONT));
	Add(_T("Inter-character spacing"), _T("%d"), GetTextCharacterExtra(hDC));

	DWORD flag = SetMapperFlags(hDC, 0);
	SetMapperFlags(hDC, flag);

	Add(_T("Font Mapper Flags"),       _T("0x%X"), flag);

	Add(_T("Text Alignment"),		   _T("0x%X"), GetTextAlign(hDC));

	Add(_T("Text Justification"),      _T("write only"), 0);

	Add(_T("Layout"),                  _T("%d"), GetLayout(hDC));

	Add(_T("Path"),					   _T("%d bytes"), GetPath(hDC, NULL, NULL, 0));

	RECT rect;

	int typ = GetClipBox(hDC, & rect);

	HRGN hRgn = CreateRectRgn(0, 0, 1, 1);
	
	GetClipRgn(hDC, hRgn);

	Add(_T("Clipping"),				   _T("type %d clip box { %d, %d, %d, %d } size %d bytes"), 
		typ, rect.left, rect.top, rect.right, rect.bottom,
		GetRegionData(hRgn, 0, NULL)
		);
	
	GetMetaRgn(hDC, hRgn);

	GetRgnBox(hRgn, & rect);
	Add(_T("Meta Region"), _T("size %d bytes, rgn box { %d, %d, %d, %d }"), 
		GetRegionData(hRgn, 0, NULL), rect.left, rect.top, rect.right, rect.bottom);

	for (int i=1; i<=5; i++)
	{
		int rslt = GetRandomRgn(hDC, hRgn, i);

		if ( rslt==1 )
		{
			GetRgnBox(hRgn, & rect);
			Add(_T("Random Region"), _T("size %d bytes, rgn box { %d, %d, %d, %d }"), 
			GetRegionData(hRgn, 0, NULL), rect.left, rect.top, rect.right, rect.bottom);
		}
		else if ( rslt==0 )
			Add(_T("Random Region"), _T("NULL"), 0);
		else
			Add(_T("Random Region"), _T("FAIL"), 0);
	}
	DeleteObject(hRgn);

	GetBoundsRect(hDC, & rect, 0);

	Add(_T("Bounds Rectangle"),		_T("{ %d, %d, %d, %d }"), 
		rect.left, rect.top, rect.right, rect.bottom);
}
Example #28
0
void _DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, short xStart, short yStart, COLORREF cTransparentColor)
{
	BITMAP     bm;
	COLORREF   cColor;
	HBITMAP    bmAndBack, bmAndObject, bmAndMem, bmSave;
	HBITMAP    bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
	HDC        hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;
	POINT      ptSize;

	hdcTemp = CreateCompatibleDC(hdc);
	SelectObject(hdcTemp, hBitmap);   // Select the bitmap

	GetObject(hBitmap, sizeof(BITMAP), &bm);
	ptSize.x = bm.bmWidth;            // Get width of bitmap
	ptSize.y = bm.bmHeight;           // Get height of bitmap
	DPtoLP(hdcTemp, &ptSize, 1);      // Convert from device

	// to logical points

	// Create some DCs to hold temporary data.
	hdcBack   = CreateCompatibleDC(hdc);
	hdcObject = CreateCompatibleDC(hdc);
	hdcMem    = CreateCompatibleDC(hdc);
	hdcSave   = CreateCompatibleDC(hdc);

	// Create a bitmap for each DC. DCs are required for a number of
	// GDI functions.

	// Monochrome DC
	bmAndBack   = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

	// Monochrome DC
	bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

	bmAndMem    = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
	bmSave      = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);

	// Each DC must select a bitmap object to store pixel data.
	bmBackOld   = (HBITMAP)SelectObject(hdcBack, bmAndBack);
	bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject);
	bmMemOld    = (HBITMAP)SelectObject(hdcMem, bmAndMem);
	bmSaveOld   = (HBITMAP)SelectObject(hdcSave, bmSave);

	// Set proper mapping mode.
	SetMapMode(hdcTemp, GetMapMode(hdc));

	// Save the bitmap sent here, because it will be overwritten.
	BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);

	// Set the background color of the source DC to the color.
	// contained in the parts of the bitmap that should be transparent
	cColor = SetBkColor(hdcTemp, cTransparentColor);

	// Create the object mask for the bitmap by performing a BitBlt
	// from the source bitmap to a monochrome bitmap.
	BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0,
		SRCCOPY);

	// Set the background color of the source DC back to the original
	// color.
	SetBkColor(hdcTemp, cColor);

	// Create the inverse of the object mask.
	BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0,
		NOTSRCCOPY);

	// Copy the background of the main DC to the destination.
	BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, xStart, yStart,
		SRCCOPY);

	// Mask out the places where the bitmap will be placed.
	BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);

	// Mask out the transparent colored pixels on the bitmap.
	BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);

	// XOR the bitmap with the background on the destination DC.
	BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);

	// Copy the destination to the screen.
	BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0,
		SRCCOPY);

	// Place the original bitmap back into the bitmap sent here.
	BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);

	// Delete the memory bitmaps.
	DeleteObject(SelectObject(hdcBack, bmBackOld));
	DeleteObject(SelectObject(hdcObject, bmObjectOld));
	DeleteObject(SelectObject(hdcMem, bmMemOld));
	DeleteObject(SelectObject(hdcSave, bmSaveOld));

	// Delete the memory DCs.
	DeleteDC(hdcMem);
	DeleteDC(hdcBack);
	DeleteDC(hdcObject);
	DeleteDC(hdcSave);
	DeleteDC(hdcTemp);
}
Example #29
0
static void test_dc_layout(void)
{
    INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
    SIZE size;
    POINT pt;
    HBITMAP bitmap;
    RECT rc, ret_rc;
    HDC hdc;
    HRGN hrgn;

    if (!pGetLayout || !pSetLayout)
    {
        win_skip( "Don't have SetLayout\n" );
        return;
    }

    hdc = CreateCompatibleDC(0);
    bitmap = CreateCompatibleBitmap( hdc, 100, 100 );
    SelectObject( hdc, bitmap );

    size_cx = GetDeviceCaps(hdc, HORZSIZE);
    size_cy = GetDeviceCaps(hdc, VERTSIZE);
    res_x = GetDeviceCaps(hdc, HORZRES);
    res_y = GetDeviceCaps(hdc, VERTRES);
    dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
    dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);

    ret = GetMapMode( hdc );
    ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
    expect_viewport_ext(hdc, 1, 1);
    expect_window_ext(hdc, 1, 1);
    expect_world_transform(hdc, 1.0, 1.0);
    expect_LPtoDP(hdc, 1000, 1000);

    pSetLayout( hdc, LAYOUT_RTL );
    if (!pGetLayout( hdc ))
    {
        win_skip( "SetLayout not supported\n" );
        DeleteDC(hdc);
        return;
    }

    ret = GetMapMode( hdc );
    ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
    expect_viewport_ext(hdc, 1, 1);
    expect_window_ext(hdc, 1, 1);
    expect_world_transform(hdc, 1.0, 1.0);
    expect_LPtoDP(hdc, -1000 + 99, 1000);
    GetViewportOrgEx( hdc, &pt );
    ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y );
    GetWindowOrgEx( hdc, &pt );
    ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y );
    GetDCOrgEx( hdc, &pt );
    ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y );
    if (pGetTransform)
    {
        XFORM xform;
        BOOL ret = pGetTransform( hdc, 0x204, &xform ); /* World -> Device */
        ok( ret, "got %d\n", ret );
        ok( xform.eM11 == -1.0, "got %f\n", xform.eM11 );
        ok( xform.eM12 == 0.0, "got %f\n", xform.eM12 );
        ok( xform.eM21 == 0.0, "got %f\n", xform.eM21 );
        ok( xform.eM22 == 1.0, "got %f\n", xform.eM22 );
        ok( xform.eDx == 99.0, "got %f\n", xform.eDx );
        ok( xform.eDy == 0.0, "got %f\n", xform.eDy );
    }

    SetRect( &rc, 10, 10, 20, 20 );
    IntersectClipRect( hdc, 10, 10, 20, 20 );
    hrgn = CreateRectRgn( 0, 0, 0, 0 );
    GetClipRgn( hdc, hrgn );
    GetRgnBox( hrgn, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
    pSetLayout( hdc, LAYOUT_LTR );
    SetRect( &rc, 80, 10, 90, 20 );
    GetClipRgn( hdc, hrgn );
    GetRgnBox( hrgn, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
    GetClipBox( hdc, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
    IntersectClipRect( hdc, 80, 10, 85, 20 );
    pSetLayout( hdc, LAYOUT_RTL );
    SetRect( &rc, 15, 10, 20, 20 );
    GetClipRgn( hdc, hrgn );
    GetRgnBox( hrgn, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
    GetClipBox( hdc, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
    SetRectRgn( hrgn, 60, 10, 80, 20 );
    pSetLayout( hdc, LAYOUT_LTR );
    ExtSelectClipRgn( hdc, hrgn, RGN_OR );
    pSetLayout( hdc, LAYOUT_RTL );
    SetRect( &rc, 15, 10, 40, 20 );
    GetClipRgn( hdc, hrgn );
    GetRgnBox( hrgn, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
    GetClipBox( hdc, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );

    /* OffsetClipRgn mirrors too */
    OffsetClipRgn( hdc, 5, 5 );
    OffsetRect( &rc, 5, 5 );
    GetClipRgn( hdc, hrgn );
    GetRgnBox( hrgn, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );

    /* GetRandomRgn returns the raw region */
    if (pGetRandomRgn)
    {
        SetRect( &rc, 55, 15, 80, 25 );
        pGetRandomRgn( hdc, hrgn, 1 );
        GetRgnBox( hrgn, &ret_rc );
        ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
            ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
    }

    SetMapMode(hdc, MM_LOMETRIC);
    ret = GetMapMode( hdc );
    ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);

    expect_viewport_ext(hdc, res_x, -res_y);
    ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
    ok( rough_match( size.cx, size_cx * 10 ) ||
        rough_match( size.cx, MulDiv( res_x, 254, dpi_x )),  /* Vista uses a more precise method */
        "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
    ok( rough_match( size.cy, size_cy * 10 ) ||
        rough_match( size.cy, MulDiv( res_y, 254, dpi_y )),  /* Vista uses a more precise method */
        "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
    expect_world_transform(hdc, 1.0, 1.0);
    expect_LPtoDP(hdc, -MulDiv(1000 / 10, res_x, size_cx) + 99, -MulDiv(1000 / 10, res_y, size_cy));

    SetMapMode(hdc, MM_TEXT);
    ret = GetMapMode( hdc );
    ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
    pSetLayout( hdc, LAYOUT_LTR );
    ret = GetMapMode( hdc );
    ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
    SetMapMode(hdc, MM_TEXT);
    ret = GetMapMode( hdc );
    ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);

    DeleteDC(hdc);
    DeleteObject( bitmap );
}
Example #30
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
  HWND hwndParent = hWndParent;
  HWND hwndImage = hWndImage;

  if (hwnd == hwndParent) {
    if (message == WM_SIZE) {
      ShowWindow(hwndImage, wParam == SIZE_MINIMIZED ? SW_HIDE : SW_SHOW);
    }
    if (message == WM_WINDOWPOSCHANGED) {
      SetWindowPos(hwndImage, hwndParent, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
    }
    return CallWindowProc(
      (long (__stdcall *)(HWND,unsigned int,unsigned int,long))oldProc,
      hwnd,
      message,
      wParam,
      lParam
    );
  }
  switch (message) {
    case WM_PAINT:
    if (bgBitmap.bReady) {
      ECS();

      PAINTSTRUCT ps;
      HDC hdc = BeginPaint(hwnd, &ps);

      if (bgBitmap.iType == MIL_BITMAP) {
        HDC cdc = CreateCompatibleDC(hdc);
        SelectObject(cdc, bgBitmap.hBitmap);
        for (unsigned int x = 0; x < uWndWidth; x += bgBitmap.rPos.right) {
          for (unsigned int y = 0; y < uWndHeight; y += bgBitmap.rPos.bottom) {
            BitBlt(hdc, x, y, bgBitmap.rPos.right, bgBitmap.rPos.bottom, cdc, 0, 0, SRCCOPY);
          }
        }
        DeleteDC(cdc);
      }
      else {
        int r = GetRValue(bgBitmap.cGradientFrom) << 10;
        int g = GetGValue(bgBitmap.cGradientFrom) << 10;
        int b = GetBValue(bgBitmap.cGradientFrom) << 10;
        int dr = ((GetRValue(bgBitmap.cGradientTo) << 10) - r) / (int)uWndHeight * 4;
        int dg = ((GetGValue(bgBitmap.cGradientTo) << 10) - g) / (int)uWndHeight * 4;
        int db = ((GetBValue(bgBitmap.cGradientTo) << 10) - b) / (int)uWndHeight * 4;
        RECT rect;
        rect.left = 0;
        rect.top = 0;
        rect.right = uWndWidth;
        rect.bottom = 4;
        while (rect.top < (int)uWndHeight)
        {
          HBRUSH brush = CreateSolidBrush(RGB(r>>10,g>>10,b>>10));
          FillRect(hdc, &rect, brush);
          DeleteObject(brush);
          rect.top+=4;
          rect.bottom+=4;
          r+=dr;
          g+=dg;
          b+=db;
        }
      }

      myImageList *img = bgBitmap.next;
      while (img) {
        if (img->iType == MIL_TEXT) {
          SetBkMode(hdc, TRANSPARENT);

          SetTextColor(hdc, img->cTextColor);
          SelectObject(hdc, img->hFont);
          DrawText(hdc, img->szText, -1, &img->rPos, DT_TOP | DT_LEFT | DT_NOPREFIX | DT_WORDBREAK);
        }
        else if (img->iType == MIL_BITMAP) {
          HDC cdc = CreateCompatibleDC(hdc);
          SelectObject(cdc, img->hBitmap);
          BitBlt(hdc, img->rPos.left, img->rPos.top, img->rPos.right - img->rPos.left, img->rPos.bottom - img->rPos.top, cdc, 0, 0, SRCCOPY);
          DeleteDC(cdc);
        }
        else {
          COLORREF   cColor;
          HBITMAP    bmAndBack, bmAndObject, bmAndMem, bmSave;
          HBITMAP    bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
          HDC        hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;
          POINT      ptSize;

          HBITMAP hBitmap = img->hBitmap;

          hdcTemp = CreateCompatibleDC(hdc);
          SelectObject(hdcTemp, hBitmap);   // Select the bitmap

          ptSize.x = img->rPos.right - img->rPos.left;
          ptSize.y = img->rPos.bottom - img->rPos.top;
          DPtoLP(hdcTemp, &ptSize, 1);  // Convert from device to logical points

          // Create some DCs to hold temporary data.
          hdcBack   = CreateCompatibleDC(hdc);
          hdcObject = CreateCompatibleDC(hdc);
          hdcMem    = CreateCompatibleDC(hdc);
          hdcSave   = CreateCompatibleDC(hdc);

          // Create a bitmap for each DC. DCs are required for a number of
          // GDI functions.

          // Monochrome DC
          bmAndBack   = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

          // Monochrome DC
          bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);

          bmAndMem    = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
          bmSave      = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);

          // Each DC must select a bitmap object to store pixel data.
          bmBackOld   = (HBITMAP)SelectObject(hdcBack, bmAndBack);
          bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject);
          bmMemOld    = (HBITMAP)SelectObject(hdcMem, bmAndMem);
          bmSaveOld   = (HBITMAP)SelectObject(hdcSave, bmSave);

          // Set proper mapping mode.
          SetMapMode(hdcTemp, GetMapMode(hdc));

          // Save the bitmap sent here, because it will be overwritten.
          BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);

          // Set the background color of the source DC to the color.
          // contained in the parts of the bitmap that should be transparent
          cColor = SetBkColor(hdcTemp, img->cTransparent);

          // Create the object mask for the bitmap by performing a BitBlt
          // from the source bitmap to a monochrome bitmap.
          BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0,
              SRCCOPY);

          // Set the background color of the source DC back to the original
          // color.
          SetBkColor(hdcTemp, cColor);

          // Create the inverse of the object mask.
          BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0,
              NOTSRCCOPY);

          // Copy the background of the main DC to the destination.
          BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, img->rPos.left, img->rPos.top,
              SRCCOPY);

          // Mask out the places where the bitmap will be placed.
          BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);

          // Mask out the transparent colored pixels on the bitmap.
          BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);

          // XOR the bitmap with the background on the destination DC.
          BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);

          // Copy the destination to the screen.
          BitBlt(hdc, img->rPos.left, img->rPos.top, ptSize.x, ptSize.y, hdcMem, 0, 0,
              SRCCOPY);

          // Place the original bitmap back into the bitmap sent here.
          BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);

          // Delete the memory bitmaps.
          DeleteObject(SelectObject(hdcBack, bmBackOld));
          DeleteObject(SelectObject(hdcObject, bmObjectOld));
          DeleteObject(SelectObject(hdcMem, bmMemOld));
          DeleteObject(SelectObject(hdcSave, bmSaveOld));

          // Delete the memory DCs.
          DeleteDC(hdcMem);
          DeleteDC(hdcBack);
          DeleteDC(hdcObject);
          DeleteDC(hdcSave);
          DeleteDC(hdcTemp);
        }
        img = img->next;
      }

      LCS();

      EndPaint(hwnd, &ps);
    }
    break;
    case WM_WINDOWPOSCHANGING:
      if (IsWindow(hwndParent))
      {
        LPWINDOWPOS wp = (LPWINDOWPOS) lParam;
        wp->flags |= SWP_NOACTIVATE;
        wp->hwndInsertAfter = hwndParent;
      }
      break;
    case WM_CLOSE:
      DestroyWindow(hwnd);
    break;
    default:
      return DefWindowProc(hwnd, message, wParam, lParam);
  }