📄 visual c++编程小技巧之九.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0038)http://www.vchome.net/tech/vctip9.html -->
<HTML><HEAD><TITLE>Visual C++编程小技巧之九</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 5.50.4134.100" name=GENERATOR>
<META content=sss name=doccomm>
<META content=C:\MSOffice\Template\Sl_BOOK.dot name=Template>
<META content="Cheng Jinxing" name=Author></HEAD>
<BODY text=#000000 vLink=#551a8b aLink=#ff0000 link=#0000ee bgColor=#ccffff>
<P align=center><BR><FONT size=+3><FONT face="Times New Roman">Visual
C++</FONT><FONT face=楷体_GB2312>编程小技巧之九</FONT></FONT> </P>
<P><FONT size=+0><A href="http://www.vchome.net/tech/vctip9.html#tip68"><FONT
face="Times New Roman">68. VC1.5</FONT>下如何跳到第一事例<FONT
face="Times New Roman">?</FONT></A></FONT> </P>
<P><FONT size=+0><A href="http://www.vchome.net/tech/vctip9.html#tip69"><FONT
face="Times New Roman">69. </FONT>为什么<FONT
face="Times New Roman">VC++2.0</FONT>中使用文件对话框会死机<FONT
face="Times New Roman">?</FONT></A></FONT> </P>
<P><FONT size=+0><A href="http://www.vchome.net/tech/vctip9.html#tip70"><FONT
face="Times New Roman">70. </FONT>在<FONT
face="Times New Roman">VC++1.5</FONT>中如何<FONT
face="Times New Roman">new</FONT>一个大数组<FONT
face="Times New Roman">?</FONT></A></FONT> </P>
<P><FONT size=+0><A href="http://www.vchome.net/tech/vctip9.html#tip71"><FONT
face="Times New Roman">71. </FONT>在<FONT
face="Times New Roman">VC1.5</FONT>中,如何得到子窗口在主窗口中的相对坐标?</A></FONT> </P>
<P><FONT size=+0><A href="http://www.vchome.net/tech/vctip9.html#tip72"><FONT
face="Times New Roman">72. VC1.5 </FONT>如何调用进程<FONT
face="Times New Roman">?</FONT></A></FONT> </P>
<P><FONT size=+0><A href="http://www.vchome.net/tech/vctip9.html#tip73"><FONT
face="Times New Roman">73. VC++1.5</FONT>编<FONT
face="Times New Roman">Win3.1</FONT>程序能否实现全局跳转<FONT
face="Times New Roman">?</FONT></A></FONT> </P>
<P><FONT size=+0><A href="http://www.vchome.net/tech/vctip9.html#tip74"><FONT
face="Times New Roman">74. </FONT>如何在<FONT
face="Times New Roman">DLL</FONT>用自定义窗口<FONT
face="Times New Roman">?</FONT></A></FONT> </P>
<P><FONT size=+0><A href="http://www.vchome.net/tech/vctip9.html#tip75"><FONT
face="Times New Roman">75. </FONT>如何让<FONT
face="Times New Roman">TOOLTIP</FONT>的字体变大<FONT
face="Times New Roman">?</FONT></A></FONT> </P>
<P><FONT size=+0> </FONT> </P>
<P><A name=tip68></A><B><FONT size=+2><FONT
face="Times New Roman">68.VC1.5</FONT><FONT face=黑体>下如何跳到第一事例</FONT><FONT
face="Times New Roman">?</FONT></FONT></B> </P>
<P><FONT size=+0>各位大虾<FONT face="Times New Roman">:
CWinApp::InitInstance()</FONT>中可知是第二事例<FONT
face="Times New Roman">,</FONT>但如何在<FONT face="Times New Roman">return
FALSE;</FONT></FONT> </P>
<P><FONT size=+0>之前<FONT face="Times New Roman">FindWindow()</FONT>到第一事例呢<FONT
face="Times New Roman">? </FONT>主要困难是<FONT
face="Times New Roman">:</FONT></FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">1).</FONT>主窗口类名可否得到 <FONT
face="Times New Roman">( </FONT>主窗口<FONT face="Times New Roman">==MainFrame ?
</FONT>若是<FONT face="Times New Roman">,</FONT>怎知<FONT
face="Times New Roman">MainFrame</FONT>类名<FONT
face="Times New Roman">?</FONT></FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">2).Title</FONT>因含有文档名<FONT
face="Times New Roman">, </FONT>是一不确定串<FONT
face="Times New Roman">.</FONT></FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">1.
</FONT>类名是动态的,所以应该不易得到。(不知是否如此?)</FONT> </P>
<P><FONT size=+0>类名不是动态的,如果不作处理, <FONT face="Times New Roman">MFC </FONT>总是使用
<FONT face="Times New Roman">AfxFrameOrView </FONT>为类名,</FONT> </P>
<P><FONT size=+0>只有 <FONT face="Times New Roman">MainFrame, </FONT>和 <FONT
face="Times New Roman">View </FONT>等等才会用 <FONT
face="Times New Roman">AfxFrameOrView,</FONT></FONT> </P>
<P><FONT size=+0>我刚用 <FONT face="Times New Roman">spy </FONT>看了我的一个程序,主窗口的<FONT
face="Times New Roman">Class </FONT>为 <FONT
face="Times New Roman">Afx:b:13ce:6:3be7</FONT></FONT> </P>
<P><FONT size=+0>至于如何注册自己定义的类,我还没有学会,望高手指教。</FONT> </P>
<P><FONT face="Times New Roman" size=+0>AfxRegisterWndClass()</FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">2. </FONT>我用的方法是只查<FONT
face="Times New Roman">Title</FONT>中前半部分和你的要求串一致即可,忽略后面的文档<FONT
face="Times New Roman">?</FONT></FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">FindWindow()
</FONT>函数需要给定窗口类名和窗口标题(<FONT
face="Times New Roman">Title</FONT>),不知你是怎样做到只查前半部分的?</FONT> </P>
<P><FONT size=+0>用<FONT face="Times New Roman">EnumWindows()</FONT>一个窗口一个窗口查,不能用
<FONT face="Times New Roman">FindWindow()</FONT></FONT> </P>
<P><FONT size=+0>这里我有另外一个问题:</FONT> </P>
<P><FONT size=+0>找到第一事例的窗口后,如何激活它,使它成为当前窗口?</FONT> </P>
<P><FONT size=+0>极小状态时,才能把它激活出来,否则也是没有动静,不知何故?</FONT> </P>
<P><FONT face="Times New Roman" size=+0>if (IsIconic(hwndMain))</FONT> </P>
<P><FONT face="Times New Roman" size=+0>ShowWindow(hwndMain, SW_RESTORE);</FONT>
</P>
<P><FONT face="Times New Roman" size=+0>else</FONT> </P>
<P><FONT face="Times New Roman" size=+0>SetActiveWindow(hwndMain);</FONT> </P>
<P><FONT size=+0> </FONT> </P>
<P><A name=tip69></A><B><FONT size=+2><FONT face=黑体>69.关于</FONT><FONT
face="Times New Roman">VC++2.0</FONT><FONT face=黑体>中使用文件对话框的求助</FONT></FONT></B>
</P>
<P><FONT size=+0>在<FONT face="Times New Roman">VC++2.0</FONT>中使用了标准文件对话框以后<FONT
face="Times New Roman">,</FONT>编译联接都能正常通过,而且使用<FONT
face="Times New Roman">Ctrl+F5</FONT>执行<FONT
face="Times New Roman">EXE</FONT>文件也完全正常<FONT
face="Times New Roman">,</FONT>但是一旦用<FONT face="Times New Roman">F5</FONT>调试进入,
使用该对话框的代码时<FONT face="Times New Roman">,Win95</FONT>就会异常中止<FONT
face="Times New Roman">,</FONT>请问各位高手<FONT
face="Times New Roman">,</FONT>为什么<FONT face="Times New Roman">?</FONT></FONT>
</P>
<P><FONT
size=+0>文件对话框,改变了执行程序的当前路径,从而干扰了调试系统。如果是为了调试,可以使文件对话框定位在当前目录,并且运行时不要在其中改变目录。</FONT>
</P>
<P><FONT size=+0> </FONT> </P>
<P><A name=tip70></A><B><FONT size=+2><FONT face=黑体>70.如何用</FONT><FONT
face="Times New Roman">VC2.0</FONT><FONT face=黑体>编写能</FONT><FONT
face="Times New Roman">Edit</FONT><FONT face=黑体>超过</FONT><FONT
face="Times New Roman">64K</FONT><FONT face=黑体>的类</FONT></FONT></B> </P>
<P><FONT size=+0>我要用 <FONT face="Times New Roman">VC2.0 </FONT>编写一个 <FONT
face="Times New Roman">Editor, </FONT>要求能编辑超过 <FONT face="Times New Roman">64K
</FONT>的文本<FONT face="Times New Roman">.</FONT>我的 <FONT
face="Times New Roman">Edit </FONT>类从 <FONT face="Times New Roman">CEdit
</FONT>类派生出来 <FONT face="Times New Roman">, </FONT>但编辑超过 <FONT
face="Times New Roman">64K </FONT>的文本就显示不出来<FONT face="Times New Roman">.
</FONT>原知道在 <FONT face="Times New Roman">VC1.5 </FONT>中 <FONT
face="Times New Roman">CEdit </FONT>类只能编辑小于 <FONT face="Times New Roman">64K
</FONT>的文本<FONT face="Times New Roman">,</FONT>不知 <FONT
face="Times New Roman">VC2.0 </FONT>是否也一样<FONT
face="Times New Roman">?</FONT></FONT> </P>
<P><FONT face="Times New Roman" size=+0>.</FONT> </P>
<P><FONT size=+0>自己从<FONT
face="Times New Roman">CWnd</FONT>类派生,管理内存、输入、显示等(其实不累)。至于从<FONT
face="Times New Roman">CEdit</FONT>中派生,我也没有头绪。</FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">VC2.0</FONT>会有这事?我没试过,但我不相信。<FONT
face="Times New Roman">VC2.0</FONT>是运行在<FONT
face="Times New Roman">Win95</FONT>或<FONT face="Times New Roman">WindowsNT
</FONT>上的开发工具,是<FONT face="Times New Roman">Win32</FONT>的开发工具。<FONT
face="Times New Roman">Windows 95</FONT>及<FONT
face="Times New Roman">NT</FONT>对应用程序在内存上没有段的限制,应用程序最多可利用高达<FONT
face="Times New Roman">4G</FONT>的内存<FONT
face="Times New Roman">(</FONT>包括系统占用<FONT
face="Times New Roman">)</FONT>。你所说的限制大概是<FONT
face="Times New Roman">VC1.5</FONT>的限制吧。盖因<FONT
face="Times New Roman">VC1.5</FONT>运行于<FONT
face="Times New Roman">Win16</FONT>上,每个段不能超过<FONT
face="Times New Roman">64K</FONT>。</FONT> </P>
<P><FONT size=+0>的确如此,<FONT face="Times New Roman">VC2.0 </FONT>有两个例子 <FONT
face="Times New Roman">samples\mfc\multipad </FONT>和 <FONT
face="Times New Roman">samples\mfc\superpad </FONT>也是如此。不信你看看。</FONT> </P>
<P><FONT size=+0> </FONT> </P>
<P><A name=tip71></A><B><FONT size=+2><FONT face=黑体>71.在</FONT><FONT
face="Times New Roman">VC++1.5</FONT><FONT face=黑体>中如何</FONT><FONT
face="Times New Roman">new</FONT><FONT face=黑体>一个大数组</FONT></FONT></B> </P>
<P><FONT size=+0>我想在用<FONT face="Times New Roman">VC++1.5</FONT>编程时,<FONT
face="Times New Roman">new</FONT>一个<FONT
face="Times New Roman">[512][512]</FONT>的大数组,却总是不行.</FONT> </P>
<P><FONT size=+0>哪位专家可以指点一下.</FONT> </P>
<P><FONT size=+0>选用<FONT face="Times New Roman">Larger and
Huger</FONT>模式的库编译</FONT> </P>
<P><FONT size=+0>我用过<FONT face="Times New Roman">Large</FONT>模式,好象不行呀!我用<FONT
face="Times New Roman">Huge</FONT>模式,头文件编译时就出错了!</FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">VC++ 1.5 </FONT>毕竟是<FONT
face="Times New Roman">16</FONT>的<FONT face="Times New Roman">, 512*512
</FONT>是多少?做链表好了否则就用<FONT face="Times New Roman">VC++2.0, </FONT>全<FONT
face="Times New Roman">32</FONT>位就不该有这问题了</FONT> </P>
<P><FONT size=+0>这样的做法并不十分好<FONT
face="Times New Roman">,</FONT>要分配如此大的内存最好用全局的内存分配函数<FONT
face="Times New Roman">.</FONT>直接用指针操作<FONT
face="Times New Roman">,</FONT>效率也会提高<FONT
face="Times New Roman">.</FONT></FONT> </P>
<P><FONT size=+0>用<FONT face="Times New Roman">MFC</FONT>类不行吗<FONT
face="Times New Roman">?</FONT>如<FONT
face="Times New Roman">CObArray</FONT></FONT> </P>
<P><FONT size=+0>请用<FONT face="Times New Roman">GlobalAllocPtr</FONT>和<FONT
face="Times New Roman">GlobalFreePtr</FONT>这一对函数,如下:</FONT> </P>
<P><FONT face="Times New Roman" size=+0>DWORD dwSize ;;</FONT> </P>
<P><FONT face="Times New Roman" size=+0>hpsStr =(char huge *)GlobalAllocPtr(
GMEM_MOVEABLE , dwSize ) ;</FONT> </P>
<P><FONT face="Times New Roman" size=+0>...</FONT> </P>
<P><FONT face="Times New Roman" size=+0>GlobalFreePtr( hpsStr ) ;</FONT> </P>
<P><FONT size=+0>不管多大数组,都保证没有问题。</FONT> </P>
<P><FONT size=+0>在<FONT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -