EVC打开bmp文件

来源:互联网 发布:商家怎么报名淘宝试用 编辑:程序博客网 时间:2024/04/29 22:55

 

 

void CDrawView::OnDraw(CDC* pDC)
{
    CDrawDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;

    if (bmpstate==1)
     {
        if (0 == extname.Compare(_T("bmp")))
  {
          ShowBitmap(pDC,BmpName);
  }
     }

 

void CDrawView::OnFileOpen()
{
 // TODO: Add your command handler code here
  CFileDialog dlg(TRUE,_T("BMP"),_T("*.BMP"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,_T("BitMapFile(*.BMP)|*.BMP|"));  
     if (IDOK==dlg.DoModal())
     {
         bmpstate=1;
         BmpName.Format(_T("%s"),dlg.GetPathName());
         extname = dlg.GetFileExt();
   extname.MakeLower();
   redo=undo=0;
         Invalidate();
     }
}

void CDrawView::ShowBitmap(CDC* pDC,CString BmpName)
{
 CClientDC DC(this);
   if (bmpstate==1)
     {            
         m_bitmap.Detach();
         m_bitmap.Attach(SHLoadDIBitmap(BmpName));
         bmpstate=0;
   BITMAP bmpInfo;
         m_bitmap.GetBitmap(&bmpInfo);
         CDC bitmapDC;
         bitmapDC.CreateCompatibleDC(&DC);
         CBitmap* pOldBitmap = bitmapDC.SelectObject(&m_bitmap);
   DC.BitBlt(0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, &bitmapDC,0, 0, SRCCOPY);     
         bitmapDC.SelectObject(pOldBitmap);
         m_bitmap.DeleteObject();
     }
}

原创粉丝点击