Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls
Stay in touch using the DEVBUSS RSS feeds.
 

News

Windows Mobile Developer Controls
Sapphire Soltuions

Focus on Building the Console - Part 2 of 2

Written by Brent Pinkley  [author's bio]  [read 40297 times]
Edited by Derek

Download the code

Page 1  Page 2  Page 3  Page 4 

The purpose of the MSMQ Console application is to serve as both a full-fledged development project and as a practical administrative tool to manage messages and queues on the Pocket PC. It is an attempt to take many different techniques that have been discussed through previous articles and in the forums, and combine them in a way that facilitates learning how the design process works.

If you want to look under the hood and learn a little more about the mechanics of Microsoft Message Queue (MSMQ) on the Pocket PC, you will want to check out Part I. This article will build upon that foundation by discussing how the Console application was architected, and how some of the key components work together to enhance the user experience.

In developing the Console, I learned quite a bit from the many tips and useful advice of developers who have generously given their time to explain some of the more obscure aspects of eVB development. Therefore, I am happy to be able to combine several of these techniques and share them with you. In an effort to make this application as readable and easily digestible as possible, I have broken out much of the code into a modular design. While the Pocket PC may differ from desktop development in the fact that it can be a bit slower when using a more modular design, as opposed to inline code, I think the understandability is higher. That has been my focus throughout the application design process.

MSMQ Console Highlights

  1. ListView Configuration with API calls - Checkboxes, Icons, Full Row Selection, Columns that are Auto Sizing, Drag & Drop and Bi-Directionally Sorting, Grid Lines, Pop-up Menus
  2. MenuBar Configuration - Sub Menus, Menu Buttons, Context-Enabled Options, Setting Checked Options
  3. Scrollable Message Entry Forms - Auto Sizing Forms to Accommodate SIP
  4. TreeView Configuration w/Image List - Changing Images, Programmatic Node Expansion
  5. Registry Retrieval of Pocket PC Name
  6. Allow Only One Instance of App to Run

The Many Things a ListView Can Do

It seems that with all of the effort that went into creating a lightweight version of VB, more attention would have been given to documenting some of the controls that are part of a standard Pocket PC application. One of the most notable of these is the ListView control. The logo certification process certainly seems to be pushing the use of list view controls (see "Part 1: Building a better world with Windows CE logo certification", but much of what a list view can do is either not well documented or is achieved through API calls. That makes it somewhat rough to learn, especially if you are used to VB providing this functionality on the desktop with little effort.

The Console application explores much of the basic functionality that might be needed for Pocket PC development. It displays messages from a selected queue in a list view configured to display in report view, which allows multiple columns to be included for each list item.

In order to go further into the details of adding features to the list view, it is necessary to start with the basics of adding column headers and list items to the list view control. To add column headers is as simple as adding each column one by one, specifying an index, key, caption, width and alignment, with only the caption being required:

' Add Column Header
lvwMessages.ColumnHeaders.Add 1, "Subject", _
"Subject", , lvwColumnLeft
lvwMessages.ColumnHeaders.Add 2, "Priority", _
"!", , lvwColumnRight
lvwMessages.ColumnHeaders.Add 3, "Arrived", _
"Arrived", , lvwColumnLeft

Once the columns have been established, list items can be added. To make life simple, you can create a procedure to wrap up the necessary steps for adding items. An example of this would be:

Private Sub ListItemAdd(ByVal intIndex As Integer, _
ByVal strKey As String, _
ByVal strLabel As String, _
ByVal intPriority As Integer, _
ByVal datArrived As Date, _
ByVal intIcon As Integer)

' Add list item with icon
Set objListItem = _
lvwMessages.ListItems.Add(intIndex, _
strKey, strLabel, , intIcon)

' Add additional columns as sub items
objListItems.SubItems(1) = intPriority
objListItems.SubItems(2) = datArrived
End Sub

' Example call procedure
ListItemAdd intCount, objMsg.Id, objMsg.Label, _
objMsg.Priority, objMsg.ArrivedTime, 5

This example assumes that an image list has already been created and the SmallIcons property of the list view has been associated with the image list. For a more thorough description on working with image lists, see the article, "Adding images to the eVB Imagelist control".

Nothing too extreme yet, but that is essentially where the pavement ends and the dirt road begins. Perhaps you are the type that likes to go a little off the beaten path and do a little tweaking with controls to suit your needs. You will probably end up going to a few handy API calls to achieve just what you were looking for. Some of the configuration settings for the Console list view include full row selection, checkboxes and drag and drop column headers. Fortunately, it is the same process to achieve all of these options. You just need to add a few constants and a couple of API functions:

' In module
Public Const LVM_GETEXTENDEDLISTVIEWSTYLE = &H1037
Public Const LVM_SETEXTENDEDLISTVIEWSTYLE = &H1036
Public Const LVS_EX_FULLROWSELECT = &H20
Public Const LVS_EX_CHECKBOXES = &H4
Public Const LVS_EX_HEADERDRAGDROP = &H10

Public Declare Function GetFocus Lib _
"Coredll" () As Long
Public Declare Function SendMessage Lib _
"Coredll" Alias "SendMessageW" _
(ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

' In form
lvwMessages.SetFocus
' Get handle to ListView
hWnd = GetFocus()

' Determine current ListView style
lngStyle = SendMessage(hWnd, _
LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)

' Add options to current style
lngStyle = lngStyle Or LVS_EX_FULLROWSELECT Or _
LVS_EX_CHECKBOXES Or LVS_EX_HEADERDRAGDROP

' Set new style
SendMessage hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, _
0, lngStyle

There you have it. Three options set for the price of one! Full row select highlights the entire row when you click on a list item, checkboxes are pretty self-explanatory, and header drag drop allows a column to be moved from one position to another.

Next Page