Exemplo n.º 1
0
BOOL CScreenSnap::GetScreenDataSize(DWORD &dwScreenDataSize)
{
	CDC dc;
	dc.CreateDC("DISPLAY",NULL,NULL,NULL);
	CheckPointer(dc.GetSafeHdc(),FALSE);

	CBitmap bm;
	int nWidth	= GetSystemMetrics(SM_CXSCREEN);
	int nHeight	= GetSystemMetrics(SM_CYSCREEN);
	if(!bm.CreateCompatibleBitmap(&dc,nWidth,nHeight))
	{
		dc.DeleteDC();
		return FALSE;
	}

	BITMAP btm;
	bm.GetBitmap(&btm);

	dwScreenDataSize  = btm.bmWidthBytes * btm.bmHeight;
	dwScreenDataSize += sizeof(BITMAPFILEHEADER);
	dwScreenDataSize += sizeof(BITMAPINFOHEADER);
	
	dc.DeleteDC();

	return TRUE;
}
Exemplo n.º 2
0
LRESULT CScreenDlg::OnInitDialog(UINT uMsg,WPARAM wParam,LPARAM lParam,BOOL& bHandled){
  ShowWindow(SW_HIDE);
  CDC dcScreen;
  dcScreen.CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
  m_size.cx = GetDeviceCaps(dcScreen.m_hDC, HORZRES);
  m_size.cy = GetDeviceCaps(dcScreen.m_hDC, VERTRES);
  m_dcMem.CreateCompatibleDC(dcScreen.m_hDC);
  m_bmpScreen.CreateCompatibleBitmap(dcScreen.m_hDC, m_size.cx,m_size.cy);
  HBITMAP pOldBmp = m_dcMem.SelectBitmap(m_bmpScreen.m_hBitmap);
  m_dcMem.BitBlt(0,0,m_size.cx, m_size.cy, dcScreen.m_hDC, 0, 0, SRCCOPY);
  RECT rect={0,0,m_size.cx, m_size.cy};
  MoveWindow(&rect);
  ShowWindow(SW_SHOW);
  RIGHT_RECT.left  = m_size.cx - INFO_WIDTH-INFO_OFFSET;
  RIGHT_RECT.right = m_size.cx-INFO_OFFSET;

  m_bmpInfoBK = (HBITMAP)c6beeres::R().GetImg(IDB_BITMAP_INFOBK,IMAGE_BITMAP,INFO_WIDTH,INFO_HEIGHT);

  S1= (HBITMAP)c6beeres::R().GetImg(IDB_S1,IMAGE_BITMAP,shadow_size,shadow_size);
  S2= (HBITMAP)c6beeres::R().GetImg(IDB_S2,IMAGE_BITMAP,shadow_size,shadow_size);
  S3= (HBITMAP)c6beeres::R().GetImg(IDB_S3,IMAGE_BITMAP,shadow_size,shadow_size);
  S4= (HBITMAP)c6beeres::R().GetImg(IDB_S4,IMAGE_BITMAP,shadow_size,shadow_size);
  S5= (HBITMAP)c6beeres::R().GetImg(IDB_S5,IMAGE_BITMAP,shadow_size,shadow_size);

  thinfont  = ::CreateFont(15,0,0,0,FW_THIN,false,FALSE,FALSE,DEFAULT_CHARSET,OUT_STRING_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_MODERN,_T("arial"));
  boldfont= ::CreateFont(15,0,0,0,FW_BOLD,false,FALSE,FALSE,DEFAULT_CHARSET,OUT_STRING_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_MODERN,_T("arial"));
  penLine1.CreatePen(PS_SOLID, 1, SELECT_RECTCOLOR);
  penLine2.CreatePen(PS_SOLID, 1, CROSS_LINECOLOR);
  bool border=false,shadow=false;
  COLORREF bcolor=0;
  nsplugin::GetImgCapParam(border,shadow,bcolor);
  pen_Border.CreatePen(PS_SOLID, border_size, bcolor);
  return 0;
}
Exemplo n.º 3
0
BOOL CPMenuSpecial::SetFont (CFont  &pFont)
{
    TEXTMETRIC  tm;
    CFont       *pOldFont;
    CDC         TVDC;
    LOGFONT LogFont;

    m_Font.DeleteObject ();
    if (pFont.GetObject (sizeof (LogFont), &LogFont) != 0)
    {
        if (m_Font.CreateFontIndirect (&LogFont) != 0)
        {
            if (m_Font.GetObject (sizeof (LogFont), &LogFont) != 0)
            {
                if (TVDC.CreateDC ("DISPLAY", NULL, NULL, NULL) != 0)
                {
                    if ((pOldFont = TVDC.SelectObject (&m_Font)) != NULL)
                    {
                        TVDC.GetTextMetrics (&tm);
                        m_nDefaultTextHeight = tm.tmHeight;
                        TVDC.SelectObject (pOldFont);

                        return TRUE;
                    }
                }
            }
            m_Font.DeleteObject ();
        }
    }
    return FALSE;
}
Exemplo n.º 4
0
void CViewBitmap::Capture(CRect &rect)
{ 
 if(m_pPalette)
 { DeleteObject();
   delete m_pPalette;
 }
 m_width=rect.Width();
 m_heighth=rect.Height();
 double wid=rect.left/1024;
 double hei=rect.top/768;

 CDC dcscreen;
 dcscreen.CreateDC("DISPLAY",NULL,NULL,NULL);
 CDC dcMem;
 dcMem.CreateCompatibleDC( &dcscreen );
 CreateCompatibleBitmap( &dcscreen, m_width, m_heighth );
 dcMem.SelectObject( this );

 dcMem.BitBlt(0,0,m_width, m_heighth,&dcscreen,rect.left,rect.top,SRCCOPY);
// create an empty logical palette that¡¯s big enough to hold all the colors
 int nColors = ( 1 << ( dcscreen.GetDeviceCaps( BITSPIXEL ) *dcscreen.GetDeviceCaps( PLANES ) ) );
 LOGPALETTE *pLogpal=(LOGPALETTE*) new BYTE[sizeof(LOGPALETTE)+(nColors * sizeof(PALETTEENTRY))];
 pLogpal -> palVersion = 0x300;
 pLogpal -> palNumEntries = nColors;
// load this empty palette with the system palette's colors
 GetSystemPaletteEntries( dcscreen.m_hDC, 0, nColors,(LPPALETTEENTRY)(pLogpal->palPalEntry));
 m_pPalette = new CPalette;
 m_pPalette -> CreatePalette( pLogpal );
 delete []pLogpal;
 dcMem.DeleteDC();
 dcscreen.DeleteDC();
}
Exemplo n.º 5
0
void CMFCDCView::OnDcCdc() 
{
	// TODO: Add your command handler code here
	CDC dc;
	dc.CreateDC("DISPLAY",NULL,NULL,NULL);
	//输出信息
	dc.TextOut(100,100,"Hello CDC");
	dc.DeleteDC();
}
Exemplo n.º 6
0
void COptionTreeFontSel::ConvertFont(LOGFONT &lf, CHARFORMAT &cfFont)
{
	// Declare variables
	CDC dc;
	dc.CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
	long yPerInch = dc.GetDeviceCaps(LOGPIXELSY);


	// Create log font
	// -- Font name
	lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
	lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
	lf.lfQuality = DEFAULT_QUALITY;
	lf.lfPitchAndFamily = cfFont.bPitchAndFamily;
	_tcscpy(lf.lfFaceName, cfFont.szFaceName);
	// -- Size
	lf.lfHeight = abs(((cfFont.yHeight * yPerInch) / 1440));
	lf.lfWidth = 0;
	lf.lfEscapement = 0;
	// -- Bold
	if (cfFont.dwEffects & CFE_BOLD)
	{
		lf.lfWeight = FW_BOLD;
	}
	else
	{
		lf.lfWeight = FW_NORMAL;
	}
	// -- Strikeout
	if (cfFont.dwEffects & CFE_STRIKEOUT)
	{
		lf.lfStrikeOut = TRUE;
	}
	else
	{
		lf.lfStrikeOut = FALSE;
	}
	// -- Underline
	if (cfFont.dwEffects & CFE_UNDERLINE)
	{
		lf.lfUnderline = TRUE;
	}
	else
	{
		lf.lfUnderline = FALSE;
	}
	// -- Italic
	if (cfFont.dwEffects & CFE_ITALIC)
	{
		lf.lfItalic = TRUE;
	}
	else
	{
		lf.lfItalic = FALSE;
	}
}
// Protected member functions
BOOL COXScreenGrabber::PrepareWindow(BOOL bClient, CRect& ScrRect, CWnd* pWnd)
{
	if (pWnd == NULL)
		pWnd = CWnd::GetForegroundWindow();
	if (pWnd == NULL)
		pWnd = CWnd::GetDesktopWindow();

	ASSERT(pWnd != NULL);
	if (!pWnd->IsWindowVisible())
		return FALSE;

	if (pWnd == CWnd::GetDesktopWindow())
	{
		// create a DC for the screen and create
		CDC SreenDC;
		if (!SreenDC.CreateDC(_T("DISPLAY"), NULL, NULL, NULL))
			return FALSE;

		// get screen resolution and set Rect
		ScrRect.left = 0;
		ScrRect.top = 0;
		ScrRect.right = SreenDC.GetDeviceCaps(HORZRES);
		ScrRect.bottom = SreenDC.GetDeviceCaps(VERTRES);

		SreenDC.DeleteDC();
	}
	else
	{
		// Move window which was selected to top of Z-order for
		// the capture, and make it redraw itself
		pWnd->SetWindowPos(NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE);
		pWnd->UpdateWindow();

		if (bClient)
		{
			// get the client area dimensions
			pWnd->GetClientRect(&ScrRect);

			// convert client coords to screen coords
			CPoint pt1(ScrRect.left, ScrRect.top); 
			CPoint pt2(ScrRect.right, ScrRect.bottom); 

			pWnd->ClientToScreen(&pt1);
			pWnd->ClientToScreen(&pt2);

			ScrRect.left = pt1.x;
			ScrRect.top = pt1.y;
			ScrRect.right = pt2.x;
			ScrRect.bottom = pt2.y;
		}
		else
			pWnd->GetWindowRect(&ScrRect);
	}

	return TRUE;
}
Exemplo n.º 8
0
KernelBitmap* SGNameDrag::MakeImage(UINT32 nDepth)
{
	// If there's no current View, or no Spread, then fail.
	DocView* pView = DocView::GetCurrent();
	if (pView == 0) return 0;
	Spread* pSpread = pView->FindEnclosingSpread(OilCoord(0, 0));
	if (pSpread == 0) return 0;

	// Create a device context for the display.
	CDC sdc;
	sdc.CreateDC("DISPLAY", 0, 0, 0); 

	// Calculate the size of the rendering and set up the rendering matrix etc.
	Matrix matConvert;
	FIXED16 fxScale = 1;
	INT32 nSel = NameGallery::Instance()->GetSelectedItemCount();
	DocRect drClip(0, 0, SG_DefaultNameText, nSel * SG_DefaultSmallIcon);

	// Work out the destination bitmap's characteristics.
	double dpi = (double) GetDeviceCaps(sdc.m_hDC, LOGPIXELSX);
	if (nDepth == 0)
			nDepth = GetDeviceCaps(sdc.m_hDC, BITSPIXEL) * GetDeviceCaps(sdc.m_hDC, PLANES);

	// Create a render region with the given properties of the display etc.
	GRenderBitmap* pRenderer = new GRenderBitmap(drClip, matConvert, fxScale, nDepth, dpi);
	ERRORIF(pRenderer == 0, _R(IDE_NOMORE_MEMORY), 0);
	pRenderer->AttachDevice(pView, &sdc, pSpread);
	pRenderer->StartRender();
	pRenderer->SaveContext();

	// Blank the background.
	pRenderer->SetLineWidth(0);
	pRenderer->SetLineColour(COLOUR_WHITE);
	pRenderer->SetFillColour(COLOUR_WHITE);
	pRenderer->DrawRect(&drClip);

	// Render the item's name.
	DocColour dcText(COLOUR_BLACK), dcBack(COLOUR_WHITE);
	pRenderer->SetFixedSystemTextColours(&dcText, &dcBack);

	String_256 strName;
	m_pSourceItem->GetNameText(&strName);
	pRenderer->DrawFixedSystemText(&strName, drClip);

	// Create a kernel bitmap from the OIL bitmap and return it.
	pRenderer->RestoreContext();
	pRenderer->StopRender();
	OILBitmap* pOilMaskBmp = pRenderer->ExtractBitmap();
	delete pRenderer;

	KernelBitmap* pkb = new KernelBitmap(pOilMaskBmp, TRUE);
	ERRORIF(pkb == 0, _R(IDE_NOMORE_MEMORY), 0);
	return pkb;
}
Exemplo n.º 9
0
void COptionTreeFontSel::ConvertFont(CHARFORMAT &cfFont, LOGFONT &lf)
{	
	// Declare variables
	CDC dc;
	dc.CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
	long yPerInch = dc.GetDeviceCaps(LOGPIXELSY);

	// Convert Font
	cfFont.dwMask = CFM_COLOR | CFM_SIZE | CFM_FACE | CFM_UNDERLINE | CFM_BOLD | CFM_ITALIC | CFM_STRIKEOUT;
	cfFont.dwEffects = 0;
	// -- Face
	_tcscpy(cfFont.szFaceName, lf.lfFaceName);
	// -- Pitch and family
	cfFont.bPitchAndFamily = lf.lfPitchAndFamily;
	// -- Size
	cfFont.yHeight = ((1440 / yPerInch) * abs(lf.lfHeight));
	// -- Bold
	if (lf.lfWeight >= FW_BOLD)
	{
		cfFont.dwEffects |= CFE_BOLD;
	}
	// -- Italic
	if (lf.lfItalic == TRUE)
	{
		cfFont.dwEffects |= CFE_ITALIC;
	}
	// -- Underline
	if (lf.lfUnderline == TRUE)
	{
		cfFont.dwEffects |= CFE_UNDERLINE;
	}
	// -- Strikeout
	if (lf.lfStrikeOut == TRUE)
	{
		cfFont.dwEffects |= CFE_STRIKEOUT;
	}
	// -- Character set
	cfFont.bCharSet = lf.lfCharSet;
	cfFont.dwEffects |= CFM_CHARSET;
	// -- Text color
	cfFont.crTextColor = GetTextColor();	
}
Exemplo n.º 10
0
DWORD CFontDialog::FillInLogFont(const CHARFORMAT& cf)
{
	USES_CONVERSION;
	DWORD dwFlags = 0;
	if (cf.dwMask & CFM_SIZE)
	{
		CDC dc;
		dc.CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
		LONG yPerInch = dc.GetDeviceCaps(LOGPIXELSY);
		m_lf.lfHeight = -(int) ((cf.yHeight * yPerInch) / 1440);
	}
	else
		m_lf.lfHeight = 0;

	m_lf.lfWidth = 0;
	m_lf.lfEscapement = 0;
	m_lf.lfOrientation = 0;

	if ((cf.dwMask & (CFM_ITALIC|CFM_BOLD)) == (CFM_ITALIC|CFM_BOLD))
	{
		m_lf.lfWeight = (cf.dwEffects & CFE_BOLD) ? FW_BOLD : FW_NORMAL;
		m_lf.lfItalic = (BYTE)((cf.dwEffects & CFE_ITALIC) ? TRUE : FALSE);
	}
	else
	{
		dwFlags |= CF_NOSTYLESEL;
		m_lf.lfWeight = FW_DONTCARE;
		m_lf.lfItalic = FALSE;
	}

	if ((cf.dwMask & (CFM_UNDERLINE|CFM_STRIKEOUT|CFM_COLOR)) ==
		(CFM_UNDERLINE|CFM_STRIKEOUT|CFM_COLOR))
	{
		dwFlags |= CF_EFFECTS;
		m_lf.lfUnderline = (BYTE)((cf.dwEffects & CFE_UNDERLINE) ? TRUE : FALSE);
		m_lf.lfStrikeOut = (BYTE)((cf.dwEffects & CFE_STRIKEOUT) ? TRUE : FALSE);
	}
	else
	{
		m_lf.lfUnderline = (BYTE)FALSE;
		m_lf.lfStrikeOut = (BYTE)FALSE;
	}

	if (cf.dwMask & CFM_CHARSET)
		m_lf.lfCharSet = cf.bCharSet;
	else
		dwFlags |= CF_NOSCRIPTSEL;
	m_lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
	m_lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
	m_lf.lfQuality = DEFAULT_QUALITY;
	if (cf.dwMask & CFM_FACE)
	{
		m_lf.lfPitchAndFamily = cf.bPitchAndFamily;
		lstrcpy(m_lf.lfFaceName, A2T((LPSTR)cf.szFaceName));
	}
	else
	{
		m_lf.lfPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
		m_lf.lfFaceName[0] = (TCHAR)0;
	}
	return dwFlags;
}
Exemplo n.º 11
0
/***************************************************
PrintInit
	Initializes and sets up the data that needs to
	be calculated to perform the actual print. Such
	tasks include calcualating the number of pages
	required to print the given range, and the scale.
Params
	pDC - device context for the printer (or print preview)
	pPD - pointer to the print dialog information
	startCol- leftmost column to print on the page
	endCol	- rightmost column to print on the page
	startRow- topmost row to print on the page
	endRow	- bottom most row to print on the page
Return
	number of pages that will be printed
****************************************************/
int CUGPrint::PrintInit(CDC * pDC, CPrintDialog* pPD, int startCol,long startRow,
						int endCol,long endRow)
{
	UNREFERENCED_PARAMETER(pPD);

	ClearPrintList();

	//get a screen device context
	CDC	sDC;
	sDC.CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
	
	//check to see if the request if for printing or print preview
	m_bIsPreview = FALSE;
	SIZE size;
	pDC->SetMapMode(MM_ANISOTROPIC);
	SetWindowExtEx(pDC->m_hDC,1,1,&size);
	if(size.cx != 1){
		m_bIsPreview = TRUE;
		SetWindowExtEx(pDC->m_hDC,size.cx,size.cy,&size);
	}
	
	//get the metrics for the printer
	float paperWidthPX		= (float)pDC->GetDeviceCaps(HORZRES);
	float paperHeightPX		= (float)pDC->GetDeviceCaps(VERTRES);
	float paperWidthMM		= (float)pDC->GetDeviceCaps(HORZSIZE);
	float paperHeightMM		= (float)pDC->GetDeviceCaps(VERTSIZE);
	int virtualWidthPX = (int)( 3.79 * (paperWidthMM - m_printLeftMargin - m_printRightMargin));
	int virtualHeightPX = (int)( 3.78 * (paperHeightMM - m_printTopMargin - m_printBottomMargin));

	//save the scaling values
	m_printVScale = ( (paperHeightPX/paperHeightMM) *
					(paperHeightMM - m_printTopMargin - m_printBottomMargin) ) /
					virtualHeightPX;
	m_printHScale = ( (paperWidthPX/paperWidthMM) *
					(paperWidthMM - m_printLeftMargin - m_printRightMargin) ) /
					virtualWidthPX;

	//save the margins
	m_printLeftMarginPX = (int)((paperWidthPX/paperWidthMM) * m_printLeftMargin);
	m_printTopMarginPX = (int)((paperHeightPX/paperHeightMM) * m_printTopMargin);
	m_printRightMarginPX = (int)(paperWidthPX - (paperWidthPX/paperWidthMM) * m_printRightMargin);
	m_printBottomMarginPX = (int)(paperHeightPX - (paperHeightPX/paperHeightMM) * m_printBottomMargin);
	m_paperWidthPX = (int)paperWidthPX;
	m_paperHeightPX = (int)paperHeightPX;

	//if not print preview, then addjust values by the virtual pixel width
	if(m_bIsPreview == FALSE)
	{
		m_virPixWidth = (int)paperWidthPX / 450;  //300
		m_printVScale /= m_virPixWidth;
		m_printHScale /= m_virPixWidth;
		m_printLeftMarginPX /= m_virPixWidth;
		m_printTopMarginPX /= m_virPixWidth;
		m_printRightMarginPX /= m_virPixWidth;
		m_printBottomMarginPX /= m_virPixWidth;
		m_paperWidthPX /= m_virPixWidth;
		m_paperHeightPX /= m_virPixWidth;
	}

	//get the number of pages wide
	int col,width=0,w;
	int scol = startCol;		//start col for a page
	m_pagesWide = 0;
	
	if(m_printSideHeading)
		width = m_ctrl->GetSH_Width();
	//find the number of pages wide and the number of columns
	//on each page
	for(col =startCol;col <= endCol;col++)
	{
		m_ctrl->GetColWidth(col,&w);		
		width += w;
	
		if(width > virtualWidthPX)
		{
			m_pagesWide++;
			if(m_printSideHeading)
				width = m_ctrl->GetSH_Width();
			else
				width = 0;

			if(w < virtualWidthPX)
				col--;

			//add the column info to the list
			AddPageToList(m_pagesWide,scol,col,0,0);
			scol = col+1;
		}
	}
	
	if(width >0)
	{
		m_pagesWide++;
		//add the column info to the list
		if(col > endCol)
			col = endCol;
		AddPageToList(m_pagesWide,scol,col,0,0);
	}

	//get the number of pages high
	long row;
	long srow = startRow;		//start row for page
	int height=0,h;
	m_pagesHigh = 0;
	
	if(m_printTopHeading)
		height = m_ctrl->GetTH_Height();

	//find the number of pages high and the number of rows
	//on each page
	for(row = startRow;row <=endRow;row++)
	{
		m_ctrl->GetRowHeight(row,&h);
		height += h;
		if(height > virtualHeightPX)
		{
			m_pagesHigh ++;
			if(m_printTopHeading)
				height = m_ctrl->GetTH_Height();
			else 
				height = 0;

			if(h < virtualHeightPX)
				row--;
			
			//add the page information to the list
			int c1,c2;
			long r1,r2;
			int page;
			for(col =1;col<=m_pagesWide;col++)
			{
				//get the col info
				GetPageFromList(col,&c1,&c2,&r1,&r2);
				//update the page info
				page = (m_pagesHigh-1)*m_pagesWide +col;
				AddPageToList(page,c1,c2,srow,row);
			}
			srow = row+1;
		}
	}
	if(height >0)
	{
		m_pagesHigh++;
		//add the page information to the list
		int c1,c2;
		long r1,r2;
		int page;
		for(col =1;col<=m_pagesWide;col++)
		{
			//get the col info
			GetPageFromList(col,&c1,&c2,&r1,&r2);
			//update the page info
			page = (m_pagesHigh-1)*m_pagesWide +col;
			if(row > endRow)
				row = endRow;
			AddPageToList(page,c1,c2,srow,row);
		}
	}

	//return the number of pages in total
	return (m_pagesWide * m_pagesHigh);
}
Exemplo n.º 12
0
BOOL CScreenSnap::GetScreenData(BYTE* pScreenData,DWORD &dwScreenData)
{
	CDC dc;
	dc.CreateDC("DISPLAY",NULL,NULL,NULL);
	CheckPointer(dc.GetSafeHdc(),FALSE);
	
	CBitmap bm;
	int nWidth	= GetSystemMetrics(SM_CXSCREEN);
	int nHeight	= GetSystemMetrics(SM_CYSCREEN);
	if(!bm.CreateCompatibleBitmap(&dc,nWidth,nHeight))
	{
		dc.DeleteDC();
		return FALSE;
	}

	CDC tdc;
	if(!tdc.CreateCompatibleDC(&dc))
	{
		dc.DeleteDC();
		return FALSE;
	}

	CBitmap*pOld = tdc.SelectObject(&bm);
	if(pOld == NULL)
	{
		tdc.DeleteDC();
		dc.DeleteDC();
		return FALSE;
	}

	tdc.BitBlt(0,0,nWidth,nHeight,&dc,0,0,SRCCOPY);
	tdc.SelectObject(pOld);
	
	BITMAP btm;
	bm.GetBitmap(&btm);
	DWORD nSize  = btm.bmWidthBytes * btm.bmHeight;
//	LPSTR lpData = (LPSTR)GlobalAllocPtr(GPTR,nSize);
//	if(lpData == NULL)
//	{
//		tdc.DeleteDC();
//		dc.DeleteDC();
//		return FALSE;
//	}

	//--------------------------------------------------------

	BITMAPINFOHEADER bih;
	bih.biBitCount		= btm.bmBitsPixel;
	bih.biClrImportant	= 0;
	bih.biClrUsed		= 0;
	bih.biCompression	= 0;
	bih.biHeight		= btm.bmHeight;
	bih.biPlanes		= 1;
	bih.biSize			= sizeof(BITMAPINFOHEADER);
	bih.biSizeImage		= nSize;
	bih.biWidth			= btm.bmWidth;
	bih.biXPelsPerMeter	= 0;
	bih.biYPelsPerMeter	= 0;

	//--------------------------------------------------------
	//得到DIB色彩表
	if(!GetDIBits(dc,bm,0,bih.biHeight,(pScreenData + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)),(BITMAPINFO*)&bih,DIB_RGB_COLORS))
	{
		tdc.DeleteDC();
		dc.DeleteDC();
		return FALSE;
	}
		
	//--------------------------------------------------------
	
	BITMAPFILEHEADER bfh;
	bfh.bfReserved1	= bfh.bfReserved2 = 0;
	bfh.bfType		= ((WORD)('M'<< 8)|'B');
	bfh.bfSize		= 54 + nSize;
	bfh.bfOffBits	= 54;
	
	memcpy(pScreenData,&bfh,sizeof(BITMAPFILEHEADER));
	dwScreenData = sizeof(BITMAPFILEHEADER);
	
	memcpy(pScreenData + dwScreenData,&bih,sizeof(BITMAPINFOHEADER));
	dwScreenData += sizeof(BITMAPINFOHEADER);
	
//	memcpy(pScreenData,lpData,nSize);
	dwScreenData += nSize;

//	GlobalFreePtr(lpData);

	tdc.DeleteDC();
	dc.DeleteDC();

	return TRUE;
}
Exemplo n.º 13
0
void CLogiTextGate::Draw(CDC* pDC, CLogiView* pView)
   {
   ASSERT_VALID(this);

   // Draw the Bitmap Portion

   if (m_iStyle == 1)
      {
      CRect crBackup = m_position;
      CSize csBackup = m_size;

      m_position = CRect(m_position.TopLeft(), CSize(BITX_TXT, -BITY_TXT));
      m_size = CSize(BITX_TXT, BITY_TXT);

      CLogiGate::Draw(pDC, pView);

      m_position = crBackup;
      m_size     = csBackup;
      }

   // if printing build a bitmap on the fly for the Text.

   if (pDC->IsPrinting() || m_pDocument->m_iZoom)
      {
      CDC MemDC;

      MemDC.CreateCompatibleDC(NULL);

      pOldFont = MemDC.SelectObject(&m_pDocument->m_cfScreen);
      pOldPen = MemDC.SelectObject(&m_pDocument->m_cpBlack);
      pOldBrush = MemDC.SelectObject(&m_pDocument->m_cbWhite);
      int oldBkMode = MemDC.SetBkMode(TRANSPARENT);
      COLORREF oldTextColor = MemDC.SetTextColor(RGB(0, 0, 0));

      // calculate the surrounding rectangle of the text only

      CSize csExtent;

      if (m_bLoaded)
         {
         csExtent = MemDC.GetTextExtent( m_pTextArray[m_uIndex], m_pTextArray[m_uIndex].GetLength() ) + CSize(4,4);
         }
      else
         {
         csExtent = MemDC.GetTextExtent( m_pTextText, m_pTextText.GetLength() ) + CSize(4,4);
         }

      MemDC.GetTextMetrics(&tm);
      if (tm.tmItalic) csExtent += CSize(tm.tmHeight/4,0);

      // crate a temperary bitmap to draw the text to (can't be MemDC?)

      CBitmap cbGate;

      CDC screenDC;
      screenDC.CreateDC(L"DISPLAY", NULL, NULL, NULL);
      cbGate.CreateCompatibleBitmap(&screenDC, csExtent.cx, csExtent.cy);
      screenDC.DeleteDC();

      pOldBmp = MemDC.SelectObject(&cbGate);

      // draw rectangle also inits bitmap with brush

      MemDC.Rectangle(CRect(CPoint(0,0),csExtent));

      // draw text

      if (m_bLoaded)
         {
         MemDC.TextOut(2, 2, m_pTextArray[m_uIndex], m_pTextArray[m_uIndex].GetLength());
         }
      else
         {
         MemDC.TextOut(2, 2, m_pTextText, m_pTextText.GetLength());
         }

      MemDC.SelectObject(pOldPen);
      MemDC.SelectObject(pOldBrush);
      MemDC.SetTextColor(oldTextColor);
      MemDC.SetBkMode(oldBkMode);
      MemDC.SelectObject(pOldFont);
      MemDC.SelectObject(pOldBmp);

      // build a DIB from the bitmap

      m_Bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
      m_Bmi.bmiHeader.biHeight = csExtent.cy;
      m_Bmi.bmiHeader.biWidth = csExtent.cx;
      m_Bmi.bmiHeader.biPlanes = 1;
      m_Bmi.bmiHeader.biBitCount = 4;
      m_Bmi.bmiHeader.biCompression = BI_RGB;
      m_Bmi.bmiHeader.biSizeImage = 0;
      m_Bmi.bmiHeader.biXPelsPerMeter = 0;
      m_Bmi.bmiHeader.biYPelsPerMeter = 0;
      m_Bmi.bmiHeader.biClrUsed = 16;
      m_Bmi.bmiHeader.biClrImportant = 16;

      if(!::GetDIBits(MemDC.GetSafeHdc(), (HBITMAP) cbGate.m_hObject, 0, (UINT) m_Bmi.bmiHeader.biHeight, NULL, (LPBITMAPINFO) &m_Bmi, DIB_RGB_COLORS)) return;

      if (m_Bmi.bmiHeader.biSizeImage == 0) return;

      LPBYTE lpImage = (LPBYTE) new char[m_Bmi.bmiHeader.biSizeImage];
      ::GetDIBits(MemDC.GetSafeHdc(), (HBITMAP) cbGate.m_hObject, 0, (UINT) m_Bmi.bmiHeader.biHeight, lpImage, (LPBITMAPINFO) &m_Bmi, DIB_RGB_COLORS);

      MemDC.DeleteDC();

      // determine where to draw the dib

      CPoint origin;

      if (m_iStyle == 1)
         {
         origin = CPoint(m_position.left+(BITX_TXT-1), m_position.top-csExtent.cy);
         }
      else
         {
         origin = CPoint(m_position.left, m_position.bottom);
         }

      // draw it

      ::StretchDIBits(pDC->GetSafeHdc(), origin.x, origin.y, csExtent.cx, csExtent.cy, 0, 0, m_Bmi.bmiHeader.biWidth, m_Bmi.bmiHeader.biHeight, lpImage, (LPBITMAPINFO) &m_Bmi, DIB_RGB_COLORS, SRCCOPY);

      delete [] lpImage;
      }

   // Else not printing do direct

   else
      {
      pOldPen = pDC->SelectObject(&m_pDocument->m_cpBlack);
      pOldFont = pDC->SelectObject(&m_pDocument->m_cfScreen);
      pOldBrush = pDC->SelectObject(&m_pDocument->m_cbWhite);
      int oldBkMode = pDC->SetBkMode(TRANSPARENT);
      COLORREF oldTextColor = pDC->SetTextColor(RGB(0, 0, 0));

      // calculate the surrounding rectangle of text only

      CSize csExtent;

      if (m_bLoaded)
         {
         csExtent = pDC->GetTextExtent(m_pTextArray[m_uIndex], m_pTextArray[m_uIndex].GetLength() ) + CSize(4,4);
         }
      else
         {
         csExtent = pDC->GetTextExtent(m_pTextText, m_pTextText.GetLength() ) + CSize(4,4);
         }

      pDC->GetTextMetrics(&tm);
      if (tm.tmItalic) csExtent += CSize(tm.tmHeight/4,0);

      // determine where to draw things

      CPoint origin;

      if (m_iStyle == 1)
         {
         origin = CPoint(m_position.left+(BITX_TXT-1), m_position.top-csExtent.cy);
         }
      else
         {
         origin = CPoint(m_position.left, m_position.bottom);
         }

      pDC->Rectangle(CRect(origin,csExtent));

      if (m_bLoaded)
         {
         pDC->TextOut(origin.x+2, origin.y+2, m_pTextArray[m_uIndex], m_pTextArray[m_uIndex].GetLength());
         }
      else
         {
         pDC->TextOut(origin.x+2, origin.y+2, m_pTextText, m_pTextText.GetLength());
         }

      pDC->SelectObject(pOldFont);
      pDC->SelectObject(pOldPen);
      pDC->SetTextColor(oldTextColor);
      pDC->SelectObject(pOldBrush);
      pDC->SetBkMode(oldBkMode);
      }
   }