Jiangsheng的CSDN Digest (Dec 2005)

关于读XML字串的一个小问题(VC/MFC 基础类)


loadXML之后文档指针已经正常获得,但是文档的内容始终为空


MSXML4的文档对象的async属性默认是真,这时候Load是异步的,要等待对象触发事件再访问文档内容。也可以把文档的async属性设置成false切换到同步模式,这样Load调用之后就可以读DOM了。


.Net和MFC哪个更有前途,大家来讨论一下 (.NET技术 非技术区)


我是计算机专业大三的学生,我这学期已经学完了C++,教材是Essencial C++,但我自己把C++ Primer看完了,正在看Effective C++。我觉得自己基础比较扎实,因为以前C学得也可以。 我现在有点疑惑,不知道该学MFC还是学.Net。 因为听说明年64位操作系统就要出来了。所以学.Net很有前途,但是.Net的正宗语言是C#,不是C++,而我没学过C#,并且听人说C#在底层实现上比较差。 我想问一下,MFC和.Net哪个更有前途。


MFC是在API的基础上封装出来的一个类库,给C++程序员在Windows上快速开发用的。
.Net类库是在Windows非托管API的基础上封装出来的一个托管类库,给程序员在各种Windows平台上跨平台开发用的。

如果你是一个C++程序员,要进行非托管程序开发,那么你不能用.Net类库。如果要进行托管程序开发,你可以选择.Net类库,但是有时也需要在工程中加入对Windows非托管API和MFC的调用,例如 http://blog.joycode.com/jiangsheng/archive/2005/03/19/46065.aspx


我使用MSXML DOM创建XML文件,怎么在文件开头写上一些注释? (VC/MFC HTML/XML)


比如我想写上:


CreateProcessInstruction


VS2005的类设计器是怎么用的? (.NET技术 VC.NET)


我下了profession的rtm版,找来找去都没找到这个类设计器在哪里?
原有的代码能用类设计器吗,还是说要新建的?


Class Designer is not included in the current version of Visual C++ 2005.

C++ support will not be included in the Class Designer until a future release of Visual Studio, hopefully Visual Studio 2006.


关于继承CTreeCtrl类后,怎样能在初始化控件时同时加入ITEM(VC/MFC 界面)


我建一个类是从CTreeCtrl派生的。我想在自定义类里加入初始化控件的时候,自动加载几个ITEM到控件中。请问怎么做?比如说我的CMyTreeCtrl是继承CTreeCtrl的,然后我用CMyTreeCtrl定义一个控件,我想这控件在初始化时就有我自定义的默认的几项在里边。


把插入项目的代码放在PresubclassWindow里面。对话框是通过SubclassWindow来关联已经创建的子窗口和成员变量的,所以WM_CREATE等消息的处理函数不会总是被调用。


多线程环境下CLISTCTRL切换和刷新慢的问题如何解决(VC/MFC 界面 )


环境:WIN2000 SP4
VS2003。NET
本地运行了自己开发的一个网络服务器软件(没有问题的)
然后运行客户端,
客户端的主界面重载了ONEARSE( ),用来设置背景图片,本身是个对话框程序
原来使用的是LISTBOX监控窗口,刷新和程序切换,界面都没有问题,
改用CLISTCGTRL控件的REPORT模式做监控窗口后,出现问题
CLISTCTRL控件的刷新,在一直保持在TOP WINDOW位置的时候,正常
但是如果有其他程序占用TOP WINDOW位置,然后切换,如果已经连接到服务器(客户端本身也是多线程),那么经常在切换的时候出现CLISTCTRL控件要等一些时间才出现,其他部分却完全正常,
或者把鼠标移动到CLISTCTRL上,也能一点但刷新出来,
但是如果立即最小化,又最大化,通常能立即恢复
在WIN98下调试发现也有这问题,但是以前使用LISTBOX没有任何问题

界面上的CLISTCTRL采用定时刷新机制,间隔3-5秒
同时各线程在收到消息后也会发送立即刷新消息,然后主截面就立即刷新CLISTCTRL控件内容
为了防止闪动,在刷新函数中使用了SETREDRAW( )函数
请各位帮忙分析原因,


估计是SetRedraw的问题
用虚列表+CListCtrl::Update,更新的项目不可见的话没必要SetRedraw这么兴师动众

http://www.codeguru.com/Cpp/data/mfc_database/article.php/c1127


怎么将两个xml文件合并在一个xml文件中?(VC/MFC HTML/XML)


现在两个xml文件,文件的格式都是相似的,比如:

1<inforoot informationtime="2005-11-15 14:34:15">
2<iedate date="2005-11-08">
3<webname mbrid="0" number="2">update.cnnic.cn:80</webname>
4</iedate>
5</inforoot>

现在我想新建一个xml,然后将2个xml文件的内容都复制到这个新的xml文件中,变成这样:

 1<root>
 2<inforoot informationtime="2005-11-15 14:34:15">
 3<iedate date="2005-11-08">
 4<webname mbrid="0" number="2">update.cnnic.cn:80</webname>
 5</iedate>
 6</inforoot>
 7<inforoot informationtime="2005-11-16 14:34:15">
 8<iedate date="2005-11-09">
 9<webname mbrid="0" number="8">www.sina.com</webname>
10</iedate>
11</inforoot>
12</root>

请问具体该怎么做?
最好有例子或者代码提示,谢谢!


用XSLT来做转换。用document函数就可以导入XML文件。如果你需要导入同一个文件两次,你可能更喜欢用一个变量来保存导入的文件内容。参见http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/b24aafc2-bf1b-4702-bf1c-b7ae3597eb0c.asp


使用vc.net中使用API的问题 (.NET技术 VC.NET)


在程序中使用了GlobalAlloc,如果不在from1.h中加入#include

   1<windows.h>,则编译会出现:   
   2error C3861: “GlobalAlloc”: 即使使用参数相关的查找,也未找到标识符   
   3C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinBase.h(1624): error C2365: “GlobalAlloc” : 重定义;以前的定义是“原先未知的标识符”   
   4,如果在from1.h中加入#include <windows.h>,则编译会出现:   
   5error C2039: “GetObjectW” : 不是“System::Resources::ResourceManager”的成员   
   6这条语句是系统自动生成的,是我在加入一个com控件量系统自动加入   
   7如果解决,在vc.net中使用API的问题怎样使用sdk中的函数 
   8
   9* * *
  10
  11把GetObjectW undef掉,用的时候直接调ANSI或UNICODE版本。在包含windows.h之后   
  12#undef GetObject 
  13
  14* * *
  15
  16###  如何实现模拟ctrl+alt+delete三键? (Java J2SE / 基础类 ) 
  17
  18* * *
  19
  20java.awt.Robot robot=new java.awt.Robot();   
  21robot.keyPress(java.awt.event.KeyEvent.VK_CONTROL);   
  22robot.keyPress(java.awt.event.KeyEvent.VK_ALT);   
  23robot.keyPress(java.awt.event.KeyEvent.VK_DELETE);   
  24  
  25robot.keyRelease(java.awt.event.KeyEvent.VK_DELETE);   
  26robot.keyRelease(java.awt.event.KeyEvent.VK_ALT);   
  27robot.keyRelease(java.awt.event.KeyEvent.VK_CONTROL);   
  28这样写为什么不成功? 
  29
  30* * *
  31
  32It is handled differently by operation systems. For example, in windows 2000 and above, it is registered as a hotkey by winlogon.exe, and is handled in a window on the SAS desktop, not the application desktop. You need to open the SAS desktop, and broadcast a WM_HOTKEY message. However, I doubt you can do this in your java virtual machine.   
  33  
  34Reference:   
  35www.codeproject.com/system/alt_control_delete.asp 
  36
  37* * *
  38
  39###  基于对话框的数据库应用程序问题(VC/MFC 界面 ) 
  40
  41* * *
  42
  43我的程序用ado实现。现在想加入一个打印功能。查了一下资料,好象只有视图类有可以加打印。但我的程序是基于对话框的。比方说有个查询功能,结果显示在一个对话矿上,如何将它打印呢? 
  44
  45* * *
  46
  47http://msdn.microsoft.com/library/en-us/dncdev00/html/vc0300.asp 
  48
  49* * *
  50
  51###  如何获得rm,rmvb,avi,wmv,mp3...等文件的头信息? (专题开发/技术/项目 多媒体/流媒体开发 ) 
  52
  53* * *
  54
  55如题,能得到播放时间,视频大小。。。tag信息   
  56有通用的函数吗?   
  57请高手指教,最好有源码,delphi的最好 
  58
  59* * *
  60
  61没有通用的函数。   
  62你可以用Windows Media Format SDK里面的WMReader对象打开Windows Media Player支持的文件,之后读取相关信息。参见http://msdn.microsoft.com/library/en-us/wmform95/htm/aboutthewindowsmediaformatsdk.asp。Real的SDK中有rm、rmvb的格式规范(或者查Real提供给IETF的Internet Draft-RealMedia File Format)。mp3可以去查MPEG-1(ISO 11172)的标准文档。AVI文件中的信息可以用AVIFileInfo来获取。 
  63
  64* * *
  65
  66###  关于gdi+中Image类显示图片的问题 (VC/MFC 基础类 ) 
  67
  68* * *
  69
  70通常我们可以用Image(L"c:\\\1.jpg")来加载显示图片   
  71但如果图片文件包含在其它文件中,需要用CFile来读到缓冲区中,再加载,   
  72以下段代码为什么不能正常显示图片?谢谢!   
  73void CMy1Dlg::OnPaint()   
  74{   
  75if (IsIconic())   
  76{   
  77CPaintDC dc(this); // device context for painting   
  78  
  79SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);   
  80  
  81// Center icon in client rectangle   
  82int cxIcon = GetSystemMetrics(SM_CXICON);   
  83int cyIcon = GetSystemMetrics(SM_CYICON);   
  84CRect rect;   
  85GetClientRect(▭);   
  86int x = (rect.Width() - cxIcon + 1) / 2;   
  87int y = (rect.Height() - cyIcon + 1) / 2;   
  88  
  89// Draw the icon   
  90dc.DrawIcon(x, y, m_hIcon);   
  91}   
  92else   
  93{   
  94CDialog::OnPaint();   
  95}   
  96  
  97CFile file;   
  98file.Open("c:\\\1.jpg", CFile::modeRead);   
  99int bufSize = (int)file.GetLength();   
 100char *pBuf = new char[bufSize];   
 101file.Read(pBuf, bufSize);   
 102WCHAR *ws = new WCHAR[bufSize];   
 103MultiByteToWideChar(CP_ACP, 0,pBuf, bufSize,ws, bufSize);   
 104  
 105Graphics graphics(GetDC()-&gt;m_hDC);   
 106Image image(ws);   
 107graphics.DrawImage(ℑ,0, 0, 400, 300);   
 108} 
 109
 110* * *
 111
 112Use COleStreamFile instead of CFile, and use CreateMemoryStream to create a stream in memory. 
 113
 114COleStreamFile image_stream ;   
 115image_stream.CreateMemoryStream(NULL);   
 116img.Save(image_stream.GetStream(), Gdiplus::ImageFormatBMP); 
 117
 118Before reading from the memory stream returned by GetStream, call SeekToBegin. 
 119
 120* * *
 121
 122###  高分提问!如何对XML文件排序?100分送上,UP有分!(.NET技术 VB.NET ) 
 123
 124* * *
 125
 126两个问题:   
 127比如我有如下XML文档,读取时如何根据level和finishDate对每个shmItem排序?   
 128我尝试使用XPathDocument和XPathNavigator,但是如果xml文档中包含中文,初始化就很慢,请各位指教是怎么回事?   
 129  
 130<?xml version="1.0" encoding="gb2312"?>
 131<!--Powered By Ranran.-->
 132<shemes>
 133<shmitem>
 134<id>632698120068125000</id>
 135<title>文章一</title>
 136<level>0</level>
 137<finishdate>2005-12-10</finishdate>
 138<tips>中文内容   
 139</tips>
 140</shmitem>
 141<shmitem>
 142<id>632698120068125300</id>
 143<title>titles23</title>
 144<level>3</level>
 145<finishdate>2005-12-10</finishdate>
 146<tips>some content   
 147</tips>
 148</shmitem>
 149</shemes>
 150
 151* * *
 152
 153<?xml version="1.0" encoding=>指明文档使用的编码。写一个XSLT来转。用XSLT查询XML的时候排序。 
 154
 155* * *
 156
 157###  工程能够正常修改,使用,但是左边工作区里ClassView下一个对话框的类不见了, FileView里有相应的.cpp.h文件,怎么才能使得那个类重新显示(VC/MFC 基础类 ) 
 158
 159###  VC保存时,文件莫名其妙的没了... 
 160
 161* * *
 162
 163保存文件时,经常有这样的警告“有其他进程正在使用本文件”。一般情况下,忽略警告,第二次保存文件时就没有警告了。在某次保存时,出现警告,多按了几次CTRL+S,结果文件没了。不幸中的万幸,我用FinalData把那个丢失的文件找回来了,原文件里大半是乱码,工程目录下多了个MVCDD.TMP的文件,里面就是丢失的代码,完好。想弄清楚这到底是VC的问题还是VA的问题,或是其他问题。 
 164
 165* * *
 166
 167如果使用的是VC6,而且没有打SP6补丁,那么关闭Norton防火墙,或者升级VC。这个问题的详细资料参考微软知识库文章FIX: "Cannot Save File" Error Message in the Visual C++ IDE http://support.microsoft.com/kb/822856/ 
 168
 169* * *
 170
 171###  如何将asf格式的文件分成包发送到网络上?(专题开发/技术/项目 多媒体/流媒体开发 ) 
 172
 173* * *
 174
 175问题描述:结点A有一个asf格式的文件,结点B以流媒体的形式从结点A那里获得数据,然后调用media player进行播放。   
 176现在是,结点A如何将asf格式的文件以包的形式发送出去??? 
 177
 178* * *
 179
 180Topic in microsoft.public.windowsmedia.sdk   
 181how to use IWMWriterSink::OnDataUnit   
 182  
 183Q:   
 184I want to use IWMWriterSink::OnDataUnit() to get the   
 185compressed sample. I modify the WMVNetWrite sample   
 186application for test app, add the following:   
 187  
 188IWMWriterNetSink-&gt;QurryInterfaceIID_IWMWriterSink,   
 189m_pWriterSink)   
 190  
 191m_pWriterSink-&gt;AllocateDataUnit();   
 192m_pWriterSink-&gt;OnDataUnit();   
 193  
 194then use the INSSBuffer::GetBufferAndLength(),but the   
 195buffer content is null! I don't know how to use the   
 196interface: If the OnDataUnit is a callback function, it   
 197should be inherented by a class , otherwise , query   
 198interface to get it, but where and how to call the   
 199OnDataUnit function.   
 200I am waiting for your help   
 201regards   
 202billy   
 203  
 204A:   
 205If you want to override OnDataUnit() method of a network sinker. You need to   
 206do these steps:   
 207  
 208  
 2091\. Define a new class that inherits from IWMClientConnections2,   
 210IWMRegisterCallback, IWMWriterNetworkSinkobject, and IWMAddressAccess2   
 211interfaces.   
 212  
 213  
 214For example:   
 215  
 216class CMyWMNetSink : public IWMWriterNetworkSink,   
 217public IWMClientConnections2,   
 218public IWMRegisterCallback,   
 219public IWMAddressAccess2   
 220  
 2212\. Besides declare the constructor and the destructor of this class,   
 222you also need to declare all methods of the inherited interfaces.   
 223  
 224For example:   
 225virtual HRESULT STDMETHODCALLTYPE OnDataUnit(   
 226/* [in] */ INSSBuffer __RPC_FAR *pDataUnit);   
 2273\. Implement the constructor of this class   
 228a) Set the reference count to 1   
 229b) Create an internal IWMWriterNetworkSink object m_pNetworkSink by   
 230using WMCreateWriterNetworkSink() function.   
 2314\. Implement IUnknow interfaces.   
 232a) Implement AddRef() and Release() method just like you implement   
 233other COM interfaces.   
 234b) Imlplement QueryInterface() method. Return "this" pointer when   
 235querying the supported interfaces, such as IID_IWMWriterNetworkSink,   
 236IID_IWMWriterSink and etc.   
 2375\. Implement all other interfaces this class supports. Pass the calls   
 238to the internal IWMWriterNetworkSinker object. Add your own code before or   
 239after the calls.   
 240For example:   
 241HRESULT STDMETHODCALLTYPE CMyWMNetSink::OnDataUnit(   
 242/* [in] */ INSSBuffer __RPC_FAR *pDataUnit)   
 243{   
 244////////////////////////////////////////////   
 245// You can add you code here   
 246////////////////////////////////////////////   
 247IWMWriterSink * pWriterSink = NULL;   
 248HRESULT hr = S_OK;   
 249hr = m_pNetworkSink-&gt;QueryInterface( IID_IWMWriterSink, (void   
 250**)&amp;pWriterSink ); if ( FAILED( hr ) ) {return hr;}   
 251hr = pWriterSink-&gt;OnDataUnit( pDataUnit ); if ( FAILED( hr ) ) { pWriterSink-&gt;Release(); return hr;}   
 252pWriterSink-&gt;Release();   
 253  
 254/////////////////////////////////////////////////   
 255// You can also add you code here   
 256/////////////////////////////////////////////////   
 257return hr;   
 258}   
 259  
 2606\. Create an instance of this class in your program. Get the   
 261IWMWriterNetworkSink interface from this instance.   
 262For example:   
 263IWMWriterNetworkSink * pNetworkSink = NULL;   
 264CMyWMNetSink * pMySink = new CMyWMNetSink();   
 265if ( pMySink == NULL ) { return E_OUTOFMEMORY; }   
 266hr = pMySink-&gt;QueryInterface( IID_IWMWriterNetworkSink, (void   
 267**)&amp;pNetworkSink ); if ( FAILED( hr ) ) { return hr; }   
 268  
 2697\. Then you can use this IWMWriterNetworkSink interface in your   
 270program.   
 271\--   
 272Thanks!   
 273Gangjiang Li   
 274Microsoft Corp.   
 275Windows Media Format SDK 
 276
 277* * *
 278
 279###  如何用DirectShow实现将一批BMP图片和指定的MP3合成一个MPEG或AVI文件(VC/MFC 图形处理/算法 ) 
 280
 281* * *
 282
 283去看DirectShow示例里面那个desktop push的sample filter CPushSourceDesktop.   
 284(SDK root)\Samples\C++\DirectShow\Filters\PushSource,在网上找一找曾经开源的软件CamStudio的源代码。 
 285
 286* * *
 287
 288###  一种自定义的图形格式如何在windows的文件管理器里缩略图显示出来(VC/MFC ATL/ActiveX/COM ) 
 289
 290* * *
 291
 292就象photoshop和CorelDraw的文件一样, 这种格式按理说Windows是不认识的, 但我们在用缩略图方式查看文件时却可以显示这样的图片, 为什么?如果我们自己有一种格式需要写出自己的图形回显程序才能显示的, 如何通知WINDOWS呢? 
 293
 294* * *
 295
 296http://www.codeproject.com/shell/thumbextract.asp 
 297
 298* * *
 299
 300###  请问创建线程是用afxBeginThreaD还是应该用CREATETHREAD? (VC/MFC 进程/线程/DLL ) 
 301
 302* * *
 303
 304为什么我用调试工具调试时,总是提醒说不应该用AFXBEGINTHREAD而应该用CREATETHREAD? 
 305
 306* * *
 307
 308both C runtime and MFC need some special initialization to function properly, so if you need MFC support, use AfxBeginThread. otherwise use _beginthreadex. DO NOT use CreateThread, since you are almost always using C runtime. 
 309
 310* * *
 311
 312请问这个东西用脚本能实现么? (其他开发语言 脚本语言(Perl ,Python)) 
 313
 314* * *
 315
 316我有一个链接   
 317http://mtgroup.ict.ac.cn/~zhp/ICTCLAS.htm   
 318  
 319这个链接里面有一个输入框,看不到的朋友我把代码也贴上来。   
 320  
 321<body alink="#FF9900" background="ICTCLAS/images/blegtext.gif" bgcolor="#CCCCCC" link="#993300" text="#000000" vlink="#0000FF">
 322<form action="/ictclas-cgi/ictclas_c" method="post">
 323<p>输入句子段落:   
 324<p><textarea cols="101" name="address" rows="6">张华平于1978年3月出生于江西省波阳县。</textarea>
 325<p><input name="submit1" type="submit" value="切分标注"/> <input type="reset" value="重置"/>
 326</p></p></p></form>
 327</body>   
 328  
 329可以看到这里面有关textarea ,还有一个叫做“切分标注的”button。我要做的是模拟在textarea里面输入数据,然后点击“input”button,然后接收到服务器端传回来的结果。   
 330不知道这个事情我能不能用什么语言来做。什么语言都可以。 
 331
 332* * *
 333
 334用Win32::OLE创建一个Internet.Application就可以   
 335#launch an Internet Explorer window and search for ACC map   
 336#for more information about automating Internet Explorer   
 337#see my article http://www.codeproject.com/shell/AutomateShellWindow.asp 
 338
 339use Win32::OLE qw(EVENTS);   
 340my $URL = "http://maps.google.com/";   
 341my $IE = Win32::OLE-&gt;new("InternetExplorer.Application")   
 342|| die "Could not start Internet Explorer.Application\n";   
 343Win32::OLE-&gt;WithEvents($IE,\&amp;Event,"DWebBrowserEvents2");   
 344$IE-&gt;{visible} = 1; #invisible by default   
 345$IE-&gt;Navigate($URL);   
 346Win32::OLE-&gt;MessageLoop();   
 347sub Event {   
 348my ($Obj,$Event,@Args) = @_;   
 349print "Here is the Event: $Event\n";   
 350if ($Event eq "DocumentComplete") {   
 351my $IEObject = shift @Args;   
 352print "Sender: $IEObject\n";   
 353print "URL: " . $IEObject-&gt;Document-&gt;URL . "\n";   
 354if($IEObject-&gt;Document-&gt;URL eq $URL)   
 355{   
 356SetEditBox($IEObject-&gt;Document,"q","1212 Rio Grande St., Austin, TX 78701");   
 357ClickButton($IEObject-&gt;Document,"submitq");   
 358}   
 359}   
 360if ($Event eq "OnQuit") {   
 361print "User Closed Internet Explorer, quiting";   
 362#Win32::OLE-&gt;WithEvents($IE,\&amp;Event,"DWebBrowserEvents2");   
 363undef $IE;   
 364Win32::OLE-&gt;QuitMessageLoop();   
 365exit(0);   
 366}   
 367}   
 368sub SetEditBox {   
 369my ($IEDocument,$name, $value) = @_;   
 370my $forms = $IEDocument-&gt;forms;   
 371for (my $i = 0; $i &lt; $forms-&gt;length; $i++) {   
 372my $form = $forms-&gt;item($i);   
 373if (defined($form-&gt;elements($name))) {   
 374$form-&gt;elements($name)-&gt;{value} = $value;   
 375}   
 376return;   
 377}   
 378}   
 379sub ClickButton{   
 380my ($IEDocument,$name) = @_;   
 381my $forms = $IEDocument-&gt;forms;   
 382for (my $i = 0; $i &lt; $forms-&gt;length; $i++) {   
 383my $form = $forms-&gt;item($i);   
 384if (defined($form-&gt;elements($name))) {   
 385$form-&gt;elements($name)-&gt;click;   
 386}   
 387return;   
 388}   
 389} 
 390
 391* * *
 392
 393###  VC.NET无法启动调试:计算机调试管理服务器被禁用?怎么办?? (.NET技术 VC.NET ) 
 394
 395* * *
 396
 397有些网络管理员为了安全起见,禁止一般用户调试程序。你可以使用WinDbg( Debug Tools For Windows)来调试看看 
 398
 399* * *
 400
 401###  Visual C++ 2005 Express 能否编译出不依赖.net平台的程序 (C/C++ 工具平台和程序库 ) 
 402
 403* * *
 404
 405Download the Windows Platform SDK and create a windows or console application. 
 406
 407* * *
 408
 409###  请教一个C++.NET中定义消息映射函数的问题 (.NET技术 VC.NET) 
 410
 411* * *
 412
 413用MSVisual C++.NET新建一个MFC Application工程.   
 4141、在框架程序的头文件(比如MainFrm.h)中有这样的定义:   
 415#define WM_MYPNP (WM_USER + 100)   
 416  
 417//定义消息映射函数:   
 418afx_msg void OnPtoP();   
 419  
 4202、然后在程序文件(比如MainFrm.cpp)中这样定义:   
 421BEGIN_MESSAGE_MAP(CMainFrame,CFrameWnd)   
 422ON_MESSAGE(WM_MYPNP ,OnPtoP)   
 423END_MESSAGE_MAP()   
 424  
 425void CMainFrame:: OnPtoP()   
 426{   
 427}   
 428  
 429  
 430在C++6.0是可以的,但在C++.NET(2003)中不行。   
 431编译通不过。   
 432erre:C2440 'static_cast' connot convert from 'void (__thiscall CMainFrame::*)(void)' to ''LRESULT(__thiscall CWnd::*)(PARAM,LPARAM) 
 433
 434* * *
 435
 436afx_msg LRESULT OnPtoP(PARAM,LPARAM);   
 437Visual C++ 6.0 does not check the function signature, and VC2003 uses static_cast to check it. 
 438
 439* * *
 440
 441###  怎样使DLL中的窗体或对话框PreTranslateMessage能有用呢?(VC/MFC 进程/线程/DLL) 
 442
 443* * *
 444
 445一般情况下DLL 的窗体或对话框,是不能响应这个PreTranslateMessage函数的,   
 446而被主程序窗口响应了。   
 447怎么样使这个函数在DLL的窗体中也能响应呢?有效呢?   
 448我主要是想在DLL的窗体中用工具提示类?   
 449m_ToolTipCtrl.RelayEvent(pMsg);   
 450return CDialog::PreTranslateMessage(pMsg); 
 451
 452* * *
 453
 454PreTranslateMessage is called by a MFC message pump. If the message pump is not a MFC one, your PreTranslateMessage won't be called. Export a PreTranslateMessage function from your DLL and call it in the message pump. 
 455
 456BOOL CXXXDlg::PreTranslateMessage(MSG* pMsg)   
 457{   
 458// TODO: Add your specialized code here and/or call the base class   
 459if(m_pDLLExportedPreTranslateMessage(pMsg))   
 460return true;   
 461return CDialog::PreTranslateMessage(pMsg);   
 462}   
 463  
 464Reference   
 465http://support.microsoft.com/kb/q140850/ 
 466
 467* * *
 468
 469###  Dhtml的应用问题!(Delphi 网络通信/分布式开发) 
 470
 471* * *
 472
 473我的Dhtml总是提示,不支持此接口.!!!   
 474MailDhtml.DocumentHTML:='<html><body></body></html>';   
 475self.MailDhtml.DocumentHTML :='HtmlBuffer.htm' 
 476
 477* * *
 478
 479Re: DHTML CONTROL MICROSOFT UPDATE DISASTER   
 480by Carlos Rocha <carlosclearthisrocha@[email protected]=""> Feb 28, 2005 at 10:40 PM 
 481
 482  
 483Dick, 
 484
 485This was post in a Delphi's newsgroup, 
 486
 487"With all the stuff surrounding Hotfix KB891781 breaking applications that use DHTMLED.OCX, it might be not entirely Microsoft's fault after all. After some investigation, this is what I found: 
 488
 4891\. DHTMLEDLib_TLB.pas declares: 
 490
 491TDHTMLEdit = class(TOleControl) 
 492
 4932\. OleCtrls.pas declares: 
 494
 495TOleControl = class(TWinControl, IUnknown, IOleClientSite,   
 496IOleControlSite, IOleInPlaceSite, IOleInPlaceFrame, IDispatch,   
 497IPropertyNotifySink, ISimpleFrameSite, IServiceProvider) 
 498
 4993\. OleCtrls.pas implements a method of IOleClientSite: 
 500
 501function TOleControl.GetContainer(out container: IOleContainer): HResult;   
 502begin   
 503Result := E_NOINTERFACE;   
 504end; 
 505
 506Now, if your application uses TDHTMLEdit, you can trace the call to its DOM member in debug mode in Delphi (I use D2005). You will see that when you try to access DOM, the new version of DHTMLED.OCX makes a call back to your application requesting IOleContainer of your TDHTMLEdit component. The trace arrives at the GetContainer line in OleCtrls.pas, and that is exactly where "No such interface" comes from. Your own application returns it to DHTMLED.OCX, which in turn denies its access to the DOM object. 
 507
 508As was noted somewhere, this does not happen to VB applications. VB implements IOleClientSite.GetContainer, Borland VCL (both Delphi and C Builder) doesn't, and that is the difference and the cause of this problem. 
 509
 510I'm not a big specialist in this stuff. Can somebody suggest how exactly to implement GetContainer? And where - modify OleCtrls.pas, DHTMLEDLib_TLB.pas, or maybe create my own class, descendant of TDHTMLEdit?" 
 511
 512回复人: ly_liuyang(Liu Yang LYSoft http://lysoft.7u7.net ) 
 513
 514首先,保存Delphi系统下的OleCtrls.Pas到你的程序所在目录   
 515然后修改部分代码,增加IOleContainer接口   
 516  
 517TOleControl = class(TWinControl, IUnknown, IOleClientSite,   
 518IOleControlSite, IOleInPlaceSite, IOleInPlaceFrame, IDispatch,   
 519IPropertyNotifySink, ISimpleFrameSite, IOleContainer)   
 520  
 521//IOleContainer   
 522function EnumObjects(grfFlags: Longint; out Enum: IEnumUnknown):   
 523HResult; stdcall;   
 524function LockContainer(fLock: BOOL): HResult; stdcall;   
 525function ParseDisplayName(const bc: IBindCtx; pszDisplayName:   
 526POleStr; out chEaten: Longint; out mkOut: IMoniker): HResult; stdcall;   
 527  
 528function TOleControl.EnumObjects(grfFlags: Integer;   
 529out Enum: IEnumUnknown): HResult;   
 530begin   
 531Result := E_NOTIMPL;   
 532end;   
 533  
 534function TOleControl.LockContainer(fLock: BOOL): HResult;   
 535begin   
 536Result := E_NOTIMPL;   
 537end;   
 538  
 539function TOleControl.ParseDisplayName(const bc: IBindCtx;   
 540pszDisplayName: POleStr; out chEaten: Integer;   
 541out mkOut: IMoniker): HResult;   
 542begin   
 543Result := E_NOTIMPL;   
 544end;   
 545  
 546并修改   
 547function TOleControl.GetContainer(out container: IOleContainer):   
 548HResult;   
 549begin   
 550container:= Self;   
 551Result:= S_OK;   
 552end;   
 553
 554
 555* * *
 556
 557###  CArray使用中的问题(VC/MFC 界面 ) 
 558
 559* * *
 560
 561我在View类中定义了CArray<int,int>m_plist;编译出现8个错误,主要有:   
 562syntax error : missing ';' before '&lt;'   
 563error C2501: 'CArray' : missing storage-class or type specifiers   
 564error C2059: syntax error : '&lt;'   
 565这是什么错误啊,   
 5662。我理解CArray中第一个int就是这个数组中的存储的数据类型,那么第二个int是表示什么意思呢?看MSDN也没明白。 
 567
 568我定义了CArray<cline,cline>m_plist;   
 569CLine data;   
 570  
 571m_plist.add(data);   
 572怎么会出现这样一个奇怪的错误   
 573cannot convert parameter 1 from 'class CLine' to 'class CLine' 
 574
 575* * *
 576
 577CArray<class arg_type="" class="" type,="">   
 578TYPE   
 579这个模板参数指明了存储在数组中的对象的类型。TYPE这个参数是CArray的返回值。   
 580ARG_TYPE   
 581这个模板参数指明了用来访问数组中的对象的参数的类型,通常是TYPE的参考。ARG_TYPE是用来传递给CArray的参数的类型。 
 582
 583you need a copy constructor to pass a class by value.   
 584you can also use CArray<cline,cline&> to pass a class by reference. 
 585
 586* * *
 587
 588###  如何创建一个没有地址栏的IE窗口 (VC/MFC 网络编程) 
 589
 590* * *
 591
 592不希望让用户看到打开网页的地址,所以想创建一个没有地址栏的IE窗口,但不影响用户做其他操作时,仍能打开一个有地址栏的IE窗口。 
 593
 594* * *
 595
 596http://www.codeproject.com/shell/AutomateShellWindow.asp   
 597  
 598IWebBrowser2::put_AddressBar   
 599http://msdn.microsoft.com/workshop/browser/webbrowser/reference/ifaces/iwebbrowser2/addressbar.asp 
 600
 601* * *
 602
 603###    
 604为什么WebBrowser下载完成一个页触发两次onDocumentComplete事件 (Delphi VCL组件开发及应用) 
 605
 606* * *
 607
 608为什么WebBrowser下载完成一个页触发两次onDocumentComplete、onNavigateComplete、onNavigateComplete事件。   
 609如果在这些事件下作处理数据容易出错,请教一下大家不如何解决。 
 610
 611* * *
 612
 613因为你浏览的页面可能有框架,每个单独的框架都可能会触发DocumentComplete事件。   
 614框架集页面会最后触发DocumentComplete事件。   
 615发送事件的对象可以通过DocumentComplete事件的第一个参数访问 
 616
 617procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;   
 618const pDisp: IDispatch; var URL: OleVariant);   
 619var   
 620CurWebrowser: IWebBrowser;   
 621TopWebBrowser: IWebBrowser;   
 622Document: OleVariant;   
 623WindowName: string;   
 624begin   
 625CurWebrowser := pDisp as IWebBrowser;   
 626TopWebBrowser := (Sender as TWebBrowser).DefaultInterface;   
 627if CurWebrowser = TopWebBrowser then   
 628ShowMessage('Complete document was loaded')   
 629else   
 630begin   
 631Document := CurWebrowser.Document;   
 632WindowName := Document.ParentWindow.Name;   
 633ShowMessage(Format('Frame "%s" was loaded', [WindowName]));   
 634end;   
 635end; 
 636
 637* * *
 638
 639###  怎么获得当前登入到2000,xp帐户的类型??? (VC/MFC 基础类) 
 640
 641* * *
 642
 643比如,判断当前是一个管理员帐户,或是一个受限帐户? 
 644
 645* * *
 646
 647Use IsUserAnAdmin   
 648However, if you need to check a limited user account, You need to either use CheckTokenMembership, or construct a security descriptor and perform an access check.   
 649  
 650You may need to use GetTokenInformation if you also target NT4.0   
 651// whoami.cpp   
 652// cl whoami.cpp /c1 /c   
 653// link whoami.obj /nodefaultlib msvcrt.lib advapi32.lib kernel32.lib /align:16   
 654//   
 655//   
 656//   
 657  
 658#pragma comment(lib,"Advapi32.lib")   
 659  
 660#include <stdio.h>   
 661#include <stdlib.h>   
 662#include <string.h>   
 663#include <windows.h>   
 664  
 665#define UULEN 256   
 666int main(int argc,char *argv[])   
 667{   
 668//OpenProcess();   
 669HANDLE hp , htoken;   
 670char buff[2560];   
 671unsigned long size = 2560;   
 672  
 673TOKEN_USER *tuser;   
 674PTOKEN_GROUPS tgroup;   
 675PTOKEN_OWNER towner;   
 676PTOKEN_SOURCE tsource;   
 677PSID sid;   
 678char user[UULEN], domain[UULEN];   
 679SID_NAME_USE snu;   
 680  
 681hp = htoken = INVALID_HANDLE_VALUE;   
 682hp = GetCurrentProcess();   
 683  
 684if(!OpenProcessToken(hp, TOKEN_QUERY | TOKEN_QUERY_SOURCE , &amp;htoken))   
 685{   
 686printf("OpenProcessToken error : %u\r\n", GetLastError());   
 687goto exit_main;   
 688}   
 689if(!GetTokenInformation(htoken, TokenUser, (void*)buff, size, &amp;size))   
 690{   
 691printf("GetTokenInformation error : %u\r\n", GetLastError());   
 692goto exit_main;   
 693}   
 694tuser = (TOKEN_USER*)buff;   
 695sid = tuser-&gt;User.Sid;   
 696size = UULEN;   
 697if(!LookupAccountSid(NULL, sid, user, &amp;size, domain, &amp;size, &amp;snu))   
 698{   
 699printf("LookupAccountSid error : %u\r\n", GetLastError());   
 700goto exit_main;   
 701}   
 702// printf("you are '%s\\\%s'\r\n", domain, user);   
 703printf( "Domain : %s\nUser : %s\n", domain, user);   
 704  
 705size = UULEN *10;   
 706if(!GetTokenInformation(htoken, TokenGroups , (void*)buff, size, &amp;size))   
 707{   
 708printf("GetTokenInformation error : %u\r\n", GetLastError());   
 709goto exit_main;   
 710}   
 711tgroup = (PTOKEN_GROUPS)buff;   
 712int len ;   
 713len = tgroup-&gt;GroupCount;   
 714printf( "Group :\n");   
 715int i;   
 716for( i = 0; i&lt; len ; i++)   
 717{   
 718sid = tgroup-&gt;Groups[i].Sid ;   
 719size = UULEN;   
 720if(!LookupAccountSid(NULL, sid, user, &amp;size, domain, &amp;size, &amp;snu))   
 721{   
 722//printf("LookupAccountSid error : %u\r\n", GetLastError());   
 723break;   
 724}   
 725printf("\t[%d] %s\n",i+1, user );   
 726}   
 727  
 728size = 2560;   
 729  
 730if(!GetTokenInformation(htoken,TokenOwner, (void*)buff, size, &amp;size))   
 731{   
 732printf("GetTokenInformation error : %u\r\n", GetLastError());   
 733goto exit_main;   
 734}   
 735  
 736towner = (PTOKEN_OWNER)buff;   
 737sid = towner-&gt;Owner;   
 738size = UULEN;   
 739  
 740if(!LookupAccountSid(NULL, sid, user, &amp;size, domain, &amp;size, &amp;snu))   
 741{   
 742printf("LookupAccountSid error : %u\r\n", GetLastError());   
 743goto exit_main;   
 744}   
 745  
 746printf( "Owner : %s\n", user );   
 747  
 748size = 2560;   
 749  
 750if(!GetTokenInformation(htoken,TokenSource, (void*)buff, size, &amp;size))   
 751{   
 752printf("GetTokenInformation error : %u\r\n", GetLastError());   
 753goto exit_main;   
 754}   
 755tsource = (PTOKEN_SOURCE ) buff;   
 756tuser = (TOKEN_USER*)buff;   
 757sid = tuser-&gt;User.Sid;   
 758size = UULEN;   
 759  
 760printf( "Source : %.8s\n", tsource-&gt;SourceName );   
 761  
 762  
 763exit_main:   
 764if(htoken != INVALID_HANDLE_VALUE)CloseHandle(htoken);   
 765if(hp != INVALID_HANDLE_VALUE)CloseHandle(hp);   
 766return 0;   
 767} 
 768
 769* * *
 770
 771###  MFC基于Dialog如何得到屏幕右下角坐标(可用位置) (VC/MFC 界面 ) 
 772
 773* * *
 774
 775如何得到屏幕右下角坐标(可用位置)?   
 776int cx = GetSystemMetrics( SM_CXSCREEN );   
 777int cy = GetSystemMetrics( SM_CYSCREEN );   
 778  
 779这样可以得到分辨率。但是我需要知道是不是下边有一个任务栏会占据一定高度。又或许任务栏在右边。总之,需要知道可用位置的最右下位置 
 780
 781* * *
 782
 783SystemParametersInfo   
 784  
 785This function, with the flag SPI_GETWORKAREA, retrieves the size of the work   
 786area on the primary display monitor. The work area is the portion of the   
 787screen not obscured by the system taskbar or by application desktop   
 788toolbars.   
 789The parameter rc is a RECT structure that receives the coordinates of the   
 790work   
 791area, expressed in virtual screen coordinates 
 792
 793* * *
 794
 795###  创建WORD.DOCUMENT组件的时候,用CLSCTX_INPROC_HANDLER、CLSCTX_LOCAL_SERVER有什么区别 (VC/MFC ATL/ActiveX/COM ) 
 796
 797* * *
 798
 799CLSCTX_INPROC_HANDLER,方式创建的时候,怎么获取MSWORD中的Applicaiton,Document接口。我试了几次好像都不行。   
 800用CLSCTX_LOCAL_SERVER方式创建COM的时候,可以轻松的获取上面提到的接口,单无法做内嵌到其他窗口的功能。 
 801
 802* * *
 803
 804Word是进程外组件,无法使用CLSCTX_INPROC_HANDLER来创建。你可以集成Active Document来嵌入Word这样的Active Document Server。   
 805You're doing some things te hard way. Since you've used #import,   
 806there were several helpful things generated for you that you aren't   
 807using. Most notably is all the smart pointers derived from _com_ptr_t!   
 808You also need to learn how to work with VARIANTs. The _variant_t class   
 809makes it easy.   
 810try   
 811{   
 812Word::_ApplicationPtr pWordApp ;   
 813HRESULT hr = pWordApp.CreateInstance(   
 814__uuidof( Word::Application ) ) ;   
 815if ( hr == S_OK )   
 816{   
 817Word::DocumentsPtr pDocs = theApp.m_pWordApp-&gt;Documents ;   
 818_variant_t vtFilename( _T("C:\\\MyFile.doc") ) ;   
 819Word::_DocumentPtr pDoc = pDocs-&gt;Open( &amp;vtFilename ) ;   
 820// etc.   
 821}   
 822}   
 823catch ( _com_error &amp; ce )   
 824{   
 825CString strMsg ;   
 826strMsg.Format( _T("%s\n%S"), ce.ErrorMessage(),   
 827(LPCWSTR)ce.Description() ) ;   
 828AfxMessageBox( strMsg, MB_OK | MB_ICONSTOP ) ;   
 829}   
 830To my knowledge, Microsoft assumes that anyone smart enough to choose C++ is smart enough not to need documentation. :) They provide all documentation for the Office Automation interface directed to VB users.   
 831  
 832  
 833If you've got the October 2001 MSDN Library, and are using Word 2000,   
 834like me, the path for the documentation is as follows:   
 835Office Developer Documentation   
 836\- Office 2000 Documentation   
 837\- Microsoft Office 2000 Language Reference   
 838\- Microsoft Word 2000 Reference   
 839\- Microsoft Word Visual Basic Reference   
 840  
 841For other versions of MSDN or Word, this may obviously vary.   
 842It's actually not too hard to translate. Look at the VB help, then look   
 843at the corresponding object interface in your TLH file. You should see   
 844the analogies. 
 845
 846* * *
 847
 848###  怎样用VB连接局域网中电脑上的数据库(access,sql,dbf) (VB 数据库(包含打印,安装,报表) ) 
 849
 850* * *
 851
 852你应该使用C/S架构的数据库服务器,例如SQL Server, Oracle或者DB2。基于文件的数据库访问很容易造成数据库损坏。参考http://support.microsoft.com/kb/300216/ 
 853
 854* * *
 855
 856###  VC++.net中如何使用正则表达式?(.NET技术 VC.NET ) 
 857
 858* * *
 859
 860.Net类库里面System.Text.RegularExpression的用法和其他语言大同小异   
 861  
 862VBS引擎那个导入就可以用,不管是VC6还是VC7用法都是一样的。但是要注意一下版本问题,导入随IE3发布的RegExp 1.0组件的类型库兼容性最好,但是默认导入的是最新版本的类型库。导入非默认类型库的方法可以参考http://msdn.microsoft.com/library/en-us/vclang/html/_predir_The_.23.import_Directive.asp,版本区别可以参考http://msdn.microsoft.com/library/en-us/script56/html/vtoriVersionInformation.asp   
 863  
 864一些其他的类库也支持正则表达式,例如   
 865http://www.boost.org 或者 http://ourworld.compuserve.com/homepages/John_Maddock/regexpp.htm 
 866
 867* * *
 868
 869###  最新的Platform SDK for Windows Server 2003 SP1 如何支持VC6.0?(VC/MFC 界面) 
 870
 871* * *
 872
 873好不容易把Platform SDK for Windows Server 2003 SP1下载并安装好了,却发现文档里面写这个版本的SDK不支持VC 6.0,如果使用这个库在VC6.0里面编译的话将会导致连接错误。   
 874请问大家,有没有办法能够使这个版本的SDK能够在VC6.0里面用使用 
 875
 876* * *
 877
 878可以,安装Visual C++ Toolkit 2003就可以升级编译器。   
 879但是,Visual C++ Toolkit 2003编译出来的目标文件和VC6的其他模块不兼容,比如调试器。推荐的方法还是使用免费的VC 2005 Express。 
 880
 881* * *
 882
 883###  安装VC时出现的问题(VC/MFC 非技术类 ) 
 884
 885* * *
 886
 887在复制完所有文件后.   
 888弹出一对话框,对话框内容为:   
 889Setup was unable to create a DCOM user account in   
 890order to register C:\program files\visual studio\Common\tools\Vs-Ent98\vanalyzr   
 891\valec.exe 按确定按钮后,显示安装不完全成功 
 892
 893* * *
 894
 895BUG: "Setup Was Unable to Create a DCOM User Account" Error Message in Visual Studio 6.0   
 896http://support.microsoft.com/?scid=kb;en-us;257413&amp;spid=3042&amp;sid=10 
 897
 898* * *
 899
 900###  关于 Extension Dll (VC/MFC 进程/线程/DLL) 
 901
 902* * *
 903
 904在一个扩展Dll中导出一个CWnd的派生类JScollWnd,我还能不能在另一个扩展Dll中从JScollWnd派生出(不是导出)类CSGrid?如果能,那么JScollWnd前面的AFX_EXT_CLASS在第二个扩展Dll中将被解释成什么呢?如果不能,还有其他的办法吗? 
 905
 906* * *
 907
 908http://msdn.microsoft.com/library/en-us/vccore/html/_core_mutual_imports.asp 
 909
 910* * *
 911
 912###  在发布用VC++.net 2003开发的用于Web页面的OCX控件时如何去掉对.net环境的依赖(.NET技术 VC.NET) 
 913
 914* * *
 915
 916现在依赖于msvcr71.dll,但很客户端都没有这个文件,OCX控件自动下载后,无法自动注册 
 917
 918* * *
 919
 920msvcr71.dll不是.Net的一部分。再发布的步骤可以参考http://support.microsoft.com/default.aspx?scid=kb;en-us;326922、 http://msdn.microsoft.com/workshop/delivery/download/overview/inf.asp 
 921
 922参见 
 923
 924Redistributing MFC, ATL, and OLE DB Templates Applications 
 925
 926http://msdn.microsoft.com/library/en-us/vccore/html/vcoriRedistributingMFCATLOLEDBTemplatesApplications.asp 
 927
 928Redistributing Microsoft Visual C++ 6.0 Applications 
 929
 930http://www.msdn.microsoft.com/library/en-us/dnvc60/html/redistribvc6.asp   
 931
 932
 933* * *
 934
 935###  C++/CLI 结构体数组使用(.NET技术 VC.NET) 
 936
 937* * *
 938
 939想要使用结构体数组,例如:   
 940  
 941value struct pix   
 942{   
 943int x;   
 944int y;   
 945};   
 946  
 947然后建立一个该结构体的数组:   
 948array<pix^>^ points=gcnew array<pix^>(10);   
 949  
 950现在想要通过一个循环给结构体初始化:   
 951for(int i=0;i&lt;10;i++)   
 952p[i]-&gt;x=5; ///这里为何不对呢?应该怎么做才正确?错误提示为:Object reference not   
 953set to an instance of an object. 
 954
 955* * *
 956
 957you need to allocate the elements on the managed heap first.   
 958see http://msdn2.microsoft.com/en-us/library/dtbydz1t.aspx 
 959
 960* * *
 961
 962###  怎样用tab键把焦点移到子对话框上?(VC/MFC 基础类 ) 
 963
 964* * *
 965
 966我建了一个对话框程序,在主对话框上加入了一个子对话框,但是发现tab键只能在主对话框的其他控件之间切换,怎样才能使焦点移到子对话框上啊? 
 967
 968* * *
 969
 970Use DS_CONTROL as a window style for the child dialog   
 971  
 972If the you can not tab out from the child dialog, try overriding PreTranslateMessage in your child dialogs and call the parent 's PreTranslateMessage first, return TRUE if it does. Otherwise, return through CDialog::PreTranslateMess 
 973
 974* * *
 975
 976MIDL中如何定义返回BSTR数组的方法(VC/MFC ATL/ActiveX/COM) 
 977
 978* * *
 979
 980为什么这样定义只能返回第一个串,第二个开始都是无效地址。   
 981HRESLUT GetStrings([out]short*psize,[out,size_is(,*psize)]BSTR**ppstrs);   
 982  
 983说明一下我把该COM方法代码改写为本地客户端内的函数后,可以正确调用。 
 984
 985* * *
 986
 987You can not pass a array in a short variable. see How To Pass Arrays Between Visual Basic and C   
 988http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q207931 
 989
 990* * *
 991
 992###  AfxBeginThread启动工作线程出现的问题(VC/MFC 进程/线程/DLL ) 
 993
 994* * *
 995
 996VC.net 2003提示说:error C2665: “AfxBeginThread” : 2 个重载中没有一个可以转换参数 1(从“UINT (LPVOID)”类型) d:\softwares\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\afxwin.h(4105): 可能是“CWinThread *AfxBeginThread(AFX_THREADPROC,LPVOID,int,UINT,DWORD,LPSECURITY_ATTRIBUTES)”   
 997d:\softwares\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\afxwin.h(4108): 或 “CWinThread *AfxBeginThread(CRuntimeClass *,int,UINT,DWORD,LPSECURITY_ATTRIBUTES)”   
 998试图匹配参数列表“(overloaded-function, CClientSocket *, int)”时   
 999  
1000  
1001我是这么用的:AfxBeginThread(ClientThread,pClientSocket,THREAD_PRIORITY_NORMAL);   
1002其中ClientThread函数原型为UINT ClientThread(LPVOID pParam),pClientSocket为一个指向CSocket类的指针。 
1003
1004* * *
1005
1006不要传递CSocket*,和大多数MFC类一样,这个MFC类不是线程安全的   
1007把socket句柄强制转换成LPARAM类型再传递过去。 
1008
1009void CListeningSocket::OnAccept(int nErrorCode)   
1010{   
1011CSocket::OnAccept(nErrorCode);   
1012CSocket socket;   
1013if (Accept(socket))   
1014{   
1015SOCKET hSocket= socket.Detach();   
1016AfxBeginThread(AcceptConnection, (LPVOID)hSocket);   
1017}   
1018}   
1019  
1020  
1021UINT AcceptConnection( LPVOID pParam )   
1022{   
1023  
1024SOCKET hSocket = (SOCKET)(pParam);   
1025CSocket Socket;   
1026Socket.Attach( hSocket ); // gives resource exception   
1027.   
1028.   
1029.   
1030.   
1031} 
1032
1033* * *
1034
1035###  如何用javascript调用VC++的函数(VC/MFC 基础类) 
1036
1037* * *
1038
1039有一个网页作为资源放在VC++资源里 用HtmlView可以显示 但是如何使网页里的javascript与C++通信呢?也就是javascript调用C++的函数 注意这个网页是作为资源存在的 而不是写在C++里的 
1040
1041* * *
1042
1043http://blog.csdn.net/jiangsheng/archive/2003/11/09/3795.aspx   
1044http://blog.csdn.net/jiangsheng/archive/2004/06/27/27807.aspx   
1045http://blog.csdn.net/jiangsheng/archive/2004/07/06/35567.aspx   
1046http://blog.csdn.net/jiangsheng/archive/2004/11/07/170742.aspx 
1047
1048* * *
1049
1050###  动态创建的控件在自己的事件中销毁自己安全吗(Delphi VCL组件开发及应用) 
1051
1052* * *
1053
1054我写了一个不可视控件,内部有个线程(用的是BeginThread,未用TThread),   
1055线程函数的参数就是“Self”:   
1056  
1057BeginThread(nil,0,@_WkrThreadProc,Pointer(Self),CREATE_SUSPENDED,dwThreadId);   
1058  
1059另外控件有个私有的用AllocateHWnd()建立的隐藏窗口。   
1060  
1061  
1062使用者调用控件的Start()方法后,Start()内启动线程,线程在工作中,不断用   
1063PostMessage投递自定义的消息到隐藏窗口(线程退出前的最后一个消息是自定义   
1064的WM_THREAD_END),隐藏窗口的窗口过程处理消息并调用事件点火代码触发事件,   
1065WM_THREAD_END消息仅仅就是触发控件的OnEnd(Sender: TObject)事件,没有其他代码。   
1066  
1067控件的destructor中先等待线程的结束(如果线程还在运行),清理一些成员,   
1068然后DeallocateHWnd隐藏窗口,   
1069  
1070\-----------------------------   
1071我的问题是:如果使用者动态创建控件,并在在控件的OnEnd事件里把控件自身销毁,   
1072比如Sender.Free()是安全的吗? 
1073
1074* * *
1075
1076你的 控件的OnEnd事件, 已经是在对应窗口的线程中调用,估计这里问题不大,   
1077关键是你的destructor 中有否正确释放资源 
1078
1079Firing an event is like calling a method or function. So the event   
1080handler is called from the object itself, which is still alive at that   
1081time, and therefore it is potentially dangerous to delete it. It's OK to   
1082delete if you are sure that the method where the event is fired from no   
1083longer refers to any of the member variables (or resources). However, I strongly recommend the following COM IOleObject implementation:   
1084  
1085pIOleObject-&gt;Close(); //notify the object, so it can close itself gracefully   
1086pIOleObject-&gt;Release();//free your reference to the object 
1087
1088* * *
1089
1090###  MFC编写ActiveX,在属性页中如何得到控件的指针(VC/MFC ATL/ActiveX/COM ) 
1091
1092* * *
1093
1094http://support.microsoft.com/kb/205670 
1095
1096* * *
1097
1098###  如何使用WindowsAPI提供的MD5加密函数(VC/MFC 基础类 ) 
1099
1100* * *
1101
1102WinXP, VC7.1   
1103  
1104在MSDN中,有几个函数介绍:MD5Init();MD5Update();MD5Final();   
1105  
1106Header: Declared in MD5.h.   
1107Library: Included as a resource in CryptDLL.dll   
1108  
1109我在程序中#include <md5.h>   
1110#import <cryptdll.dll> //加不加都没用   
1111但编译器还是提示找不到那几个函数,请问这是什么原因? 
1112
1113* * *
1114
1115http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devnotes/winprog/md5init.asp   
1116  
1117This function has no associated header file or import library. You must use the LoadLibrary or GetProcAddress functions to dynamically link to Cryptdll.dll. 
1118
1119* * *
1120
1121###  Webbrowser的控制下载(Delphi VCL组件开发及应用 ) 
1122
1123* * *
1124
1125Webbrowser有onbeforeNavigate 可以判断是什么网址以及终止该操作。但是onDownloadBegin中如果获取当前下载对象的url以及如何终止呢??第二次提这个问题,我想在wb做的浏览器中,选择性的下载的一些对象,一些受排斥的对象,如js. falsh. image等,能进行选择性的阻止!! 
1126
1127* * *
1128
1129www.codeproject.com/atl/vbmhwb.asp   
1130虽然是面向VB设计的,但是Delphi也应该可以用 
1131
1132* * *
1133
1134###  如何使用VC来更改"工作组"或"域" (VC/MFC 硬件/系统 ) 
1135
1136* * *
1137
1138在WinXP/2003中可以使用WMI。参见 http://www.microsoft.com/technet/scriptcenter/guide/sas_wmi_osjn.mspx 、   
1139http://www.microsoft.com/technet/scriptcenter/topics/networking/05_atnc_dns.mspx 和http://www.microsoft.com/china/MSDN/library/enterprisedevelopment/softwaredev/WDdnclinicscripting.mspx 
1140
1141* * *
1142
1143###  怎样使CListctrl第一列中的各项居中显示(VC/MFC 界面 ) 
1144
1145* * *
1146
1147同样是“LVCFMT_CENTER”,为什么第二列和第三列都能居中,可第一列实际显示就是偏左呢? 
1148
1149* * *
1150
1151MSDN documentation: 
1152
1153If a column is added to a list-view control with index 0 (the leftmost column) and with LVCFMT_RIGHT or LVCFMT_CENTER specified, the text is not right-aligned or centered. The text in the index 0 column is left-aligned. Therefore if you keep inserting columns with index 0, the text in all columns are left-aligned. If you want the first column to be right-aligned or centered you can make a dummy column, then insert one or more columns with index 1 or higher and specify the alignment you require. Finally delete the dummy column. 
1154
1155* * *
1156
1157###  怎样使加到CListCtrl中的图标居中显示(VC/MFC 基础类 ) 
1158
1159* * *
1160
1161我在对话框程序中的一个CListCtrl第二列加入了图标,怎样才能使它们居中显示?文字居中就可以,假如图标就不行了。 
1162
1163* * *
1164
1165use customerdraw   
1166see http://blog.csdn.net/jiangsheng/archive/2003/11/20/3796.aspx and http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/listview/notifications/nm_customdraw_listview.asp 
1167
1168* * *
1169
1170###  问三个问题,都是与IE有关的(VC/MFC HTML/XML ) 
1171
1172* * *
1173
1174我做了一个ActiveX控件,在网页中使用,现有三个问题想问一下,不知道能否实现:   
11751、能否调出IE的下在对话框下载文件,就像IE右键中的“目标另存为”   
11762、能否在控件里控制在新窗口中打开一个链接   
11773、能否控制IE的前进后退的历史列表 
1178
1179* * *
1180
11811 用一个隐藏的浏览器控件浏览到文件   
11822 http://www.codeproject.com/shell/AutomateShellWindow.asp   
11833 http://msdn.microsoft.com/workshop/browser/travellog/travellog.asp 
1184
1185* * *
1186
1187###  产生不重复随机数的问题 (VB 基础类) 
1188
1189* * *
1190
1191生成 1 到 250 的125个随机数,要求无重复数 
1192
1193* * *
1194
1195You can shuffle an array of natural numbers between 1 and 250; however, you don't need to complete the shuffling since you merely need 125 numbers. 
1196
1197From http://en.wikipedia.org/wiki/Shuffle:   
1198  
1199In computer science, shuffling is equivalent to generating a random permutation of the cards. There are two basic algorithms for doing this, both popularized by Donald Knuth. The first is simply to assign a random number to each card, and then to sort the cards in order of their random numbers. This will generate a random permutation, unless two of the random numbers generated are the same. This can be eliminated either by retrying these cases, or reduced to an arbitrarily low probability by choosing a sufficiently wide range of random number choices.   
1200  
1201The second, generally known as the Knuth shuffle or Fisher-Yates shuffle[1], is a linear-time algorithm (as opposed to the previous O(n log n) algorithm if using efficient sorting such as mergesort or heapsort), which involves moving through the pack from top to bottom, swapping each card in turn with another card from a random position in the part of the pack that has not yet been passed through (including itself). Providing that the random numbers are unbiased, this will always generate a random permutation.   
1202  
1203Notice that great care needs to be taken in implementing the Knuth shuffle; even slight deviations from the correct algorithm will produce biased shuffles. For example, working your way through the pack swapping each card in turn with a random card from any part of the pack is an algorithm with nn different possible execution paths, yet there are only n! permutations. A counting argument based on the pigeonhole principle will clearly show that this algorithm cannot produce an unbiased shuffle, unlike the true Knuth shuffle, which has n! execution paths which match up one-to-one with the possible permutations.   
1204  
1205Whichever algorithm is chosen, it is important that a source of truly random numbers is used as the input to the shuffling algorithm. If a biased or pseudo-random source of random numbers is used, the output shuffles may be non-random in a way that is hard to detect, but easy to exploit by someone who knows the characteristics of the "random" number source.   
1206  
1207References   
1208D. Aldous and P. Diaconis, "Shuffling cards and stopping times", American Mathematical Monthly 93 (1986), 333–348   
1209Trefethen, L. N. and Trefethen, L. M. "How many shuffles to randomize a deck of cards?" Proceedings of the Royal Society London A 456, 2561–2568 (2000)   
1210  
1211http://www.math.washington.edu/~chartier/Shuffle/   
1212http://www2.toki.or.id/book/AlgDesignManual/BOOK/BOOK4/NODE151.HTM 
1213
1214* * *
1215
1216###  窗口句柄失效时抛出的异常是什么?如何捕获?如何获取当前IE窗口的URL(VC/MFC 基础类 ) 
1217
1218* * *
1219
1220我在MFC程序里检查各个IE窗口的URL并进行相应的处理。可是有时候用户关闭某个窗口程序就会出现异常   
1221(因为这时候窗口句柄已经失效了)。如何捕捉该异常呢?另外能否直接获取当前激活的IE窗口的URL?   
1222相关代码:   
1223  
1224SHDocVw::IShellWindowsPtr m_spSHWinds;   
1225if (m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) != S_OK)   
1226{   
1227CoUninitialize();   
1228return EmptyString;   
1229}   
1230int n = m_spSHWinds-&gt;GetCount();   
1231for (int i = 0; i &lt; n; i++)   
1232{   
1233//....   
1234} 
1235
1236* * *
1237
1238http://blog.joycode.com/jiangsheng/archive/2005/10/20/65489.aspx 
1239
1240* * *
1241
1242###  VC2003中新建了一个MFC的程序,如何加入一个ACTIVEX控件(.NET技术 VC.NET ) 
1243
1244* * *
1245
1246http://msdn.microsoft.com/library/en-us/vccore/html/vcgrfWhereIsClassWizardInVisualCNET.asp 
1247
1248* * *
1249
1250在htm中接受com控件发出的事件(VC/MFC ATL/ActiveX/COM ) 
1251
1252* * *
1253
1254我为客户做了一个com控件有一些事件(如OnStateChange)发出,客户要求用htm调用。   
1255一开始,一切正常htm中调用代码如下:   
1256  
1257<object classid="CLSID:EE9626A3-976C-470C-8282-07AB2FE2F85F" id="DvdPlayCtl"></object>
1258<script language="JavaScript">   
1259  
1260DvdPlayCtl.attachEvent("OnStateChange", MyOnStateChange);   
1261  
1262function MyOnStateChange(state,info)   
1263{   
1264alert("state change to "+state+" ,"+info);   
1265}   
1266</script>   
1267则一旦com的状态发生改变就发出OnStateChange事件,htm就可以正常接受并提示,但后来客户要求用   
1268另一种方式声明com控件,代码如下:   
1269  
1270<script language="JavaScript">   
1271var DvdPlayCtl = new ActiveXObject("DvdPlayCtl.DvdPlayCtl");   
1272</script>   
1273即动态生成此com控件,则运行htm时以前的代码DvdPlayCtl.attachEvent部分出错:“对象不支持此操作” 
1274
1275* * *
1276
12771、在com中增加一个属性OnStateChange,其类型为IDispatch *并为其添加put方法。   
1278  
12792、在put方法的实现中将传进的DISPATCH型指针赋给自己的成员变量IDispatch *m_pDispatch。   
1280  
1281STDMETHODIMP CDvdPlayCtl::put_OnStateChange(IDispatch *newVal)   
1282{   
1283// TODO: Add your implementation code here   
1284m_pDispatch = newVal;   
1285return S_OK;   
1286}   
1287  
12883、定义成员函数void Send_Event(int state, TCHAR * info);在发送事件的函数中添加以下代码:   
1289if (m_pDispatch != NULL)   
1290{   
1291CComVariant* pvars = new CComVariant[2];   
1292  
1293pvars[1] = state;//回调函数的第一个参数   
1294pvars[0] = info;//回调函数的第二个参数   
1295  
1296DISPPARAMS disp = { pvars, NULL, 2, 0 };   
1297HRESULT hr = m_pDispatch-&gt;Invoke(0, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &amp;disp, NULL, NULL, NULL);   
1298delete[] pvars;   
1299}   
1300注意:   
13011、pvars的填充与函数参数顺序是相反的   
13024、在htm中如下调用   
1303<script language="JavaScript">   
1304  
1305var DvdPlayCtl = new ActiveXObject("DvdPlayCtl.DvdPlayCtl");   
1306  
1307DvdPlayCtl.OnStateChange = OnStateChange;   
1308DvdPlayCtl.OnError = OnError;   
1309  
1310function OnStateChange(state,info)   
1311{   
1312alert("state change to "+state+" ,"+info);   
1313}   
1314</script>
1315
1316* * *
1317
1318###  類似VC的界面中,左邊的樹形控件不是添加一個控件,而是在MainFrm中定義的一個變量,如何做它的雙擊響應事件(VC/MFC 界面) 
1319
1320* * *
1321
1322控件的通知消息是发给父窗口的,但是MFC也支持消息反射,所以你可以在控件的父窗口主框架中处理消息,或者从CTreeCtrl派生一个类来处理反射的消息。参考微软技术文章TN062 消息反射。 
1323
1324* * *
1325
1326###  如何检测显示器是否处于休眠状态 (Delphi Windows SDK/API ) 
1327
1328* * *
1329
1330休眠状态是指用SendMessage(Handle, WM_SYSCOMMAND, SC_MONITORPOWER, -1)关闭的 
1331
1332* * *
1333
1334The GetDevicePowerState function is supposed to retrieve the current power state of the specified device. However, Apps may fail to use GetDevicePowerState on the display, as they can't get a handle on "\\\\.\Display#", while the # index is 1-based, or "\\\\.\LCD", for security reasons.   
1335  
1336If you are trying to do this on Windows XP, then you can use SetupDiGetDeviceRegistryProperty and Property: SPDRP_DEVICE_POWER_DATA to get the power management information. This is documented in the Windows XP DDK.   
1337  
1338The WMI Class Win32_DesktopMonitor does not report the power state. use SPI_GETPOWEROFFACTIVE or DeviceIOControl with IOCTL_VIDEO_GET_POWER_MANAGEMENT will simply reports power management is enabled or not. SPI_GETPOWEROFFACTIVE just determines whether the power-off phase of screen saving is enabled or not.   
1339  
1340BTW, you can always use the SetThreadExecutionState or other APIs (you have used) to switch ON the monitor no matter the monitor is in the ON or OFF state.   
1341  
1342References   
1343  
1344http://msdn.microsoft.com/library/en-us/Display_r/hh/Display_r/VideoMiniport_Functions_b47b2224-5e0b-44af-9d04-107ff1299381.xml.asp   
1345  
1346http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_desktopmonitor.asp 
1347
1348* * *
1349
1350###  使用CWebBrowser2的打印功能时,可不可以去掉文件路径的打印(VC/MFC 网络编程 ) 
1351
1352* * *
1353
1354如我们打印www.csdn.net主页   
1355在打印出的页面左下脚会有   
1356  
1357http://www.csdn.net/   
1358  
1359如何去掉,请朋友们帮忙解决 
1360
1361附:打印代码   
1362void CMyDlg::OnBtPrint()   
1363{   
1364// Verify the Web Browser control is valid.   
1365LPDISPATCH lpDispApp = m_wndBrowser.GetApplication();   
1366if(lpDispApp)   
1367{   
1368// Get the HTMLDocument interface.   
1369LPDISPATCH lpDispDoc = m_wndBrowser.GetDocument();   
1370if (lpDispDoc != NULL)   
1371{   
1372// Get the IOleCommandTarget interface so that we can dispatch the command.   
1373LPOLECOMMANDTARGET lpTarget = NULL;   
1374if (SUCCEEDED(lpDispDoc-&gt;QueryInterface(IID_IOleCommandTarget,(LPVOID*) &amp;lpTarget)))   
1375{   
1376// Execute the print preview command. The control will handle the print preview GUI.   
1377// OLECMDID_PRINTPREVIEW is defined in "docobj.h".   
1378lpTarget-&gt;Exec(NULL, OLECMDID_PRINTPREVIEW, 0, NULL, NULL);   
1379lpTarget-&gt;Release();   
1380}   
1381lpDispDoc-&gt;Release();   
1382}   
1383lpDispApp-&gt;Release();   
1384}   
1385}   
1386
1387
1388* * *
1389
1390其实IE是可以设置打印出来的Header和Footer的.   
1391  
13921\. 构造一个其实是SafeArray的VARIANT,这个SafeArray包含Header和Footer两个元素,   
1393然后在在Exec的倒数第二个VARIANT参数那里传进去,这样真实打印出来的时候就是   
1394你想要的设置了. 具体设置方法非常复杂,MSDN里面搜索一下   
1395Printing with the Internet Explorer WebBrowser Control,有非常详细论述.Microsoft都说只能Workaround.   
13962\. 当倒数第二个VARIANT参数是NULL的时候,IE会用你在IE里的页面设置.   
1397  
13983\. PRINTPREVIEW的时候,无论你在倒数第二个参数设了多么多东西,IE也只会用回IE自己的页面设置. 所以无论你怎么设,通过IE的打印预览,你无法看到你编程设置的Header和Footer, 你设的Header和Footer只有OLECMDID_PRINT才能奏效. 这时可以用虚拟打印机来调试程序的.   
1399  
14004\. 也可以Hack一下,打印或者打印预览前保存注册表里面的设置,然后设为你想要的,打印后再恢复回去.页面设置在注册表里的位置MSDN好像有讲,自己也可以搜注册表搜到.   
1401  
1402上面讨论以IE6 SP1为准.其他版本的有一定程度上不同 
1403
1404http://support.microsoft.com/support/kb/articles/Q267/2/40.ASP   
1405http://msdn.microsoft.com/workshop/browser/mshtml/reference/constants/idm_print.asp   
1406http://msdn.microsoft.com/workshop/browser/hosting/printpreview/reference/behaviors/headerfooter.asp 
1407
1408* * *
1409
1410###  请问在ActiveX控件里面怎么做出CScrollView那种可以滚动的效果(VC/MFC ATL/ActiveX/COM ) 
1411
1412* * *
1413
1414直接对滚动条进行设置的话就得处理好多消息,还得在画的时候算坐标 
1415
1416* * *
1417
1418Designing ActiveX Components with the MFC Document/View Model   
1419By exploiting MFC's poorly understood document/view model, you can give your ActiveX component many great features with relatively little effort   
1420  
1421http://www.microsoft.com/mind/0497/mfc.asp 
1422
1423* * *
1424
1425###  axWebBrowser 后退\前进的问题 (.NET技术 C# ) 
1426
1427* * *
1428
1429WinForm 中用 axWebBrowser 控件,有前进\后退的按钮,默认是 Enable = false,怎么能在点击网页中的连接后,激活后退按钮,退到首次访问页面后,禁止后退按钮,同理前进按钮. 也就是说,当有可后退旱,后退按钮激活,当可前进时,前进按钮激活,否则禁止. 
1430
1431* * *
1432
1433捕获commandstatechange事件   
1434参考http://support.microsoft.com/kb/q836128 
1435
1436* * *
1437
1438###  mdi方式下,建立多个doc/view模版的方法(VC/MFC 界面 ) 
1439
1440* * *
1441
1442mdi方式下,建立多个doc/view模版的方法?   
1443msdn中的帮助里有个例子,mdidocvw只有实现,没有过程讲解,看不懂。   
1444程序开始的时候有一个模版,但是第二个怎么加,手动建立3个类? 
1445
1446* * *
1447
1448Creation of Multiple Dynamic Views. How to initilize and use additional different views in your MDI app by using Doc / view architecture. Example code of OpenGL window and a Dialog window.   
1449  
1450http://www.codeproject.com/docview/MultiViewsMFC_MDI.asp   
1451  
1452Create additional classes. Use ClassWizard, WizardBar, or ClassView to create additional document, view, and frame-window classes beyond those created automatically by AppWizard.   
1453  
1454http://msdn.microsoft.com/library/en-us/vccore98/html/_core_sequence_of_operations_for_building_mfc_applications.asp 
1455
1456* * *
1457
1458###  如何给Richedit加上英文单词拼写检查功能?(Delphi VCL组件开发及应用) 
1459
1460* * *
1461
1462Adding Spell Check and Synonym Info to a Text Editor, using Word Automation   
1463  
1464http://www.codeproject.com/com/AutoSpellCheck.asp</cryptdll.dll></md5.h></pix^></pix^></windows.h></string.h></stdlib.h></stdio.h></cline,cline&></class></cline,cline></int,int></carlosclearthisrocha@[email></windows.h></windows.h>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus