Click here to Skip to main content
15,885,366 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 170.5K   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

 
AnswerRe: How to use on win32 [modified] Pin
Lord Sy26-Nov-06 9:32
Lord Sy26-Nov-06 9:32 
GeneralIt's documented! Pin
Zoltan Csizmadia13-Aug-02 4:39
Zoltan Csizmadia13-Aug-02 4:39 
GeneralRe: It's documented! Pin
Tanzim Husain27-Aug-02 23:04
Tanzim Husain27-Aug-02 23:04 
GeneralRe: It's documented! Pin
Zoltan Csizmadia28-Aug-02 3:49
Zoltan Csizmadia28-Aug-02 3:49 
GeneralRe: It's documented! Pin
Anonymous9-Jan-03 19:37
Anonymous9-Jan-03 19:37 
GeneralRe: It's documented! Pin
Zoltan Csizmadia10-Jan-03 3:13
Zoltan Csizmadia10-Jan-03 3:13 
GeneralRe: It's documented! Pin
Member 103232620-Apr-04 7:39
Member 103232620-Apr-04 7:39 
GeneralURL Documented at Microsoft site Pin
Joseph Ellsworth24-May-05 21:07
Joseph Ellsworth24-May-05 21:07 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/apippc/html/ppc__mdref_shloadimagefile.aspBig Grin | :-D

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.