📄 index.html
字号:
switch to your application. For that, all you need to is to do a
::PostMessage (hDlg,WM_NULL,0,0); after the call to
TrackPopupMenu. </p>
<h4><a name="activex_size"></a>I have created an ActiveX control.
At design time, I would like it to behave like the Timer control
in Visual Basic. That is, when it is drawn on a from it
automatically sizes down (or up) to a certain size.How do I do
that?</h4>
<p>Check out KB article "HOWTO: Define the Display Size of
an MFC ActiveX Control" ID: Q168326. And "How to
Disable the Resizing of an OLE Control" ID: Q137538.</p>
<h4><a name="side_frame"></a>Is there a way to find out on which
side of the frame a controlbar is docked?</h4>
<p>First check whether the control bar is actually docked using
IsFloating(). Then, If its docked, Get the parent of the
ControlBar which will be CDockBar (Undocumented) and check the ID
of the given CDockBar. It should be one of
AFX_IDW_DOCKBAR_TOP</p>
<p>AFX_IDW_DOCKBAR_BOTTOM</p>
<p>AFX_IDW_DOCKBAR_RIGHT</p>
<p>AFX_IDW_DOCKBAR_LEFT</p>
<p>These are defined in afxres.h.</p>
<p>The following code will do that for you</p>
<p><code>int GetDockPos (CControlBar * pBar)</code></p>
<p><code>{</code></p>
<blockquote>
<p><code>if (!pBar->IsFloating ())</code></p>
</blockquote>
<blockquote>
<p><code>{</code></p>
</blockquote>
<blockquote>
<blockquote>
<p><code>int id = pBar->GetParent ()->GetDlgCtrlID
();</code></p>
<p><code>switch (id)</code></p>
<p><code>{</code></p>
<blockquote>
<p><code>case AFX_IDW_DOCKBAR_TOP:</code></p>
</blockquote>
<blockquote>
<p><code>// AfxMessageBox
("AFX_IDW_DOCKBAR_TOP");</code></p>
</blockquote>
<blockquote>
<p><code>break;</code></p>
</blockquote>
<blockquote>
<p><code>case AFX_IDW_DOCKBAR_BOTTOM:</code></p>
</blockquote>
<blockquote>
<p><code>// AfxMessageBox
("AFX_IDW_DOCKBAR_BOTTOM");</code></p>
</blockquote>
<blockquote>
<p><code>break;</code></p>
</blockquote>
<blockquote>
<p><code>case AFX_IDW_DOCKBAR_RIGHT:</code></p>
</blockquote>
<blockquote>
<p><code>// AfxMessageBox
("AFX_IDW_DOCKBAR_RIGHT");</code></p>
</blockquote>
<blockquote>
<p><code>break;</code></p>
</blockquote>
<blockquote>
<p><code>case AFX_IDW_DOCKBAR_LEFT:</code></p>
</blockquote>
<blockquote>
<p><code>// AfxMessageBox
("AFX_IDW_DOCKBAR_LEFT");</code></p>
</blockquote>
<blockquote>
<p><code>break;</code></p>
</blockquote>
<p><code>}</code></p>
<p><code>return id;</code></p>
</blockquote>
</blockquote>
<blockquote>
<p><code>}</code></p>
</blockquote>
<blockquote>
<p><code>return -1;</code></p>
</blockquote>
<p><code>}</code></p>
<h4><a name="default_folder"></a>How do you set a default folder
to be selected when you call SHBrowseFolder?</h4>
<p>The CDirDialog class which is available on codeguru does not
consider this possibility. So, Here is some code that you can use
to fix that.</p>
<p>You can use the callback feature of the SHBrowseForFolder..</p>
<p>set BROWSEINFO's lpfn = CallBackProc (whatever)</p>
<p>//This has to be a static member of CDirDialog.</p>
<p><code>int CALLBACK CDirDialog::CallbackProc (HWND hDlg, UINT
uMsg,LPARAM lParam, LPARAM lpData)</code></p>
<p><code>{</code></p>
<blockquote>
<p><code>switch (uMsg)</code></p>
</blockquote>
<blockquote>
<p><code>{</code></p>
</blockquote>
<blockquote>
<p><code>case BFFM_INITIALIZED:</code></p>
<blockquote>
<p><code>{</code></p>
<p><code>::SendMessage(hDlg, BFFM_SETSELECTION, 1,
"C:\\temp");</code></p>
<p><code>}</code></p>
<p><code>break;</code></p>
</blockquote>
<p><code>}</code></p>
<p><code>return 0;</code></p>
</blockquote>
<p><code>}</code></p>
<p>This does not work properly with UNC paths. It seems if you
use PIDL instead of the string path in lParam of
BFFM_SETSELECTION,it works correctly. You can get the code to do
that from the CDirDialog OnBrowse () function code. Its available
on this site.</p>
<h4><a name="long_filename"></a>How can I get the complete long
filename of a file (path and filename) if I know his short
filename (8.3 format) ?</h4>
<p>See the help for SHGetFileInfo () API. That can take a short
file name and get you the long file name if there is one.</p>
<h4><a name="drive_type"></a>I know how to get a drive type, but
how do i know if the drive is a 3 1/2, 5 3/4?</h4>
<p>See the KB article "HOWTO: Getting Floppy Drive Type
Information" Article ID: Q163920.</p>
<h4><a name="Enter_tab">How to make Enter (VK_ENTER) to act like
a tab in a dialog box?</a></h4>
<p>This is one of the most often asked question. The Windows user
interface design goes against this. But, Hey , Who am I to argue?
I will give the solution here. If you want to use it, go right
ahead and use it. But, If the UI Police catch you, don’t
blame me.You can either handle OnOK () and check the currently
focused control (GetFocus()) and use GetDlgCtrlID () to check the
ID of the control which has the focus,and if its IDOK , call
CDialog::OnOK (), otherwise, set the focus to next ctrl using
NextDlgCtrl () which might look something like</p>
<p><code>void CMyDlg:: OnOK()</code></p>
<p><code>{</code></p>
<blockquote>
<p><code>CWnd *pWnd = GetFocus();</code></p>
<p><code>ASSERT (pWnd);</code></p>
<p><code>if (IDOK == pWnd ->GetDlgCtrlID())</code></p>
<p><code>{</code></p>
<blockquote>
<p><code>CDialog::OnOK();</code></p>
</blockquote>
<p><code>}</code></p>
<p><code>else</code></p>
<p><code>{</code></p>
<blockquote>
<p><code>NextDlgCtrl();</code></p>
</blockquote>
<p><code>}</code></p>
</blockquote>
<p><code>}</code></p>
<p> </p>
<p>Or process the messages WM_KEYDOWN with VK_ENTER using
PreTranslateMessage<br>
() (in case of modeless dialog) or CWinApp::ProcessMessageFilter
() (in case<br>
of modal dialog) and do the necessary.</p>
<h4><a name="disabled_tooltip"></a>How can I display tooltips for
disabled controls (for example CEdit)??</h4>
<p>Answer by <a href="mailto:davidl@mvps.org">David lowndes</a>:</p>
<p>I wrestled with this same problem several weeks ago. For an
MFC dialog</p>
<p>I found the following works for me:</p>
<p>The CWnd class has its own tooltip control built in. Therefore
all I do is:</p>
<p><font face="Times New Roman"><code>BEGIN_MESSAGE_MAP(CMfcDlgttDlg,
CDialog)</code></font></p>
<p><font face="Times New Roman"><code>//{{AFX_MSG_MAP(CMfcDlgttDlg)</code></font></p>
<p><font face="Times New Roman"><code>...</code></font></p>
<p><font face="Times New Roman"><code>//}}AFX_MSG_MAP</code></font></p>
<p><font face="Times New Roman"><code>ON_NOTIFY_EX( TTN_NEEDTEXT,
0, HandleNeedText )</code></font></p>
<p><font face="Times New Roman"><code>END_MESSAGE_MAP()</code></font></p>
<p><font face="Times New Roman"><code>....</code></font></p>
<p><font face="Times New Roman"><code>BOOL
CMfcDlgttDlg::HandleNeedText( UINT id, NMHDR * pNMHDR, LRESULT
*pResult )</code></font></p>
<p><font face="Times New Roman"><code>{</code></font></p>
<blockquote>
<p><font face="Times New Roman"><code>TOOLTIPTEXT *pTTT =
(TOOLTIPTEXT *)pNMHDR;</code></font></p>
<p><font face="Times New Roman"><code>UINT nID
=pNMHDR->idFrom;</code></font></p>
<p><font face="Times New Roman"><code>if (pTTT->uFlags
& TTF_IDISHWND)</code></font></p>
<p><font face="Times New Roman"><code>{</code></font></p>
<blockquote>
<p><font face="Times New Roman"><code>
// idFrom is actually the HWND of the tool</code></font></p>
<p><font face="Times New Roman"><code>nID =
::GetDlgCtrlID((HWND)nID);</code></font></p>
<p><font face="Times New Roman"><code>if(nID)</code></font></p>
<p><font face="Times New Roman"><code>{</code></font></p>
<blockquote>
<p><font face="Times New Roman"><code>/* Assumes you
have a string resource with the same ID as the dialog
control ID for the tooltip text */</code></font></p>
<p><font face="Times New Roman"><code>pTTT->lpszText
= MAKEINTRESOURCE(nID);</code></font></p>
<p><font face="Times New Roman"><code>pTTT->hinst
= AfxGetResourceHandle();</code></font></p>
<p><font face="Times New Roman"><code>return(TRUE);</code></font></p>
</blockquote>
</blockquote>
<blockquote>
<p><font face="Times New Roman"><code> }</code></font></p>
</blockquote>
<p><font face="Times New Roman"><code>}</code></font></p>
<p><font face="Times New Roman"><code>return(FALSE);</code></font></p>
</blockquote>
<p><font face="Times New Roman"><code>}</code></font></p>
<p>And in OnInitDialog I call EnableToolTips().</p>
<p>There's no tooltip control to add/create, no AddTool calls,
and no PreTranslateMessage needed. It seems to work fine for me.
Let me know if it works for you (if you try it of course).</p>
<p><strong>Note</strong>: I have not tested this. BTW, If you are
using VC 5.0 SP1 or SP2 , it seems that there is some problem
with the toolhit test due to the TOOLTESTINFO size change. See
this KB article "<strong>Bug: CToolTipCtrl Does not display
Text after Installing VC SP1" ID: Q172276. </strong>For a
clean fix. Or get SP3 which seems to have fixed the problem.</p>
<p align="right">Girish</p>
<h4><a name="tab_problem"></a>I have embedded a property sheet
and it's pages to a CFormView.Both property pages and CFromView
contains controls such like edit-fields,buttons, comboboxes
etc.The problem is that sometimes when the focus is in property
page it does not come out of there and go to CFormview's
controls. Why?? I have tried to set WS_EX_CONTROLPARENT and
sometimes it works.BUT when I embed ocx-control to property page
I can't EVER set focus to CFormViews controls with tab key ...Is
there any flags to set? Or any methods to override in
ocx-control?</h4>
<p>It seems to be a bug. Try putting this code in the
CPropertySheet::PreTranslateMessage ().</p>
<p>This problem occurs even on the dialogs with property sheet in
it and have an Activex control.</p>
<p><font face="Times New Roman"><code>BOOL
CPropSheet::PreTranslateMessage(MSG* pMsg)</code></font></p>
<p><font face="Times New Roman"><code>{</code></font></p>
<blockquote>
<p><font face="Times New Roman"><code>/*First Property Sheet
tab key translation allow sheet to translate Ctrl+Tab,
Shift+Ctrl+Tab, Ctrl+PageUp, and Ctrl+PageDown */</code></font></p>
<p><font face="Times New Roman"><code>if (pMsg->message ==
WM_KEYDOWN && GetAsyncKeyState(VK_CONTROL) < 0
&&</code></font></p>
<p><font face="Times New Roman"><code> (pMsg->wParam
== VK_TAB || pMsg->wParam == VK_PRIOR || pMsg->wParam
== VK_NEXT))</code></font></p>
<p><font face="Times New Roman"><code> {</code></font></p>
<blockquote>
<p><font face="Times New Roman"><code>
if (SendMessage(PSM_ISDIALOGMESSAGE, 0, (LPARAM)pMsg))</code></font></p>
<blockquote>
<p><font face="Times New Roman"><code> return
TRUE;</code></font></p>
</blockquote>
</blockquote>
<p><font face="Times New Roman"><code> }</code></font></p>
<p><font face="Times New Roman"><code>/*Check for the Dialog
handling by the PropertyPage*/</code></font></p>
<p><font face="Times New Roman"><code> if
(IsDialogMessage (pMsg))</code></font></p>
<blockquote>
<p><font face="Times New Roman"><code> return
TRUE;</code></font></p>
</blockquote>
<p><font face="Times New Roman"><code> else
if (CWnd::PreTranslateMessage(pMsg)) /*Last , see if the
window wants to handle this message*/</code></font></p>
<blockquote>
<p><font face="Times New Roman"><code> return
TRUE;</code></font></p>
</blockquote>
<p><font face="Times New Roman"><code>
return FALSE; /*Nobody wants it so return false */</code></font></p>
</blockquote>
<p><font face="Times New Roman"><code>}</code></font></p>
<p> </p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -