Click here to Skip to main content
15,881,882 members
Articles / Mobile Apps / Windows Mobile

A Picture Viewer for the Pocket PC 2002

Rate me:
Please Sign up or sign in to vote.
4.79/5 (21 votes)
2 Nov 2003CPOL4 min read 496.2K   685   43   139
Putting imgdecmp.lib to work with a few extras.

Sample Image - PicView1.jpg

Introduction

This is a very simple picture viewer that illustrates some implementation details that you might want to use in your own Pocket PC 2002 projects. These are:

  • Using the imgdecmp.lib for loading BMP, JPEG and GIF image files.
  • Implementing a "tap-and-scroll" for scrolling convenience.
  • Implementing a full screen view.
  • Removing the "New" button from a Document / View toolbar.
  • Adding a title bar to the view (new)

Application architecture

This application uses the MFC's Document / View architecture in order to ease implementation. Bitmap pictures are drawn in a CScrollView-derived class, with a special support for the "tap-and-scroll" functionality. This allows the user to scroll the bitmap using the stylus, by tapping and dragging it. The document does not allow saving (after all, this is a viewer), but supports zooming. The zoom in and zoom out commands are supported at the document level although, arguably, they could be implemented at the view level.

Loading images

Images are loaded through a sparsely-documented API, implemented through the imgdecmp.lib. Both this library and its header are distributed with the PPC2002 SDK. Apparently, this is the same mechanism that is used by Pocket IE to load its images from the Internet, and that is why it supports a packet architecture. As for file formats, it is reported to support BMP, JPEG and GIF, but it may support more.

Images are loaded in CPicViewDoc::Serialize(). The process (see source) involves calling the DecompressImageIndirect() function, the DecompressImageInfo structure and two callback functions. The first callback function - GetImageData() - is used to read the image data in chunks, whereas the second - ImageProgress() - is used to report the image loading progress. In this sample, the callback does nothing (but yes, it must be there).

The fields of the DecompressImageInfo structure are quite self-explanatory, with one exception: lParam. This is the parameter that is passed to the callback functions, and I use it to carry a pointer to a structure containing a pair of values (ReadBmp): the CFile pointer retrieved from the open CArchive, and a counter of the image size. This is not strictly necessary for this application because one file has just one image, so passing the CFile* in lParam would be enough. This technique is used because it allows for extensibility, in the case where the file has multiple images, such as a skin file. Here you cannot rely in the end-of-file stop rendering the bitmap.

Tap-And-Scroll

This technique allows scrolling the image with a tap and drag sequence. The image will follow the stylus, scrolling automatically. The scroll bars are also present and active.

In order to achieve this effect, the view handles both OnLButtonDown() and OnMouseMove() (see code). The first stores the tap point, and the second calculates the scroll vector. This vector is then used in the ScrollTo() method, where the new scroll position is calculated. Note that this code was directly adapted from MFC's sources in order to avoid the unpleasant "jagged" scrolling one gets by using CScrollView::ScrollToPosition(). This method does not allow scrolling in both x and y directions simultaneously.

Full screen view

In the Pocket PC 2002, the full screen functionality is achieved through the SHFullScreen API. This function allows the application to position its main window over areas that are usually controlled by the system, such as the SIP and the taskbar. The code that achieves this is in the CMainFrame::OnFullScreen() handler. In order to support full screen toggling, a context menu is available through the tap-and-hold command. This menu allows you to enter and leave the full screen mode, as well as to issue Zoom In and Zoom Out commands.

The New button

Because this is just a viewer, the New button was removed from the main menu using a technique designed by Vassili Philippov. The original article is here: How to remove New button from command bar?

Title bar

Updated on October 27, 2003. The sample application now supports a title bar for displaying the image's file name. This title bar can be hidden or shown via a menu option, under Tools.

This title bar is implemented through the CCeTitleBar class, a CControlBar-derived window. It merely displays the title text in a predefined font and color.

Using this class is very straightforward (see source code). The window is created on the view's OnCreate handler and destroyed in OnDestroy. The view's OnUpdate handler is used to set the title text (document file name). Showing and hiding the title bar is done in the view's OnShowTitle handler.

License

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


Written By
Software Developer (Senior) Frotcom International
Portugal Portugal
I work on R&D for Frotcom International, a company that develops web-based fleet management solutions.

Comments and Discussions

 
GeneralRe: Link error Pin
bt12-Jan-04 23:15
bt12-Jan-04 23:15 
GeneralRe: Link error Pin
João Paulo Figueira3-Jan-04 5:59
professionalJoão Paulo Figueira3-Jan-04 5:59 
GeneralRe: Link error Pin
bt111-Jan-04 21:53
bt111-Jan-04 21:53 
GeneralExcellent utility.. but.. Pin
J Patel1-Sep-03 16:47
J Patel1-Sep-03 16:47 
GeneralRe: Excellent utility.. but.. Pin
João Paulo Figueira2-Sep-03 2:46
professionalJoão Paulo Figueira2-Sep-03 2:46 
GeneralRe: Excellent utility.. but.. Pin
J Patel2-Sep-03 6:04
J Patel2-Sep-03 6:04 
GeneralIt is very good, but it is very slow Pin
zhangzq7127-Aug-03 0:17
zhangzq7127-Aug-03 0:17 
GeneralRe: It is very good, but it is very slow Pin
João Paulo Figueira27-Aug-03 1:06
professionalJoão Paulo Figueira27-Aug-03 1:06 
GeneralExcuse me, question about midi Pin
Yang_tapan12-Aug-03 17:22
Yang_tapan12-Aug-03 17:22 
Generalfile download is break Pin
Anonymous25-Jun-03 8:51
Anonymous25-Jun-03 8:51 
GeneralRe: file download is break Pin
João Paulo Figueira25-Jun-03 8:53
professionalJoão Paulo Figueira25-Jun-03 8:53 
GeneralCouldn't find imgdecmp.h Pin
jeffreytee18-Jun-03 20:10
jeffreytee18-Jun-03 20:10 
GeneralRe: Couldn't find imgdecmp.h Pin
João Paulo Figueira19-Jun-03 3:11
professionalJoão Paulo Figueira19-Jun-03 3:11 
GeneralRe: Couldn't find imgdecmp.h Pin
jeffreytee19-Jun-03 19:23
jeffreytee19-Jun-03 19:23 
GeneralRe: Couldn't find imgdecmp.h Pin
João Paulo Figueira19-Jun-03 22:17
professionalJoão Paulo Figueira19-Jun-03 22:17 
GeneralRe: Couldn't find imgdecmp.h Pin
Kris Smith18-Jul-03 7:33
Kris Smith18-Jul-03 7:33 
GeneralRe: Couldn't find imgdecmp.h Pin
João Paulo Figueira18-Jul-03 9:00
professionalJoão Paulo Figueira18-Jul-03 9:00 
GeneralRe: Couldn't find imgdecmp.h Pin
kiran chandra17-Sep-03 19:27
kiran chandra17-Sep-03 19:27 
GeneralRe: Couldn't find imgdecmp.h Pin
João Paulo Figueira17-Sep-03 22:21
professionalJoão Paulo Figueira17-Sep-03 22:21 
QuestionDoes anyone try to implement thumbnails? Pin
waynejih4-May-03 21:52
waynejih4-May-03 21:52 
AnswerRe: Does anyone try to implement thumbnails? Pin
João Paulo Figueira4-May-03 21:56
professionalJoão Paulo Figueira4-May-03 21:56 
GeneralProblems Pin
henrytaihk8-Apr-03 1:17
henrytaihk8-Apr-03 1:17 
GeneralRe: Problems Pin
João Paulo Figueira8-Apr-03 6:53
professionalJoão Paulo Figueira8-Apr-03 6:53 
GeneralRe: Problems Pin
henrytaihk8-Apr-03 17:01
henrytaihk8-Apr-03 17:01 
GeneralRe: Problems Pin
João Paulo Figueira9-Apr-03 3:47
professionalJoão Paulo Figueira9-Apr-03 3:47 

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.