ATL中使用點陣圖資源繪圖

sinall發表於2005-05-30

 HRESULT OnDraw(ATL_DRAWINFO& di)
 {
  AFX_MANAGE_STATE(AfxGetStaticModuleState());

  RECT& rc = *(RECT*)di.prcBounds;
  HBITMAP hbmp=::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_TEST));
  BITMAP bm;         //點陣圖物件結構
  GetObject(hbmp,sizeof(BITMAP),&bm);      //返回hbitmap所指點陣圖的基本資訊到結構物件bm裡
  long width=bm.bmWidth;
  long height=bm.bmHeight;  
  HDC hdc=::CreateCompatibleDC(NULL);
  HGDIOBJ hOld=::SelectObject(hdc,hbmp);
  ::BitBlt(di.hdcDraw,rc.left,rc.top,width,height,hdc,0,0,SRCCOPY);
  ::SelectObject(hdc,hOld);

  return S_OK;
 }

相關文章