::
::
::
::
::
//利用资源文件
void CBitmap1View::OnPaint()


{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CBitmap BmpLady;
CDC MemDCLady;

// Load the bitmap from the resource
BmpLady.LoadBitmap(IDB_LADY);
// Create a memory device compatible with the above CPaintDC variable
MemDCLady.CreateCompatibleDC(&dc);
// Select the new bitmap
CBitmap *BmpPrevious = MemDCLady.SelectObject(&BmpLady);

// Copy the bits from the memory DC into the current dc
dc.BitBlt(20, 10, 436, 364, &MemDCLady, 0, 0, SRCCOPY);

// Restore the old bitmap
dc.SelectObject(BmpPrevious);
// Do not call CView::OnPaint() for painting messages
}

//从文件获得
void CDialog1Dlg::OnPaint()


{
CPaintDC dc(this); // device context for painting

if (IsIconic())

{
SendMessage(WM_ICONERASEBKGND,
reinterpret_cast<WPARAM>(dc.GetSafeHdc()),
0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else

{
CDialog::OnPaint();
}
HBITMAP bmpHandle = (HBITMAP)LoadImage(NULL,
strPictureName,
IMAGE_BITMAP,
0,
0,
LR_LOADFROMFILE);
CBitmap bmpPicture;
CDC mdcPicture;
CBitmap *bmpFromHandle = bmpPicture.FromHandle(bmpHandle);

CRect rctPicture;
m_Picture.GetWindowRect(&rctPicture);
mdcPicture.CreateCompatibleDC(&dc);
CBitmap * bmpPrevious = mdcPicture.SelectObject(bmpFromHandle);

ScreenToClient(&rctPicture);

dc.BitBlt(rctPicture.left, rctPicture.top,
rctPicture.Width(), rctPicture.Height(),
&mdcPicture, 0, 0, SRCCOPY);

dc.SelectObject(bmpPrevious);
DeleteObject(bmpHandle);
}

//在视图类中处理
void CShowPicture1View::OnFileOpen()


{
// TODO: Add your command handler code here

TCHAR strFilter[] =
{ TEXT("Picture Files (*.bmp)|*.bmp||") };
CFileDialog dlg(TRUE, TEXT(".bmp"), NULL, 0, strFilter);

if( dlg.DoModal() == IDOK )

{
strFilename = dlg.GetFileName();
Invalidate();
}
}
void CShowPicture1View::OnDraw(CDC* pDC)


{
CShowPicture1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;

// TODO: add draw code for native data here
if( strFilename != "" )

{
BITMAP bmpProperties;

// Create a bitmap handle using the name of the file
HBITMAP bmpHandle = (HBITMAP)LoadImage(NULL,
strFilename,
IMAGE_BITMAP,
0,
0,
LR_LOADFROMFILE);

CBitmap bmpPicture;
CDC mdcPicture;

// Convert the Win32 bitmap handle into an MFC bitmap object
CBitmap *bmpFromHandle = bmpPicture.FromHandle(bmpHandle);
bmpPicture.Attach(bmpHandle);

// Call the Win32 GetObject() function to get the properties
// of the bitmap and store them in a BITMAP structure
::GetObject(bmpPicture,
sizeof(bmpProperties),
&bmpProperties);

// Create a compatible device context
mdcPicture.CreateCompatibleDC(pDC);
// Select the bitmap into the device context
CBitmap * bmpPrevious =
mdcPicture.SelectObject(bmpFromHandle);

// Using the dimensions store in the BITMAP object,
// display the picture
pDC->BitBlt(0, 0,
bmpProperties.bmWidth, bmpProperties.bmHeight,
&mdcPicture, 0, 0, SRCCOPY);

// Get the dimensions of the new picture
SIZE sizeTotal;
sizeTotal.cx = bmpProperties.bmWidth;
sizeTotal.cy = bmpProperties.bmHeight;
// Change the scrolling area/dimensions of the view
SetScrollSizes(MM_TEXT, sizeTotal);

// Restore the bitmap
pDC->SelectObject(bmpPrevious);
// Delete the Win32 bitmap handle
DeleteObject(bmpHandle);
}
}
void CCView4View::OnDraw(CDC* pDC)


{
CCView4Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

CBitmap Bmp;
CBrush brBits;

WORD wBits[] =
{ 0x00, 0x22, 0x44, 0x88, 0x00, 0x22, 0x44, 0x88,
0x22, 0x44, 0x88, 0x00, 0x22, 0x44, 0x88, 0x00,
0x44, 0x88, 0x00, 0x22, 0x44, 0x88, 0x00, 0x22,
0x88, 0x00, 0x22, 0x44, 0x88, 0x00, 0x22, 0x44 };

Bmp.CreateBitmap(32, 32, 1, 1, wBits);

brBits.CreatePatternBrush(&Bmp);
CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&brBits);

pDC->Rectangle(20, 20, 400, 400);

pDC->SelectObject(&Bmp);
}
posted on
2007-06-20 18:34
tivoli_chen
阅读(
391)
评论()
收藏
举报