HOWTO: Jump to a Particular Page in a Property Sheet.
ID: Q198439
|
The information in this article applies to:
-
Microsoft Win32 Software Development Kit (SDK)
on the following platforms: NT, Win95, Win98
SUMMARY
Usually, the CTRL+TAB or CTRL+SHIFT+TAB key combination is used to navigate
between the pages in a property sheet. This navigation is sequential,
however, and it is not possible to jump to a particular page using the
keyboard. By using mnemonics for each page and trapping the key strokes,
you can jump to a particular page in a property sheet.
MORE INFORMATION
The following steps illustrate how to add mnemonics to a page and how to
trap the key strokes to check for the mnemonics. The sample code that
follows uses a WH_GETMESSAGE hook to examine the keys pressed. If the key
pressed happens to be a combination of the ALT key and the key designated
for a particular page, then that page is activated.
- When initializing the PROPSHEETHEADER structure, include the
PSH_USECALLBACK flag in the dwFlags member variable, and assign a
callback function to the pfnCallback member variable.
- The callback function could be written as shown below:
int CALLBACK PropSheetCallbackProc(HWND hwndDlg, UINT uMsg, LPARAM
lParam)
{
if (uMsg == PSCB_INITIALIZED)
{
g_hWndPropSheet = hwndDlg; //Store the window handle of the
//property sheet in a global
//variable.
g_hhook = SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)hkProc,
NULL,GetWindowThreadProcessId(g_hWndPropSheet,NULL));
}
return 0;
}
- When initializing the PROPSHEETPAGE structure, use the mnemonic prefix
(&) in the "pszTitle" member variable to designate a letter for a
particular page. This letter, when pressed in combination with the ALT
key, would activate this page.
Sample Code for the Hook Filter Function
To trap the key strokes and to examine them, the hook filter function could
be written as shown below:
LRESULT CALLBACK hkProc(UINT nCode, WPARAM wParam, LPARAM lParam)
{
if ( nCode < 0 )
{
return CallNextHookEx(g_hhook,nCode,wParam,lParam);
}
if ( ((MSG *)lParam)->message == WM_SYSCHAR )
{
HWND hTabCtrl = (HWND)
SendMessage(g_hWndPropSheet,PSM_GETTABCONTROL,0,0);
int nCount = SendMessage(hTabCtrl,TCM_GETITEMCOUNT,0,0);
TCHAR buf[80],shortcutLower[3],shortcutUpper[3];
TC_ITEM tcItem;
tcItem.mask = TCIF_TEXT;
tcItem.pszText = buf;
shortcutUpper[0] = shortcutLower[0] = _T('&');
shortcutUpper[2] = shortcutLower[2] = _T('\0');
for( int i = 0; i < nCount; i++ )
{
tcItem.cchTextMax = 79;
SendMessage(hTabCtrl,TCM_GETITEM,i,(LONG)&tcItem);
shortcutUpper[1] = shortcutLower[1] =
(TCHAR) ((MSG *)lParam)->wParam;
if ( _istlower(shortcutUpper[1]) )
shortcutUpper[1] = _totupper(shortcutUpper[1]);
if ( _istupper(shortcutLower[1]) )
shortcutLower[1] = _totlower(shortcutLower[1]);
if ( _tcsstr( buf, shortcutLower ) ||
tcsstr(buf,shortcutUpper) )
{
PropSheet_SetCurSel(g_hWndPropSheet,NULL,i);
((MSG *)lParam)->message = WM_NULL; // We have taken care of
// the message, so make
// it WM_NULL.
}
}
}
return CallNextHookEx(g_hhook,nCode,wParam,lParam);
}
Additional query words:
kbDSupport
Keywords : kbHook kbNTOS kbPropSheet kbSDKWin32 kbWinOS95 kbWinOS98
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbhowto