CSDN博客

img kugou123

FAQ200412:怎么在一个静态Picture控件中显示JPG文件

发表于2004/12/29 15:55:00  877人阅读

分类: 界面

my  example:  
HBITMAP  CPicture::LoadImageFromID(UINT  nIDRes)  
{  
           try  
           {  
                       HMODULE  hInst=GetModuleHandle(NULL);  
                       LPCTSTR  lpRes  =  MAKEINTRESOURCE(nIDRes);  
                       HRSRC  hRsrc  =  ::FindResource(hInst,  lpRes,  "JPG");  
                       if  (NULL  ==  hRsrc)  
                                   return  FALSE;  
                         
                       HGLOBAL  hGlobal  =  LoadResource(hInst,  hRsrc);  
                       if  (NULL  ==  hGlobal)  
                                   return  FALSE;  
                         
                       DWORD  dwSize  =  SizeofResource(hInst,  hRsrc);  
                       LPVOID  lpData  =  LockResource(hGlobal);  
                       if  (NULL  ==  lpData)  
                                   return  FALSE;  
                         
                       //  alloc  memory  based  on  file  size  
                       HGLOBAL  hJPG  =  ::GlobalAlloc(GMEM_MOVEABLE,  dwSize);  
                       LPVOID  lpJGP  =  ::GlobalLock(hJPG);  
                       memcpy(lpJGP,  lpData,  dwSize);  
                       ::GlobalUnlock(hJPG);  
                         
                       //LPVOID  pvData  =  GlobalLock(hGlobal);  
                       //_ASSERTE(NULL  !=  pvData);  
                         
                       //  read  file  and  store  in  global  memory  
                         
                       LPSTREAM  pstm  =  NULL;  
                       //  create  IStream*  from  global  memory  
                       HRESULT  hr  =  CreateStreamOnHGlobal(hJPG,  TRUE,  &pstm);  
                       _ASSERTE(SUCCEEDED(hr)  &&  pstm);  
                         
                       //  Create  IPicture  from  image  file  
                       LPPICTURE  gpPicture;  
                         
                       hr  =  ::OleLoadPicture(pstm,  dwSize,  FALSE,  IID_IPicture,  (LPVOID  *)&gpPicture);  
                       _ASSERTE(SUCCEEDED(hr)  &&  gpPicture);              
                       pstm->Release();  
                         
                       OLE_HANDLE  m_picHandle;  
                         
                       gpPicture->get_Handle(&m_picHandle);  
                       return  (HBITMAP)m_picHandle;  
           }  
           catch  (...)  
           {  
 
           }  
           return  NULL;  
}  
//call    
           CPicture  pic;    
           HBITMAP  hbmp=pic.LoadImageFromID(IDR_TODAY);//IDR_TODAY  is  jpg  id  
           (HBITMAP)::SendMessage(::GetDlgItem(this->m_hWnd,IDC_TODAY),  STM_SETIMAGE,  IMAGE_BITMAP,  (LPARAM)hbmp);  
阅读全文
0 0

相关文章推荐

img
取 消
img