Click here to Skip to main content
16,003,404 members
Articles / Mobile Apps / Windows Mobile

Property sheet callbacks in the Pocket PC 2002

Rate me:
Please Sign up or sign in to vote.
4.00/5 (7 votes)
25 May 2003CPOL3 min read 128K   187   20   39
How to insert title and footer links in Pocket PC property sheets, using MFC

Sample Image - CePropertySheet.jpg

Introduction

This article describes a scarcely documented feature of Pocket PC 2002 property sheets: how to include a title and a footer with link. Both title and footer will be present in all pages of the property sheet. This article also shows how to hide the application menu bar, like a standard CDialog.

Callbacks

Both titles and footers are implemented through a callback function present in all MFC handled property sheets, through CPropertySheet. The callback function address is stored in the pfnCallback member of the PROPSHEETHEADER structure stored in CPropertySheet's m_psh member. When you create a property sheet, MFC will fill in this pointer with the address of its own handler, AfxPropSheetCallback. This callback handles the PSCB_INITIALIZED and PSCB_GETVERSION messages. This is needed in order to put the tabs in the bottom, and to report which version of the controls, the property sheet is using. But we can do more with this callback: we can use it to insert a title and a footer, just like the property sheet in the demo project (see picture).

In order to access these functionalities, we must handle the PSCB_GETTITLE and PSCB_GETLINKTEXT messages in the callback. The problem is that MFC has already provided one callback for the property sheet, so how can we provide our own callback function? The answer is very simple: we hook it.

CCePropertySheet

All the relevant code is in the CCePropertySheet class. This class derives from MFC's CPropertySheet, and specializes its functionality in the following aspects:

  • Provides a standard CCeCommandBar;
  • Inserts a caption taken from the constructor parameters;
  • Allows the user to insert a footer with an optional link.

Using CCePropertySheet

Using the class is very straightforward:

CLinkSheet    dlg(_T("Link"));

dlg.SetLink(_T("Start <file:pword.exe{Word}>"));
dlg.DoModal();

The first line declares the object (derived from CCePropertySheet). The second line sets the footer link text. Finally, the dialog is called.

Implementing CCePropertySheet

The class is not complex, as you can see from the source code.

The first thing we have to do is hook the callback function (see HookCallback). This function is called from the constructors, where we store the sheet's caption in a static CString. When HookCallback is called, MFC has already stored its own callback function pointer in m_psh.pfnCallback. The pointer is stored in a static member, and is replaced by the class' own callback.

Serving the callback is quite straightforward. The title and link messages are checked for and served. The MFC callback is always called to handle the message, so we retain all the functionality we already know. Serving the messages means copying the specific strings to the address given by lParam.

Finally, the OnInitDialog handler is used to create an empty CCeCommandBar. Besides hiding the application's command bar, this can be used as a regular command bar, meaning you can insert menus and buttons.

Note that both m_strLink and m_strTitle are static member variables. This is required because they are both referenced by the callback function that must be static itself (will not receive the implicit this in the parameter list). Also, note that these variables are only accessed once, during the property sheet creation cycle. If you need to create a second property sheet as a result of a command issued by the first, you can be sure that the overridden string values will have no effect on the first property sheet.

Thanks

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

 
Questionmenu bar not appearing on the command bar for VS 2008 migrated from evc++ 4.0 Pin
Member 1095000815-Jul-14 23:18
Member 1095000815-Jul-14 23:18 
Hi We are migrating code developed in eVC++4.0 to Visual Studio 2008 VC++ 9.0 version. Entire classes migrated successfully and even we are to launch the application on Windows Mobile Emulator without issues but there is one screen where we’ve a menu bar as shown in below screenshot. We have not been able to view Menu Bar on the screen as shown, This works fine in eVC++ 4.0. We are using Pocket PC 2003 emulator.



We are creating a class inherited from CPropertySheet. As below:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
In Header File:

class COptionsSheet : public CPropertySheet
{
DECLARE_DYNAMIC(COptionsSheet)
#if(WINVER == 0x400)// This works for MenuBAr inherited from CDialog classes.
CCommandBar m_cb;
#else
CCeCommandBar m_cb;
#endif
public:
virtual BOOL OnInitDialog();

We are drawing menu bar on the property window as below:

In .CPP file:
IMPLEMENT_DYNAMIC(COrderSheet, CPropertySheet)
BEGIN_MESSAGE_MAP(COrderSheet, CPropertySheet)
ON_COMMAND(ID_CUSTOMER_COLLECTPAYMENT, OnCustomerCollectpayment)
ON_WM_INITMENUPOPUP()
ON_NOTIFY(GN_CONTEXTMENU, 0, OnContextMenu)
END_MESSAGE_MAP()

BOOL COrderSheet::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();

m_cb.Create(this);//This we have changed for VS 2008 as menu was not appearing for class inherited from CDialog class as well. In eVC++ 4.0 code we have used. Please see m_cb in header file discription

m_cb.InsertMenuBar(IDR_ORDER1);// This calis unable to draw mwnu bar
CMenu *pMenu = CWnd::GetMenu(); //pMenu becomes NULL in very next line as we are passing it as parameter below.

gPromotion.LoadSalesPromotions(pMenu, "Sales", SRC_TRACE_START);

---------------------------------------------------------------------------------------------------------

We tried this as well but it’s also not working:
CMenu *pMenu = new CMenu;
BOOL cehckStatus = pMenu->LoadMenu(IDR_ORDER1);
SetMenu(pMenu);
CRect r; GetWindowRect(&r);
r.bottom += GetSystemMetrics(SM_CYMENU);
MoveWindow(r);

Do we have to change or add something more for the menu bar in case of Property Sheet. Is there any change between eVC++ and Visual studio 2008 that we need to incorporate here.
QuestionLicensing Pin
MKahlow1-Oct-07 7:50
MKahlow1-Oct-07 7:50 
AnswerRe: Licensing Pin
João Paulo Figueira2-Oct-07 21:29
professionalJoão Paulo Figueira2-Oct-07 21:29 
General&quot;Please enter an integer&quot; Problem! Pin
epeyman19-Jul-05 12:21
epeyman19-Jul-05 12:21 
GeneralRe: &quot;Please enter an integer&quot; Problem! Pin
João Paulo Figueira20-Jul-05 6:23
professionalJoão Paulo Figueira20-Jul-05 6:23 
GeneralRe: &quot;Please enter an integer&quot; Problem! Pin
epeyman21-Jul-05 9:45
epeyman21-Jul-05 9:45 
GeneralRe: &quot;Please enter an integer&quot; Problem! Pin
epeyman21-Jul-05 12:36
epeyman21-Jul-05 12:36 
GeneralRe: &quot;Please enter an integer&quot; Problem! Pin
epeyman28-Jul-05 6:05
epeyman28-Jul-05 6:05 
GeneralRe: &quot;Please enter an integer&quot; Problem! Pin
rohinivn13-Mar-07 22:50
rohinivn13-Mar-07 22:50 
GeneralTitle Pin
Marco Giuntoni13-Oct-04 0:17
professionalMarco Giuntoni13-Oct-04 0:17 
GeneralRe: Title Pin
João Paulo Figueira13-Oct-04 0:35
professionalJoão Paulo Figueira13-Oct-04 0:35 
Generalintegration Pin
OsoPolar8-Oct-04 6:45
OsoPolar8-Oct-04 6:45 
GeneralRe: integration Pin
João Paulo Figueira8-Oct-04 6:51
professionalJoão Paulo Figueira8-Oct-04 6:51 
GeneralRe: integration Pin
OsoPolar12-Oct-04 22:35
OsoPolar12-Oct-04 22:35 
QuestionCan not run on STANDARDSDK_420 Pin
Member 4515166-Sep-04 20:06
Member 4515166-Sep-04 20:06 
AnswerRe: Can not run on STANDARDSDK_420 Pin
João Paulo Figueira6-Sep-04 22:37
professionalJoão Paulo Figueira6-Sep-04 22:37 
Questioncode modification?? Pin
benahpets1-Sep-04 3:35
benahpets1-Sep-04 3:35 
AnswerRe: code modification?? Pin
João Paulo Figueira1-Sep-04 3:45
professionalJoão Paulo Figueira1-Sep-04 3:45 
GeneralProblem Pin
benahpets31-Aug-04 3:45
benahpets31-Aug-04 3:45 
GeneralRe: Problem Pin
João Paulo Figueira31-Aug-04 4:34
professionalJoão Paulo Figueira31-Aug-04 4:34 
GeneralRe: Problem Pin
benahpets31-Aug-04 4:37
benahpets31-Aug-04 4:37 
GeneralRe: Problem Pin
João Paulo Figueira31-Aug-04 4:46
professionalJoão Paulo Figueira31-Aug-04 4:46 
GeneralRe: Problem Pin
benahpets31-Aug-04 4:55
benahpets31-Aug-04 4:55 
GeneralRe: Problem Pin
João Paulo Figueira31-Aug-04 5:19
professionalJoão Paulo Figueira31-Aug-04 5:19 
GeneralRe: Problem Pin
benahpets31-Aug-04 5:35
benahpets31-Aug-04 5:35 

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.