FAQ200412: How to display JPG files in a static Picture control

xiaoxiao2021-03-06  41

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 = loading (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 = :: GMEM_MOVEABLE, DWSIZE

LPVOID LPJGP = :: Globalock (hjpg);

Memcpy (LPJGP, LPDATA, DWSIZE);

:: GlobalUnlock (hjpg);

// lpvoid pvdata = Globalock (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 (ac) && 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);

转载请注明原文地址:https://www.9cbs.com/read-75225.html

New Post(0)