Tuesday, February 1, 2000

HP hotkeys, OK buttons, and file existence

.KEYWORD progpower
.FLYINGHEAD PROGRAMMING POWER
.TITLE HP hotkeys, OK buttons, and file existence
.OTHER
.SUMMARY This month, bSQUARE’s Andrew Tucker takes a look at a hidden feature that should be of interest to all users of Hewlett Packard (HP) Jornada H/PCs and H/PC Pros. It shows you how to create an OK button in the title bar of your dialog box; how to test for the existence of a file on your Windows CE device even if it’s in ROM; and how to get a listview to select a whole row at a time instead of just the first column.
.AUTHOR Andrew Tucker
Before we jump into this month’s topics, I wanted to thank everyone who has sent in questions and comments on previous columns. We forgot to mention it, but the SIP question last month was sent in by John Rogers of Trimble Navigation. This column is geared toward responding to user feedback, so be sure to send us any questions you might have, as well as comments on previous columns, to poweranswers@bsquare.com.

This month we’ll take a look at a hidden feature that should be of interest to all users of Hewlett Packard (HP) Jornada H/PCs and H/PC Pros. The tip comes from the comp.os.ms-windows.ce USENET newsgroup posting by Steve Grother at HP.

Across the top of the Jornada’s keyboard are 11 hotkeys that allow you to start a specific application at the push of a button. The stock configuration of the device has settings for the application icon printed on the key, but HP provides an editor that allows you to change the keys to correspond to any program you like. What HP doesn’t tell you, or let you customize, is that combining shift or control with a hotkey can have a completely different setting from just the hotkey itself. To take advantage of this, I wrote a hotkey editor that allows you to customize all 33 hotkeys to a program of your choice rather than just the 11 that the HP editor allows. We’ll examine how the editor works in some detail, and then we’ll look at some common Windows CE programming problems that it solves along the way.

The key to customizing the hotkeys is knowing that the mapping is kept under the registry key HKEY_LOCAL_MACHINE&#92Software&#92Microsoft&#92Shell&#92Keys. Each hotkey is a separate registry key made up of four hexadecimal digits. The top two characters specify what modifier key is used for this entry. 0x44 is the shift key, 0x48 is the control key, and 0x40 means no modifier keys. The bottom two characters specify the actual hotkey. Starting with the value of 0xC1 representing the far left key with the Inbox, the value increments by one for each key. Table A lists all the hotkey combinations and their numeric registry key names. The default value under the registry key holds the actual path to the executable or shell link that will be launched when that key is pressed.

.BEGIN_TAB_TABLE A Hotkeys
.TAB_TABLE_WIDTH 50% 50%
.TAB_TABLE_HEADER Hotkey combinations Numeric registry key names
.TAB_TABLE_ROW 40C1 Key 1
.TAB_TABLE_ROW 44C1 Shift-Key 1
.TAB_TABLE_ROW 48C1 Control-Key 1
.TAB_TABLE_ROW 40C2 Key 2
.TAB_TABLE_ROW 44C2 Shift-Key 2
.TAB_TABLE_ROW 48C2 Control-Key 2
.TAB_TABLE_ROW 40C3 Key 3
.TAB_TABLE_ROW 44C3 Shift-Key 3
.TAB_TABLE_ROW 48C3 Control-Key 3
.TAB_TABLE_ROW 40C4 Key 4
.TAB_TABLE_ROW 44C4 Shift-Key 4
.TAB_TABLE_ROW 48C4 Control-Key 4
.TAB_TABLE_ROW 40C5 Key 5
.TAB_TABLE_ROW 44C5 Shift-Key 5
.TAB_TABLE_ROW 48C5 Control-Key 5
.TAB_TABLE_ROW 40C6 Key 6
.TAB_TABLE_ROW 44C6 Shift-Key 6
.TAB_TABLE_ROW 48C6 Control-Key 6
.TAB_TABLE_ROW 40C7 Key 7
.TAB_TABLE_ROW 44C7 Shift-Key 7
.TAB_TABLE_ROW 48C7 Control-Key 7
.TAB_TABLE_ROW 40C8 Key 8
.TAB_TABLE_ROW 44C8 Shift-Key 8
.TAB_TABLE_ROW 48C8 Control-Key 8
.TAB_TABLE_ROW 40C9 Key 9
.TAB_TABLE_ROW 44C9 Shift-Key 9
.TAB_TABLE_ROW 48C9 Control-Key 9
.TAB_TABLE_ROW 40CA Key 10
.TAB_TABLE_ROW 44CA Shift-Key 10
.TAB_TABLE_ROW 48CA Control-Key 10
.TAB_TABLE_ROW 40CB Key 11
.TAB_TABLE_ROW 44CB Shift-Key 11
.TAB_TABLE_ROW 48CB Control-Key 11
.END_TAB_TABLE

The extended editor, shown in Figure A, looks a lot like the stock editor provided by HP. Full source code is available at http://www.halcyon.com/ast/dload/HotKeyEditor.zip.

.FIGPAIR A The extended editor looks a lot like the stock editor provided by HP.

The edit box in the lower right hand corner always shows the program associated with the currently highlighted hotkey, and you can either type in a new entry or use the Browse button to select a file from a directory on the device. The Restore Defaults button will change the hotkeys back to the values of the original device configuration. To save your changes, press Enter or select the OK button in the title bar. If any of the specified files do not exist, the editor will warn you via a dialog box. You’ll then need to change the offending filename(s) and hit OK again or cancel the dialog to throw away your changes.

The editor is mostly a straightforward Windows CE dialog application, but it does address a couple of common questions that often come up in the newsgroups and mailing list.

.H1 How do I create an OK button in the title bar of my dialog box?
This feature is controlled by the extended window style WS_EX_CAPTIONOKBTN. Typically, you specify window styles via the properties dialog in the Visual C++ for Windows CE resource editor. Unfortunately, there’s a bug in the latest version that causes the checkbox for this feature to be disabled, as shown in Figure B. Luckily, there are a couple of workarounds.

.FIG B Unfortunately, there’s a bug in the latest version of Visual C++ for Windows CE resource editor that causes the checkbox for creating buttons in the title bar to be disabled.

One possibility for working around this bug is to manually add the style to the list in the resource file dialog template. Resource files are just plain text, so this is easy to do, but it’s a major pain. Every time you save from the resource editor, your changes will be overwritten — yuck! The second, and much more attractive, alternative is to change the style programmatically at runtime. This doesn’t always work for window styles, but luckily it works in this situation. Just add the following line to the handler for your WM_INITDIALOG message and the OK button will magically show up in your title bar:

.BEGIN_CODE
SetWindowLong(hwndDlg, GWL_EXSTYLE, WS_EX_CAPTIONOKBTN );
.END_CODE

.PAGE
.H1 How do I test for the existence of a file on my Windows CE device, even if it’s in ROM?
The standard method of testing for a file’s existence is to attempt to open it in shared, read-only mode and test for a valid handle. Due to the way that the Windows CE file storage is structured, this method won’t work on executable modules that are in ROM. The right way to do this is to use the GetFileAttributes API (application programming interface). If 0xFFFFFFFF is returned, the file doesn’t exist. If the file does exist, the value contains some interesting information. Windows CE utilizes the following three new attributes to describe files in ROM:

.BEGIN_LIST
.BULLET FILE_ATTRIBUTE_INROM: lets you know that the file is part of the read-only OS image and can’t be updated.
.END_LIST

.BEGIN_LIST
.BULLET FILE_ATTRIBUTE_ROMMODULE: also means that the file is in ROM, but additionally that it’s a binary image such as a DLL (data link layer) or an .EXE file. Files with this attribute will be executed directly from ROM instead of first being copied to RAM. This feature is referred to as execute in place (XIP) in some of the documentation and literature on Windows CE.
.END_LIST

.BEGIN_LIST
.BULLET FILE_ATTRIBUTE_ROMSTATICREF: specifies that the file is a DLL that’s statically linked to at least one other ROM module and cannot be replaced by a file of the same name in a different directory.
.END_LIST

.H1 How do I get a listview to select a whole row at a time instead of just the first column?
If you’ve been using the Win32 listview control on the desktop or Windows CE for a while, you’ve no doubt run across this question. Earlier versions of the control didn’t provide the functionality at all, and Microsoft supplied a detailed example program that showed how to hack in support for it. This was a major kludge, and Microsoft redeemed itself by adding in support in later versions. It isn’t turned on by default, but if you execute the following statement to your handler for the WM_INITDIALOG message you won’t have to go through any kludgy gyrations.

.BEGIN_CODE
ListView_SetExtendedListViewStyleEx(hwndLV,
LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
.END_CODE

That about wraps it up. See you next month. Be sure to keep those questions coming to poweranswers@bsquare.com.

.BEGIN_SIDEBAR
.H1 Product Availability and Resources
Full source code for the extended editor, which looks a lot like the stock editor provided by HP, is available at http://www.halcyon.com/ast/dload/HotKeyEditor.zip.

.H1 Bulk reprints
Bulk reprints of this article (in quantities of 100 or more) are available for a fee from Reprint Services, a ZATZ business partner. Contact them at reprints@zatz.com or by calling 1-800-217-7874.
.END_SIDEBAR

.BIO Andrew Tucker works on developer tools for Windows CE at bSQUARE Corporation. He has been writing code for Windows since 1991 and has published articles in C/C++ Users Journal, Dr Dobbs Journal, and Windows Developer Journal. He recently co-authored SAMS Teach Yourself Windows CE Programming in 24 Hours. Andrew has a BSCS from Seattle Pacific University and is working on a MSCS at the University of Washington. He can be reached at poweranswers@bsquare.com.