Click here to Skip to main content
15,867,756 members
Articles / Mobile Apps / Windows Mobile

Loading images with an undocumented API in PPC 2002

Rate me:
Please Sign up or sign in to vote.
4.72/5 (16 votes)
12 Aug 2002CPOL 169.8K   25   35
This article describes an undocumented API that enables you to load images (bmp, gif etc.) from files under Pocket PC 2002

Introduction

Loading images under windows can always be a painful process, especially if the image formats are like JPEG, GIF or PNG. There's always the Imgdecmp library, that does a good job, but its also a bit of a bother with the documentation being so thin and all that. The other day I was trying to load a bitmap from my device using LoadImage, but somehow I kept getting the dreaded "The handle is invalid" error. So I did a search on the MFC code that ships with the PPC SDK in hope of finding a piece of code that will help me solve the puzzle. 

One thing led to another. I suddenly came across HBITMAP SHLoadImageFile(LPCTSTR pszFileName) in aygshell.h. Bingo! I had suddenly uncovered an undocumented API! No trace of it in MSDN, a search in Google produced nothing!! Since then, I've tried this API with gif's and bmp's also and I guess it will work fine for jpeg's and png's too. Here's a code sample...

// assuming code is in the OnDraw method of a view....

CBitmap bitmap;

// Attach the bitmap object to the HBITMAP returned by SHLoadImageFile
bitmap.Attach(SHLoadImageFile(_T("/My Documents/mcdonalds.gif")));

BITMAP bmpInfo;
bitmap.GetBitmap(&bmpInfo);

CDC bitmapDC;
bitmapDC.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = bitmapDC.SelectObject(&bitmap);

pDC->BitBlt(0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, &bitmapDC, 
            0, 0, SRCCOPY);

bitmapDC.SelectObject(pOldBitmap);
bitmap.DeleteObject();

That's all for now.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralImages not in the Resource directory Pin
spret8514-Sep-09 23:34
spret8514-Sep-09 23:34 
Questionhow to load tiff file image from java or c Pin
mikerahul13-Oct-07 1:40
mikerahul13-Oct-07 1:40 
Questionloading JPEG from stream? Pin
houari_id20-Mar-06 8:18
houari_id20-Mar-06 8:18 
GeneralThe unanimation bug Pin
eagleanec20-Feb-06 21:15
eagleanec20-Feb-06 21:15 
QuestionHow to show image from jpeg stream? Pin
Member 225629617-Sep-05 17:55
Member 225629617-Sep-05 17:55 
Generalfriends, you solved my great problem Pin
jiang shanshan25-Aug-05 19:04
jiang shanshan25-Aug-05 19:04 
Generalworks on pocket pc 2003 as well Pin
Pemeran Utama7-Mar-05 20:56
Pemeran Utama7-Mar-05 20:56 
GeneralWorks with JPG too Pin
Anonymous7-Feb-05 16:46
Anonymous7-Feb-05 16:46 
Questionhow about in eVB ? Pin
Anonymous16-Jan-04 1:50
Anonymous16-Jan-04 1:50 
QuestionUse SHLoadImageFile in dialog-based application? Pin
cwei_lim30-Dec-03 14:37
cwei_lim30-Dec-03 14:37 
Hello Tanzim.

I wan to use ur code to load an image on a dialog-based application and set it in a static field using setBitmap. This is my code:

<br />
BOOL CTestBitmapDlg::OnInitDialog()<br />
{<br />
	CDialog::OnInitDialog();<br />
	SetIcon(m_hIcon, TRUE);		// Set big icon<br />
	SetIcon(m_hIcon, FALSE);	// Set small icon<br />
	<br />
	CenterWindow(GetDesktopWindow<br />
	CBitmap bitmap;<br />
<br />
	bitmap.Attach(SHLoadImageFile(_T("/VIC.BMP")));<br />
<br />
	m_bmp.SetBitmap(bitmap);<br />
	m_bitmap.SetBitmap(bitmap);<br />
	return TRUE;  <br />
}<br />

I'm new to evc++D'Oh! | :doh: . I'm not sure this is correct o not. But the image doesn't appear. What can i do? Can u show me the way?


Thanks.
GeneralAbout SHLoadImageFile Pin
lopatkin26-Oct-03 22:34
lopatkin26-Oct-03 22:34 
GeneralRe: About SHLoadImageFile Pin
Anonymous19-Nov-03 18:16
Anonymous19-Nov-03 18:16 
GeneralRe: About SHLoadImageFile Pin
LiptenSoup14-Jan-04 11:09
LiptenSoup14-Jan-04 11:09 
GeneralIt is in MSDN Pin
Anonymous26-Oct-03 0:06
Anonymous26-Oct-03 0:06 
GeneralRe: It is in MSDN Pin
Anonymous13-Feb-04 3:22
Anonymous13-Feb-04 3:22 
GeneralGive a hand pls~~^_^ Pin
wehaha10-Sep-03 2:19
wehaha10-Sep-03 2:19 
GeneralI couldnt compile.... Pin
Ramees10-May-03 21:14
Ramees10-May-03 21:14 
GeneralRe: I couldnt compile.... Pin
Tanzim Husain30-May-03 19:11
Tanzim Husain30-May-03 19:11 
GeneralRe: I couldnt compile.... Pin
Anonymous8-Jun-03 0:12
Anonymous8-Jun-03 0:12 
GeneraleVB Pin
Chetan Kapadia17-Jan-03 2:58
Chetan Kapadia17-Jan-03 2:58 
QuestionHow to Images in WinCE4.1 - A Probable solution Pin
Tanzim Husain25-Sep-02 22:41
Tanzim Husain25-Sep-02 22:41 
QuestionHow to Images in WinCE4.1 ? Pin
DrWatson1-Sep-02 23:12
DrWatson1-Sep-02 23:12 
AnswerRe: How to Images in WinCE4.1 ? Pin
Tanzim Husain2-Sep-02 22:19
Tanzim Husain2-Sep-02 22:19 
GeneralRe: How to Images in WinCE4.1 ? Pin
huizhongxiang3-Sep-02 20:32
huizhongxiang3-Sep-02 20:32 
GeneralRe: How to Images in WinCE4.1 ? Pin
Houser7-Sep-02 23:28
Houser7-Sep-02 23:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.