Using Shortcut Keys for Property Pages

Its unfortunate that the tab control or the property sheet do not support the shortcut keys. It's fortunate, however, that it is so easy to implement.

Step 1: Assign shortcut keys to property pages

Open up each of the property page resource in the resource editor and update the caption by adding an ampersand before the character that is to be the shortcut key. The shortcut key will appear underlined in the property sheet tab.

Step 2: Override OnPreTranslateMessage

Override the OnPreTranslateMessage() function and add the code shown below. The logic used is fairly simple. If a system key ( an alt key combination ) is pressed, all the tab items are searched for this key. If one is found then the associated page is activated. Note that the call to the base class version of this function is at the bottom. Therefore, if a page and a control in the active page have the same shortcut key, the page wins.
BOOL CModalShapePropSheet::PreTranslateMessage(MSG* pMsg)
{
	if( pMsg->message == WM_SYSKEYDOWN && pMsg->wParam > 32 )
	{
		CTabCtrl *pTab = GetTabControl();
		int n = pTab->GetItemCount();

		TCHAR buf[80], shortcut[3];
		TC_ITEM tcItem;
		tcItem.mask = TCIF_TEXT;
		tcItem.pszText = buf;
		shortcut[0] = _T('&');
		shortcut[2] = _T('\0');
		for( int i = 0; i < n; i++ )
		{
			tcItem.cchTextMax = 79;
			pTab->GetItem( i, &tcItem );
			shortcut[1] = (TCHAR) pMsg->wParam;
			if( _tcsstr( buf, shortcut ) )
			{
				SetActivePage( i );
				return TRUE;
			}
		}
	}
	return CPropertySheet::PreTranslateMessage(pMsg);
}



Comments

  • lower case shortcuts

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

    Originally posted by: Rolf Behrens

    thanks for this routine, but you forgot the lowercase shortcuts
    
    I just add
    ...
    shortcut[1] = tolower(shortcut[1]);
    if( _tcsstr( buf, shortcut ) )
    {
    SetActivePage( i );
    return TRUE;
    }
    ...

    then it works with lowercase as well.

    CU Rolf

    Reply
  • Help on PropertySheet.

    Posted by Legacy on 10/18/1999 12:00am

    Originally posted by: pabitra kumar dash

    Hi,

    I created a propertysheet in which I am able to add
    two property pages. When a third property page added into
    it, my application behaves abnormally. Can I know what will
    be the problem in it?

    Please help.

    Regards,
    pabitra

    Reply
  • How do I add an index to my property page

    Posted by Legacy on 05/13/1999 12:00am

    Originally posted by: dominic

    I'm just a beginner so hopefully someone can help me

    I would like my tools button to display the property page when it's press.
    I have attached a variable=page number/index to that button and if it's press,
    the function SetActivePage(index) will execute. Now I don't know how to add an index to my property page. Can anyone help?

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

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds