strechblt 画图有关问题

strechblt 画图问题
小弟想用strechblt 画出数组color里的8位灰度图像数据,未遂……请教大虾……代码如下:

void CShow_pic2Dlg::DrawImg(CDC *pDC, int x, int y)
{
int color[16][16]={
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128},
{256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128},
{256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128},
{256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128},
{256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128},
{256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
int imgWidth=16,imgHeight=16;
char __bif[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256]; 
BITMAPINFO& bif = *(BITMAPINFO*)__bif; 
bif.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
bif.bmiHeader.biWidth = imgWidth;  
bif.bmiHeader.biHeight = imgHeight;  
bif.bmiHeader.biPlanes = 1;  
bif.bmiHeader.biBitCount = 8; 
bif.bmiHeader.biCompression = BI_RGB;  
bif.bmiHeader.biSizeImage = 0;  
bif.bmiHeader.biXPelsPerMeter = 96;  
bif.bmiHeader.biYPelsPerMeter = 96;  
bif.bmiHeader.biClrUsed = 0;  
bif.bmiHeader.biClrImportant = 0;  
for(int i = 0; i < 256; ++i) 

int b = i; 
bif.bmiColors[i].rgbBlue = b; 
bif.bmiColors[i].rgbGreen = b; 
bif.bmiColors[i].rgbRed = b; 
bif.bmiColors[i].rgbReserved = 0; 


StretchDIBits(*pDC, x, y + imgHeight-1, imgWidth, -imgHeight,  
0,0, imgWidth, imgHeight, color, 
(BITMAPINFO*)&bif, DIB_RGB_COLORS , SRCCOPY); 
}

void CShow_pic2Dlg::OnButton2() 
{
// HWND hWnd = AfxGetMainWnd()-> m_hWnd;
// CDC* pdc; //CDC是一个类,用于封装hDc
// HDC hDC= ::GetDC(hWnd);
CPaintDC dc(this);
CDC *pDC=&dc;
DrawImg(pDC, 0 , 0);
}

------解决方案--------------------
CPaintDC dc(this);
 CDC *pDC=&dc;
 DrawImg(pDC, 0 , 0);
-->
CDC* pDC = GetDC();
 DrawImg(pDC, 0 , 0);
ReleaseDC(pDC);

CPaintDC不能用在这里
A CPaintDC object can only be used when responding to a WM_PAINT message, usually in your OnPaint message-handler member function.