📄 shortcut_keys.shtml.htm
字号:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Zafir Anjum">
<TITLE>PropertySheet - Using Shortcut Keys for Property Pages</TITLE>
</HEAD>
<body background="../fancyhome/back.gif" tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000" bgproperties="fixed">
<table WIDTH="100%">
<tr WIDTH="100%">
<td><A HREF="http://209.66.99.126/cgi/ads.cgi?advert=catalyst"><IMG SRC="../banners/catalyst.jpg" tppabs="http://www.codeguru.com/banners/catalyst.jpg" HEIGHT=60 WIDTH=468 ALT="Catalyst Development" BORDER=2></A><BR><SMALL><A HREF="http://209.66.99.126/cgi/ads.cgi?advert=catalyst">Click here for Free ActiveX Control</A></SMALL><td>
</tr>
</table>
<CENTER>
<H3>
<FONT COLOR="#AOAO99">Using Shortcut Keys for Property Pages</FONT>
<HR></H3></CENTER>
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.
<h4>Step 1: Assign shortcut keys to property pages</h4>
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.
<h4>Step 2: Override OnPreTranslateMessage</h4>
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.
<PRE><TT><FONT COLOR="#990000">
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);
}
</FONT></TT></PRE>
<P>
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="../index.htm" tppabs="http://www.codeguru.com/">Goto HomePage</A></FONT></TD>
<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>© 1997 Zafir Anjum</FONT> </CENTER>
</TD>
<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact me: <A HREF="mailto:zafir@home.com">zafir@home.com</A> </FONT></DIV>
</TD>
</TR>
</TABLE>
<CENTER><IMG SRC="../cgi/Count.cgi-ft=2&dd=E-df=ps_shortcut_keys.cnt" tppabs="http://www.codeguru.com/cgi/Count.cgi?ft=2&dd=E%7cdf=ps_shortcut_keys.cnt" ALIGN="BOTTOM" BORDER="0"></CENTER>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -