void CGDIDlg::OnLoadFile()
{
CBitmap bmp;
bmp.LoadBitmap(IDB_MYBMP);
//假设是在一个CWnd派生类的成员函数中
CClientDC dc(this);
CDC memdc;
memdc.CreateCompatibleDC(&dc);
CBitmap *oldbmp=memdc.SelectObject(&bmp);
dc.BitBlt(0,0,100,100,&memdc,0,0,SRCCOPY);
if(oldbmp)
memdc.SelectObject(oldbmp);
}
void CGDIDlg::OnLoadIi()
{
// TODO: Add your command handler code here
CBitmap bmp;
bmp.LoadBitmap(IDB_MYBMP);
CClientDC dc(this);
dc.DrawState(CPoint(0,0),CSize(200,200),&bmp,DST_BITMAP);
}
//#include "GDI.h"
//extern CGDIApp theApp;
void CGDIDlg::OnLoadIii()
{
//从资源Load一个位图,如果从文件load的话,可以使用::LoadImage()
HINSTANCE hInstance=AfxGetApp()->m_hInstance; //theApp.m_hInstance;
HBITMAP hbmp=::LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_MYBMP));
//Win32 API的版本:
//假设位图大小为100*100像素
//假设hwnd是要绘制的窗口的HANDLE
HWND hwnd=this->m_hWnd;
HDC hwnddc=::GetDC(hwnd);//HDC GetDC(HWND hWnd)
HDC memdc=::CreateCompatibleDC(hwnddc);
HBITMAP oldbmp=(HBITMAP)::SelectObject(memdc,hbmp);
::BitBlt(hwnddc,0,0,100,100,memdc,0,0,SRCCOPY);
if(oldbmp)
::SelectObject(memdc,oldbmp);
DeleteDC(memdc);
::ReleaseDC(hwnd,hwnddc);
}