A Pinnable Dialog Base Class

.

Introduction

This class enables you to have a dialog where the user can dynamically switch between modeless and modal behaviour by toggling its "pinned" state. This is similar to the Properties dialog in Developer Studio where you can display the properties of one file or class, pin the dialog and then select another file or class and see its properties displayed automatically in the properties dialog. This feature was simpler to implement than I thought it was going to be. Essentially, a pinnable dialog is a modeless dialog. When the dialog is unpinned (i.e., when it is to behave as a modal type dialog) it is hidden whenever it loses focus. When the dialog is pinned, it behaves as a standard modeless dialog.

The CPinnableDialog base class handles the switching between the pinned and unpinned states. You just derive your dialog class from CPinnableDialog and create an instance of it in the parent window or frame class and then hide and show it as appropriate. The pinnable dialog sends a message to the parent window when it is to close. The pinned state simply dictates whether it closes when it is deactivated. The class allows the developer to dictate whether a deactivation closure is treated as a cancel or as if the Ok button was pressed.

The CPinnableDialog class uses the dialog's icon in the top left hand corner to display the pin rather than using a bitmapped button as Developer Studio does. I think this looks a lot neater and allows the dialog's client area to be completely utilised. When the dialog is closed it sends a user-defined WM_PINUPCLOSE message to the parent window. Usually the parent handles this message by simply hiding the dialog. The parent window can also determined how the dialog was closed (for example, whether the Ok or Cancel buttons were pressed) so that it can retrieve any values which have been edited by the user and validate them if necessary before allowing the dialog to close.

Usage

To implement this behaviour in one of your own dialogs, follow these steps :-

  1. Create your dialog resource as normal and get Class Wizard to generate a dialog class and data members for you. The dialog should have the "Title Bar" and "System Menu" styles enabled.
  2. Add two icons to your project's resources, one for the pinned state and one for the unpinned state. I "borrowed" the ones from Developer Studio!
  3. Change the base class of the dialog to CPinnableDialog. Make sure you change all occurrence of CDialog to CPinnableDialog, especially in the BEGIN_MESSAGE_MAP macro block.
  4. When you call the CPinnableDialog's constructor, pass the resource IDs for the dialog template and the two icons as well as the parent CWnd pointer.
  5. Add a public function to your dialog class which can be called to set the dialog's contents when it is to be shown.
  6. In the parent window class, add a data member to hold a pointer to your dialog class. In the constructor, create a new dialog object using new and in the destructor delete it.
  7. Add a message handler to the parent window class to handle the WM_PINUPCLOSE message which the dialog will send when it is to be closed. In the handler, call the dialog's Hide function.
  8. Whenever you want to display the dialog, set the dialog's data (using the function you added above) and call its Show function.
  9. Whenever you might want to
    update the data that the dialog is displaying (for example, when the user selects another item), check to see if the dialog is visible (i.e., it is pinned) and if it is, call your refresh function.

The Sample Project

I have included a sample project which illustrates how the CPinnableDialog class can be used. It is a very simple dialog-based application which displays a list of interfaces implemented by a typical ActiveX control. The user can display the properties of any particular interface by either double clicking on its entry in the list box or by selecting Properties from the context menu. Once the properties dialog is displayed, the user can pin it and select another interface to see its properties automatically displayed. The name and description fields are read-only but the user can toggle the implemented flag.

Downloads

Download demo project - 19 Kb
Download source - 3 Kb


Comments

  • Fix for show of pin icon in proper form

    Posted by Legacy on 09/18/2003 12:00am

    Originally posted by: Andrei

    It needs to load icon images in CPinnableDialog constructor by LoadImage function instead of LoadIcon, because LoadIcon only loads images that conform SM_CXICON and SM_CYICON system metric values, which is not our case, because these images are 16x16. It leads images to be shown corrupted. The correct code would be

    m_hPinned = (HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(nPinnedIconID),
    IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);

    Reply
  • can i get any information how to create menu items

    Posted by Legacy on 03/17/2001 12:00am

    Originally posted by: k v d prasad

    respected sir i am working as a programer in nordic info soft.at present i am java programer.now i am changing to vc.so i need guidelenes like u .so can i have notes on menu items?.
    
    

    waiting for u reply.

    Reply
  • Please show how to do this for a dialog based app.

    Posted by Legacy on 02/01/2001 12:00am

    Originally posted by: Les Leroux

    I would like to use this "pinnable" technique in a dialog based application. Possible? Easy?

    Reply
  • Can this be done on a Dialog Base Application ?

    Posted by Legacy on 12/07/2000 12:00am

    Originally posted by: James

    How can I use the CPinnableDialog on a Dialog base Application?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

  • Live Event Date: September 19, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT In response to the rising number of data breaches and the regulatory and legal impact that can occur as a result of these incidents, leading analysts at Forrester Research have developed five important design principles that will help security professionals reduce their attack surface and mitigate vulnerabilities. Check out this upcoming eSeminar and join Chris Sherman of Forrester Research to learn how to deal with the influx of new device …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds