在Onpaint中调用 CWnd *pWnd;
pWnd = GetDlgItem(IDC_Img);
ShowBitmap(pWnd);然后再ShowBitmap中填充Img区域,再拷贝一个位图,但是位图重绘有问题。
另外,怎么得到对话框的hInstance来load位图,可以这么用吗?
hBmp=LoadBitmap(theApp.m_hInstance,"MyBitmap");
BOOL ShowBitmap::ShowBitmap(CWnd *pWnd)
{
HANDLE  hBmp;           
HDC   hBitmapDC;
HDC hMemDC;
PAINTSTRUCT  PtrStr;
    int bitmapWidth=266;
    int  bitmapHeight=64;
HGDIOBJ  prevObject;
HBRUSH  fill;
HDC  hdcRect;

CRect rect; pWnd->GetClientRect(&rect); hdcRect=::GetDC(pWnd->m_hWnd);
fill=CreateSolidBrush(0xFFFFFF);        // Select white brush
prevObject=SelectObject(hdcRect,fill);
FillRect(hdcRect,&rect,fill);           // Paint white rect
SelectObject(hdcRect,prevObject);
DeleteObject(fill);
::ReleaseDC(pWnd->m_hWnd,hdcRect); hBmp=LoadBitmap(theApp.m_hInstance,"MyBitmap");
hBitmapDC=::BeginPaint(pWnd->m_hWnd,&PtrStr);
hMemDC=CreateCompatibleDC(hBitmapDC);
SelectObject(hMemDC,hBmp);

//Place Bitmap in center of paint area
BitBlt(hBitmapDC,
rect.left,  // x
rect.top,    // y
bitmapWidth,                                 // width
bitmapHeight,                                // height
hMemDC,0,0,SRCCOPY);
DeleteDC(hMemDC);
::EndPaint(pWnd->m_hWnd,&PtrStr); return true;
}