void COpenSaveAcessView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC* pDC;
pDC=GetDC();
COpenSaveAcessDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if(pDoc->m_pDib==NULL)
return;
BITMAPINFOHEADER *infoHead=(BITMAPINFOHEADER*)pDoc->m_pDib;
int width=infoHead->biWidth;
int height=infoHead->biHeight;
int biBitCount=infoHead->biBitCount;
int colorTableLng;
if(biBitCount!=24)//看了书
colorTableLng=(int)pow(2,biBitCount);
else
colorTableLng=0;
HPALETTE hPalette=0,hOldPal;
if(colorTableLng!=0){
RGBQUAD *pColorTable=(RGBQUAD*)(pDoc->m_pDib+sizeof(BITMAPINFOHEADER));
LPLOGPALETTE lpColorTable=(LPLOGPALETTE)new char[2*sizeof(WORD)+
sizeof(PALETTEENTRY)*colorTableLng];//RGBQUAD 可以互换PALETTEENTRY
lpColorTable->palVersion=0x300;
lpColorTable->palNumEntries=colorTableLng;
for(int i=0;i<colorTableLng;i++){
lpColorTable->palPalEntry[i].peBlue=pColorTable[i].rgbBlue;
lpColorTable->palPalEntry[i].peGreen=pColorTable[i].rgbGreen;
lpColorTable->palPalEntry[i].peRed=pColorTable[i].rgbRed;
lpColorTable->palPalEntry[i].peFlags=0;
}
hPalette=::CreatePalette(lpColorTable);//看了书
hOldPal=::SelectPalette(pDC->GetSafeHdc(),hPalette,TRUE);
pDC->RealizePalette();
delete []lpColorTable;
}
pDC->SetStretchBltMode(COLORONCOLOR);
unsigned char *pImgData=(unsigned char *)(pDoc->m_pDib+
sizeof(BITMAPINFOHEADER)+
sizeof(RGBQUAD)*colorTableLng);//看了书
::StretchDIBits(pDC->GetSafeHdc(), m_ptOrigin.x, m_ptOrigin.y,
point.x-m_ptOrigin.x,point.y-m_ptOrigin.y,
m_ptOrigin.x, m_ptOrigin.y,
point.x-m_ptOrigin.x,point.y-m_ptOrigin.y,
pImgData/*注意这里*/,
(LPBITMAPINFO/*注意这里*/)pDoc->m_pDib,
DIB_RGB_COLORS,SRCCOPY);
if(hOldPal!=NULL)
::SelectPalette(pDC->GetSafeHdc(),hOldPal,TRUE);
CView::OnLButtonUp(nFlags, point);
}