⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index.html

📁 随书类文件![随书类]MFC_SOURCEBOOK
💻 HTML
📖 第 1 页 / 共 3 页
字号:
            <p><code>rect.top -= 1;</code></p>
        </blockquote>
        <blockquote>
            <p><code>m_wndToolBar.GetParentOwner
            ()-&gt;MoveWindow(rect,TRUE); </code></p>
        </blockquote>
        <blockquote>
            <p><code>// I am doing this in order to get the
            toolbar to paint itself</code></p>
        </blockquote>
        <blockquote>
            <p><code>bFirstTime = false;</code></p>
        </blockquote>
    </blockquote>
    <blockquote>
        <p><code>}</code></p>
    </blockquote>
</blockquote>

<blockquote>
    <p><code>}</code></p>
</blockquote>

<blockquote>
    <p><code>else</code></p>
</blockquote>

<blockquote>
    <blockquote>
        <p><code>bFirstTime = true;</code></p>
    </blockquote>
</blockquote>

<blockquote>
    <p><code>CFrameWnd::OnTimer(nIDEvent);</code></p>
</blockquote>

<p><code>}</code></p>

<p>This will take care of the problem. There might be a better
way, If someone does, please tell me. I will update it here.</p>

<h4><a name="accel_modeless"></a>How to use accelerators in a
modeless dialog box with MFC?</h4>

<p>See this KB article Using Accelerators with an MFC Modeless
Dialog Box&quot; ID:Q117500.</p>

<h4><a name="arrow_cform"></a>I've wrote a custom control and use
it in CFormView. Now the problem is, that I want to use the
arrwokeys in this control. I can't catch this key with
WM_KEYDOWN. By default the key changes the focus to the next
control. How can I capture the arrow-keys in my custom control ?</h4>

<p>You need to handle WM_GETDLGCODE i.e.. OnGetDlgCode and return
DLGC_WANTARROWS there.Then you will get VK_LEFT, VK_UP etc. in
your WM_KEYDOWN (OnKeyDown) which you can handle.</p>

<h4><a name="default_propsheet"></a>How to set the default button
in a property Sheet?</h4>

<p>Check out KB article &quot;How to Change Default Button on
CPropertySheet&quot; ID:Q140587.</p>

<h4><a name="disable_propsheet"></a>How to disable a property
page in a property Sheet?</h4>

<p>See this KB article &quot;How To Disable Tabs in
CPropertySheet&quot; ID:Q151662. And there was an article by Paul
Delascia about grayed out tabs on a property sheet on FEB 98 MSJ.
See that also. That has a better effect to show.</p>

<h4><a name="Richedit_dlg"></a>How do I use RichEdit Control in a
dialog? If I just insert it on the dialog, the application just
does not start.</h4>

<p>The trick is to call AfxInitRichEdit () before calling the
DoModal () or Create() of the CDialog which contains the Rich
edit control.</p>

<h4><a name="DoPrompt"></a>Does anyone know what parameters are
passed to CWinApp::DoPromptFileName()?</h4>

<p>Not that many people use this, but since this is the one used
by CWinApp::OnFileOpen , i might as well give the descripition as
I understood.</p>

<p>DoPromptFileName () is a public but undocumented member
function of CWinApp.It needs similar parameters as FileDialog and
the first parameter is CString&amp; which will be filled by the
selected filename if the user selects one and the others are not
hard to understand.</p>

<p>This is the declaration of that function in CWinApp.</p>

<p>This returns True, if the user pressed OK else False.</p>

<p><code>BOOL DoPromptFileName(</code></p>

<p><code>CString&amp; fileName, /* [in,out]. You input the name
of the file to be</code></p>

<p><code>shown in the beginning. if the user does an ok on the
dialog, this will</code></p>

<p><code>be filled with the selected filename.*/</code></p>

<p><code>UINT nIDSTitle, /* ID in the string table for title of
the Dialog box</code></p>

<p><code>which comes up */</code></p>

<p><code>DWORD lFlags, /* m_ofn.flags */</code></p>

<p><code>BOOL bOpenFileDialog,&nbsp; /* to open or to save */</code></p>

<p><code>CDocTemplate* pTemplate /* doc tempate */</code></p>

<p><code>);</code></p>

<p>You can use this somewhat like this,</p>

<p><font size="2" face="Courier New"><var>CString mess =
&quot;Whatever&quot;;</var></font></p>

<p><font size="2" face="Courier New"><var>if
(AfxGetApp()-&gt;DoPromptFileName
(mess,AFX_IDS_APP_TITLE,OFN_HIDEREADONLY | OFN_FILEMUSTEXIST,
TRUE, NULL))</var></font></p>

<blockquote>
    <p><font size="2" face="Courier New"><var>AfxMessageBox
    (mess);</var></font></p>
</blockquote>

<p>This works fine with the doc/view classes, but might not work
on dialogs.And as a final word of caution, This is an
implementation function and is a helper for MFC classes. The
implementation might change and you might be in a mess.</p>

<h4><a name="redirect_dos"></a>Can someone tell me how to
redirect (or catch) a DOS window output to a file or array.&nbsp;
The output is a black screen that comes up with a
WinExec(&quot;doscommand&quot;,SW_SHOWMINIMIZED) line. I tried to
have the command use the standard redirection parameters
&quot;&gt;&quot;, but this doesn't get any output.</h4>

<p>Check out this KB article &quot;Redirection Issues on Windows
95 MS-DOS Apps and Batch Files&quot; ID:Q150956. </p>

<h4><a name="append_top"></a>How do I append a couple of Menu
resources during run time at the top level?</h4>

<p>Try Something like this </p>

<p>menu and menu2 are declared as member variables of the class,
Since,they should exist till the end.</p>

<p><code>{</code></p>

<blockquote>
    <p><code>menu.LoadMenu (IDR_MENU1);</code></p>
</blockquote>

<blockquote>
    <p><code>menu2.LoadMenu (IDR_MENU2);</code></p>
</blockquote>

<blockquote>
    <p><code>MENUITEMINFO mi;</code></p>
</blockquote>

<blockquote>
    <p><code>mi.cbSize = sizeof (MENUITEMINFO);</code></p>
</blockquote>

<blockquote>
    <p><code>mi.fMask = MIIM_SUBMENU|MIIM_TYPE;</code></p>
</blockquote>

<blockquote>
    <p><code>mi.fType = MFT_STRING;</code></p>
</blockquote>

<blockquote>
    <p><code>mi.fState =MFS_ENABLED; </code></p>
</blockquote>

<blockquote>
    <p><code>mi.wID = 0;</code></p>
</blockquote>

<blockquote>
    <p><code>mi.hSubMenu = menu2.GetSafeHmenu (); </code></p>
</blockquote>

<blockquote>
    <p><code>mi.hbmpChecked = NULL;</code></p>
</blockquote>

<blockquote>
    <p><code>mi.dwTypeData = &quot;Whatever&quot;; /*Change this
    to the topname You can get</code></p>
</blockquote>

<blockquote>
    <p><code>the string of the Menu you are trying to append and
    put it here.</code></p>
</blockquote>

<blockquote>
    <p><code>then you will have to have hSubMenu =
    menu2.GetSubMenu */</code></p>
</blockquote>

<blockquote>
    <p><code>(index)-&gt;GetSafeHmenu ();</code></p>
</blockquote>

<blockquote>
    <p><code>mi.cch = 8; //Change this to the length of the text</code></p>
</blockquote>

<blockquote>
    <p><code>if (InsertMenuItem&nbsp; (menu.GetSafeHmenu
    (),3,TRUE, &amp;mi))</code></p>
</blockquote>

<blockquote>
    <p><code>{</code></p>
</blockquote>

<blockquote>
    <blockquote>
        <p><code>AfxMessageBox (&quot;Success&quot;);</code></p>
    </blockquote>
</blockquote>

<blockquote>
    <p><code>}</code></p>
</blockquote>

<blockquote>
    <p><code>else</code></p>
</blockquote>

<blockquote>
    <p><code>{</code></p>
</blockquote>

<blockquote>
    <blockquote>
        <p><code>DWORD dwError&nbsp; = GetLastError ();</code></p>
    </blockquote>
    <blockquote>
        <p><code>AfxMessageBox (&quot;Failure&quot;);</code></p>
    </blockquote>
</blockquote>

<blockquote>
    <p><code>}</code></p>
</blockquote>

<blockquote>
    <p><code>::SetMenu (m_hWnd, menu);</code></p>
</blockquote>

<blockquote>
    <p><code>::DrawMenuBar (m_hWnd);</code></p>
</blockquote>

<p><code>}</code></p>

<p>There are other ways of doing this too. </p>

<h4><a name="app_path"></a>I need to open a file which is in the
same directory as the application. How do I get the application
path?</h4>

<p>GetModuleFileName () API gives the complete path of the given
application. You can use NULL for hModule to get the current
application.</p>

<h4><a name="resize_jumps"></a>How to resize a window in jumps?</h4>

<p>Check out KB article &quot;SAMPLE: RESIZE App Shows How to
Resize a Window in Jumps&quot; ID:Q123605. Sample is a plain C
app. But, converting it to MFC should not be a big problem.</p>

<h4><a name="process_list"></a>Is there an API or MFC call I can
make to see what applications are currently running on someone's
workstation?</h4>

<p>This has to be implemented differently in 95 and NT. </p>

<p>The following code works for 95 only.</p>

<p>Check out Tlhelp32.h and the set of functions exposed
there.You will be interested in CreateToolhelp32Snapshot (),
Process32First and Process32Next. The code might look like this</p>

<p><code>void CCheckListView::FillProcessInfo ()</code></p>

<p><code>{</code></p>

<blockquote>
    <p><code>HANDLE hSnapshot;</code></p>
    <p><code>BOOL fOK;</code></p>
    <p><code>PROCESSENTRY32 pe32;</code></p>
    <p><code>unsigned cProcesses = 0;</code></p>
    <p><code>// create a process snapshot and walk through the
    process list</code></p>
    <p><code>hSnapshot = CreateToolhelp32Snapshot(
    TH32CS_SNAPPROCESS, 0 );</code></p>
    <p><code>if ( !hSnapshot ) return;</code></p>
    <p><code>CString cstr;</code></p>
    <p><code>pe32.dwSize = sizeof(pe32);&nbsp;&nbsp;&nbsp;&nbsp;
    // Gotta initialize dwSize!</code></p>
    <p><code>for ( fOK = Process32First( hSnapshot, &amp;pe32
    );fOK;fOK = Process32Next( hSnapshot, &amp;pe32 ) )</code></p>
    <p><code>{</code></p>
    <blockquote>
        <p><code>processInfo.m_pID = pe32.th32ProcessID;</code></p>
        <p><code>cstr = pe32.szExeFile;</code></p>
        <p><code>//Here you have the name of one of the
        processes.</code></p>
        <p><code>// TODO, use cstr to put the string to any place
        to access it later..</code></p>
    </blockquote>
    <p><code>}</code></p>
    <p><code>CloseHandle( hSnapshot );&nbsp;&nbsp; // Done with
    this snapshot.&nbsp; Free it</code></p>
</blockquote>

<p><code>}</code></p>

<p>I found this code in an old MSJ. I am not sure which one.
Anyway, Matt Pietrek is the one who had written that. He has also
written code to do the same thing on NT. You need to use
EnumProcesses () and other PSAPI functions to achieve that. See
oct 97 WDJ (windows developers journal) which has code to
(oct97.zip -&gt; esposito.zip) which has code to do something
similar. Again, that code is in C not in MFC.</p>

<h4><a name="proppage_font"></a>How to change fonts on a property
page?</h4>

<p>Check out KB article &quot;SAMPLE: PRPFONT - How to Set
CPropertySheet Fonts&quot; ID:Q142170. </p>

<h4><a name="toolbar_dlg"></a>Is there any way to attach a
toolbar and a status bar to a dialog box?</h4>

<p>You can check out DLGCBR32 sample and the KB article
&quot;SAMPLE: Adding Control Bars to Foundation Classes
Dialogs&quot; Article ID: Q123158.</p>

<h4><a name="trackpopup"></a>Can anyone tell me why
TrackPopupMenu (and variations thereof) won't return if the user
clicks on any window my app doesn't own?</h4>

<p>Check out this KB article &quot;PRB: Menus for Notification
Icons Don't Work Correctly&quot;Article ID: Q135788. That tells
you what to do. Basically, you just need to force a context

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -