Jiangsheng的CSDN Digest(March 4, 2006)

标签: webbrowserfunctionnulldescriptorinterfaceflash
32850人阅读 评论(5) 收藏 举报
分类:
为了便于搜索,这里尽可能保留了论坛上讨论的原文,但是这并不表示本人赞同帖子中的表述方式和观点。

CSDN 讨论总结系列:


在c++中如何创建一个文件? (VC/MFC 基础类)


已知IStream *pIStream取道内容,如何将pIStream内容写到一个文件中去?


http://www.codeproject.com/cpp/memorystream.asp

HANDLE hFile = CreateFile( lpFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); if ( hFile ) { HGLOBAL hMem = NULL; GetHGlobalFromStream( pStream, &hMem );// LPVOID lpData = GlobalLock( hMem ); DWORD dwBytesWritten; bResult = WriteFile( hFile, lpData, lBytesStreamed, &dwBytesWritten, NULL ); bResult &= ( dwBytesWritten == (DWORD)lBytesStreamed ); // clean up GlobalUnlock(hMem); CloseHandle(hFile); The GetHGlobalFromStream function retrieves the global memory handle to a stream that was created through a call to the CreateStreamOnHGlobal function. it may not work on other streams. The general approach is using a buffer as follows: HRESULT hr = S_OK; char szBuff[100]; ULONG cbRead = 1; while (hr == S_OK && cbRead > 0) { hr = pStream->Read(szBuff, sizeof(szBuff)-1, &cbRead); if (hr == S_OK) { szBuff[cbRead] = NULL; WriteToFile(szBuff,cbRead); } }

 


 

想获取windows下CPU温度,请高手指点(其他开发语言 汇编语言)


搜索过以前的帖子,发现没有好的解决方案.那我想只能分成下面几个步骤进行:

1,获取主板上用于监测的芯片型号。
2,针对特定型号写特定的访问程序。

现在想请高手指点,如何获取主板上使用的芯片型号?现在我对windows驱动是一窍不通。


try http://support.microsoft.com/default.aspx?scid=306852
or contact your motherboard manufacturer.
虽然ms在win2k之后就提供wmi中的win32_temperatureProbe,但大部分主板不能直接支持(需要安装主板自己的驱动程序)现在的普遍做法是通过访问superio的register来获取,所以程序第一步就是必须获取主板上的superio芯片的型号,不同型号的访问方法不同


如何监控Outlook Express接收新邮件? (VC/MFC ATL/ActiveX/COM )


想做的是像杀毒软件的邮件监控程序那样,每当Outlook Express接收到新邮件时,先启动自己编的一个程序,由这个程序中先检查这封电子邮件的标题和内容。查了好多资料,最多的都是用Office里的Outlook.可我们的要求是OE。如果可以实现我上面的功能,那能否扩展到任何邮件处理程序(如foxmail...)都适用可以监控呢?


检查这封电子邮件的标题和内容可以通过抓pop3包来实现。直接hook winsock的相关函数,然后检查进程名称,是邮件发生程序则执行自己的工作。

Outlook Express is not designed for automation. however, if you target Windows XP or later, you may use some new OE interfaces to obtain information.

Reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/outlookexpress/oe/reference/ifaces/istorenamespace/openspecialfolder.asp


把一个WebBrowser窗口里的内容都写到bmp里(VC/MFC 图形处理/算法)


有两个思路,第一个是提取WebBrowser的hdc,然后得到hBitmap,然后按Bmp的格式保存。还有一个很痛苦的方法, 就是在hMemDC里按WebBrowser中的字体字号去自己画。现在我尝试第一个方法,可是WebBrowser的内容很长,有滚动条控制的,我得到的hdc里只有当前屏幕上的内容。


IViewObject

  1. http://www.2ccc.com/article.asp?articleid=1423
  2. http://www.codeproject.com/miscctrl/wbp.asp
  3. http://www.codeproject.com/internet/htmlimagecapture.asp

使用CListCtrl显示大批量缩略图问题 (VC/MFC 界面)


由于工作需要大批量显示SolidWorks文件的缩略图(一万个左右),我现在使用的是虚CListCtrl既style = LVS_ICON|LVS_ALIGNTOP|LVS_OWNERDATA|WS_VISIBLE|WS_BORDER|WS_CHILD|LVS_SINGLESEL,对于SolidWorks文件可以读成bitmap,由于文件太多内存存不下,我现在想利用文件缓存,来缓存我生成的这些bitmap,有没有这样的方法,最好有例子.

我看了vcmute(横秋)有关这方面的解释提道了IExtractImage,不知道能解决我的问提吗?
http://community.csdn.net/Expert/topic/4134/4134216.xm8l?temp=.4045069
提供的连接没打开.


  1. 既然用了虚拟列表,一次显示的缩略图也不会超过几百个吧,这样对内存的需求就减少了很多。至于缓存,不需要加载所有的缩略图,使用后马上释放掉就可以了,利用双缓冲,绘制到一个内存DC上,刷新的时候再调取需要的缩略图http://blog.csdn.net/jiangsheng/archive/2003/11/20/3796.aspx
    这个示例没有在空闲时释放缓存,你可以自己决定缓存的大小上限,然后改写PrepCache函数。

    http://www.codeguru.com/cpp/controls/listview/usingimages/article.php/c899/
  2. http://www.codeguru.com/cpp/controls/listview/usingimages/article.php/c4159
  3. http://www.codeproject.com/shell/thumbextract.asp

请问怎样屏蔽WebBrowser下载窗口(VB 网络编程 )


当用WebBrowser打开一些不能解释的文件时就出现下载窗口,请问怎样屏蔽?即如果不能解释时就只出现网页不有打开页面不出现下载窗口。


一个思路:新建一个线程,在新的线程中不停的查找"文件下载"对话框,找到后,就用postmessage关闭它,不过要注意两个问题,一是要保证程序安全执行,调试的时候要小心,第二是,这样做的开销问题

http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/events/downloadbegin.asp


让VB6.0编的程序通过soap tooltik3.0调用C#写的WebService? (.NET技术 Web Services )


目前要改造部分以前用VB6.0编的管理程序,需要通过soap tooltik3.0调用C#写的WebService。由于这方面资料很少,只有求助于CSDN上的各位朋友了,谢谢!


http://msdn.microsoft.com/library/en-us/dnmapnet30/html/_MWSHeaders.asp


用什么工具能够将 一个COM插件注册(反注册)操作 提取到一个 .reg文件中(VC/MFC ATL/ActiveX/COM)


注册时被调用的插件的DllRegisterServer函数的具体实现依赖于DLL的作者,有可能超出注册表操作的范围。要监视注册表操作的话,HOOK 注册表操作函数,把目标进程的一切注册表操作和文件操作都被记录下来。


使用WebBrowser控件,如何获取当前页面,当前鼠标所在图片【或文字】的连接地址(Delphi 网络通信/分布式开发 )


简单来说,就是如何获取网页中当前鼠标下的连接地址


uses
SHDocVw, MSHtml, ActiveX

var
E: IHTMLElement;
begin

E :
= (WebBrowser1.Document as IHTMLDocument2).elementFromPoint(Mouse.CursorPos.X, Mouse.CursorPos.Y);
E :
= (WebBrowser1.Document as IHTMLDocument2).elementFromPoint(100, 100);
Label1.Caption :
= E.title;
Label1.Caption :
= E.innerText;


最近用IShellFolder2做了个遍历文件夹的程序,但是我发现当文件夹中文件数超过3000时,shell接口也不是很快啊(VC/MFC 基础类 )


能不能讲讲windows explorer点击文件夹,然后显示在右边list的工作原理。以前我也用vlist实现过,我用vector<MyData>存储每个右边tree的相应打开的list条目,MyData类型是存储文件夹下各个路径pidl及该节点一些辅助信息,然后在vlist需要显示的时候在把PIDL转换成相应的filename,filesize,filetype等等,可是还是很慢啊,(当然我是把vector填充满了以后再update_vlist),照理说vector插入几千条简单结构的记录应该很快才对啊。如果普通list用TEXTCALLBACK和I_IMAGECALLBACK,也是在需要显示时才去调用相应的text和image吧?那这样效率和虚列表差不多吧,指的是10000条记录以下的list


explorer那不是遍历,那只是展开当前文件下的文件而已。遍历肯定会慢的,IShellFolder应该是最理想的方法了,你也可以用一下FindFile,但是对虚拟目录无效。普通list用TEXTCALLBACK和I_IMAGECALLBACK还是可能差一些,因为虚列表中提供了缓存消息,你可以在适当的时候缓存数据来提高性能。vlist 只会重绘当前能显示的条目。如果你要保存数据结构的话,建议使用一个CArry只保存PIDL,然后用另外CArry一个保存要显示的信息列结构体的指针,再把第二个CArry以地址的方法传给vlist ,然后开线程去计算其他的信息,每计算一条调用一次RedrawItem,当然线程的操作要小心。仔细观察expolore你会发现,某些列的重绘并不是及时的。比如一个音乐文件的时间


有没有人用activeX控件或者其它控件显示过chm文件的内容(Delphi VCL组件开发及应用 )

请教:如用使用HtmlHelpA函数调用chm文档的指定页面(Delphi VCL组件开发及应用)


是显示在delphi的form里就行,不是调用hh.exe


Use the webbrowser control.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/htmlhelp/html/vsconocxov.asp
The HTML Help ActiveX control is designed to work with Internet Explorer and the Shdocvw.dll component. It does not include the design-time support that is necessary to use it with development tools, such as Microsoft Visual Basic Scripting Edition and Microsoft Visual C++.

var
theAdd: OleVariant;
begin
theAdd := 'mk:@MSITStore:' + AppPath + 'GPHelp.chm::/index.html';
///ms-its:C:/i386/CALC.CHM::/calc_scientific.htm
WebBrowser1.Navigate(theAdd);
end;

Reference

http://community.borland.com/article/0,1410,27842,00.html


SHGetSpecialFolderLocation是干什么的(VC/MFC 基础类 )


SHGetSpecialFolderLocation用来取得代表一些虚拟目录ITEMIDLIST。

//获取桌面的IDL LPITEMIDLIST pidlDesktop=NULL; HRESULT hr = SHGetSpecialFolderLocation(hwnd,CSIDL_DESKTOP,&pidlDesktop); if(FAILED(hr)) { ... } else { ... }

The long and sad story of the Shell Folders key
http://blogs.msdn.com/oldnewthing/archive/2003/11/03/55532.aspx


能否让我的应用程序以管理员的权限运行?就象通过管理员登陆后运行一样? (VC/MFC 基础类)


http://msdn.microsoft.com/library/en-us/secauthz/security/client_impersonation.asp


如何获得Web Browser中页面框架(frame iframe)内的元素(VB 网络编程 )


如果我们枚举Web Browser的Document对象中所有的元素,只能的页面框架的元素,请问怎样才能获得框架 src所指向页面的元素。


The capability of scripting across domain is affected by builtin security. Under "IE security settings" - "Miscellaneous", there are the options "Access data sources across domains" and "Navigate sub-frames across different domains".

Dim pFramesCol As IHTMLFramesCollection2 ! Dim pDisp As Object Dim IWindow2 As IHTMLWindow2 Dim i As Integer ! Dim varIndex As Variant Dim frameDoc As IHTMLDocument2 Set pFramesCol = doc.frames If Not pFramesCol Is Nothing Then For i = 0 To pFramesCol.length - 1 varIndex = i Set pDisp = pFramesCol.Item(varIndex) ! ' pDisp.QueryInterface IHTMLWindow2, IWindow2 ! Set IWindow2 = pDisp If Not IWindow2 Is Nothing Then If Not IWindow2.Document Is Nothing Then <== Possible error may arise: Access Denied Set frameDoc = IWindow2.Document End If End If Next i End If

webrowser.document.frames.item(index).all(i)


关于IHTMLDocument2接口(.NET技术 C# )


执行
IHTMLDocument2 doc = (IHTMLDocument2)axWebBrowser1.Document;
后发现:
可以正确进行 doc.write 操作,但访问doc的url和parentWindow属性运行的时候就提示错误

那个axWebBrowser1 是拖到对话框以后没有改任何设置的。


Document is not ready
handle DocumentComplete
http://support.microsoft.com/?kbid=312777


.net里面,怎么出来classWizard界面啊?我只会用vc6.0,.net不大会用(VC/MFC 基础类)


就是需要加消息处理函数,和虚拟函数继承的那个界面,在vc下面是快捷健:CTRL+W。.net下怎么做?


Visual C++ Concepts: Porting and Upgrading

Where Are ClassWizard and WizardBar in Visual C++ .NET?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vcgrfWhereIsClassWizardInVisualCNET.asp
 


如何设置WebBrowser控件显示内容的Html代码?(VB 控件)


如何设置WebBrowser显示页面的Html代码,WebBrowser可以显示制定的页面,但是我打算把页面的Html代码发送给WebBrowser进行显示,如何做呢?

WebBrowser1.Navigate2 "0", 0, "", "<HTML><DIV>我的内容</DIV></HTML>", ""
这行代码没作用啊.另外,我将网页文件放到资源文件中,然后读出来怎么就是乱码了呢?我想把网页放到资源文件中,防止用户改动内容,读出来后送给WebBrowser显示。


WebBrowser1.Navigate("about:blank")
WebBrowser1.Document.open
WebBrowser1.Document.writeln("<HTML>")
WebBrowser1.Document.writeln("<HEAD>")
WebBrowser1.Document.writeln("<TITLE>")
WebBrowser1.Document.writeln("New Document")
WebBrowser1.Document.writeln("</TITLE>")
WebBrowser1.Document.writeln("</HEAD>")
WebBrowser1.Document.writeln("<BODY>aaaa")
WebBrowser1.Document.writeln("</BODY>")
WebBrowser1.Document.writeln("</HTML>")
WebBrowser1.Document.Close

or

Navigate to about:blank
Wait for readyState to indicate "complete"
Get IPersistStreamInit interface from document
Call InitNew
Call Load
Wait for readyState to indicate "complete"


调用非托管 DLL 时,多层 struct/union 怎么 marshal (.NET技术 .NET Framework )


struct 的结构大概是这样

struct { const char *psVal1; const char *psVal2; struct { BYTE a1; union { BYTE bVal; // some other variables..... long lVal; struct { char *psVal; WORD wVal; }; struct { WORD wVal; BYTE *pbVal; }; }; } stVal; };



而且这个结构体的地址还要通过一个 callback 函数的 Int32 型参数传进来,只需要读,不需要写,应该怎么 Marshal 呢


最简单的方法就是在你的C++代码里写一个托管类为本地类marshal(就像你在COM Automation里干的一样.)


关于SHGetMalloc(&pMalloc) (VC/MFC 基础类)


是否windows将所有需要动态内存分配的(如new)shell对象,全都放在它自己管理的一个堆里?但是windows又不自己释放,需要用
SHGetMalloc(&pMalloc);来获得这个堆的指针,最后通过pMalloc->free(shellobj) 来释放分配的对象,最后再pMalloc->Release();释放自己对所有的动态创建的shellobj都适用吗?那什么时候调用pMalloc->Alloc来分配对象呢?用上面的方法后不需要调用它吗?


What's the difference between SHGetMalloc, SHAlloc, CoGetMalloc, and CoTaskMemAlloc
http://blogs.msdn.com/oldnewthing/archive/2004/07/05/173226.aspx

They are different code segments to do the same thing *now*. They used to do different things in history. In general, you should not implement IMalloc, instead using the COM implementation, which is guaranteed to be thread-safe in managing task memory. You get a pointer to the COM task allocator object's IMalloc through a call to the CoGetMalloc function.

SHFree can be used to free shell objects *allocated by* shelll functions


如何编程修改文件夹的属性? 比如隐藏(VC/MFC 基础类 )


The SetFileAttributes function sets the attributes for a file or directory.
http://msdn.microsoft.com/library/en-us/fileio/fs/retrieving_and_changing_file_attributes.asp


如何在regedit中打开特定的键并选中一个的指定的值(VC/MFC 基础类)


我想在程序中,调用regedit.exe打开一个特定的键,并且一个特定的值被选中.请问如何做才好.
就像在regmon中双击listview中的一项就能用regedit定位到相应的值上


write your own viewer, or use Win32 API to automate the regedit window( code may vary in different version of Windows.)
see http://support.microsoft.com/kb/178665


我的控件变量ip地址不能正确显示(VC/MFC 网络编程 )


 

BOOL CLocalipDlg::GetGlobalData() { PIP_ADAPTER_INFO pAdapterInfo = NULL; ULONG ulLEN = 0; ::GetAdaptersInfo(pAdapterInfo,&ulLEN); pAdapterInfo= (PIP_ADAPTER_INFO)::GlobalAlloc(GPTR,ulLEN); if(pAdapterInfo != NULL) { //网卡地址 memcpy(g_ucLocalMac, pAdapterInfo->Address, 6); //网关 g_dwGateWayIP = ::inet_addr(pAdapterInfo->GatewayList.IpAddress.String); //这里inet_addr() 返回的地址已经是按照网络字节顺序的 //本机ip g_dwLocalIP = ::inet_addr(pAdapterInfo->IpAddressList.IpAddress.String); //掩码 g_dwNetMask = ::inet_addr(pAdapterInfo->IpAddressList.IpMask.String); } return TRUE; } //自定义函数



//这里把32位二进制换成字符串
in_addr in;

in.S_un.S_addr = g_dwLocalIP;

m_IP.Format("%s", ::inet_ntoa(in));//然后赋给给控件变量,直接赋也不正确,控件变量是CString!

显示是204.204.204.204


204=0xCC
这说明
1 变量没有初始化
2 你没有检查函数调用的返回值判断调用是否成功
::GetAdaptersInfo(pAdapterInfo,&ulLEN);
pAdapterInfo= (PIP_ADAPTER_INFO)::GlobalAlloc(GPTR,ulLEN);
=>
::GetAdaptersInfo(pAdapterInfo,&ulLEN);//获取需要的缓冲区大小
pAdapterInfo= (PIP_ADAPTER_INFO)::GlobalAlloc(GPTR,ulLEN);//分配缓冲区
::GetAdaptersInfo(pAdapterInfo,&ulLEN);//获取信息


关于IHTMLDocument2接口的问题(.NET技术 C# )


我想设计一个win32对话框,点击对话框里面一个按钮,就用ie打开一个新窗口,那个窗口可以用那个IHTMLDocument2对象控制。
这样能不能用那个open方法做?


You need to create a COM object with the CLSID CLSID_INTERNETEXPLORER or progid internet.application
reference:
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/objects/internetexplorer.asp

You will need to create a WinForm application instead of Console application.

The DLL you will need is SHDocVw.DLL. To avoid name conflict, use AXIMP.EXE to generate your wrappers. Then, use ILDASM do disassemble the wrappers for both. Once you have that, you can recompile the IL for ShDocVw.dll (the one that AXIMP
generated) into another assembly with a different name. Then, you should be able to do the same with the IL for AxShDocVw.dll, adding a reference to the new dll that you just compiled. You should then be able to have these in your directory and use them no problem.

Better if you can program in managed C++.


如何更改xml节点的属性(VC/MFC HTML/XML )


xml文件的格式如下:

<eventDef> <event> <detail> <id>79999</id> <name>内部事件</name> </detail> <control> <enabled>true</enabled> <visible>false</visible> </control> <classify> <class>可疑网络活动类</class> <tech>事件监控</tech> <pop></pop> <danger></danger> <device>Misc</device> <service>MISC</service> </classify> </event> <eventDef>


小弟现在想要修改<enabled>...</enabled>的属性的值


1 可以用正则表达式进行文本替换
2 可以用MSXML DOM或者SAX将文件读入,之后进行修改后写回
参见
http://www.codeproject.com/string/use_regular_expression_in_your_program.asp
http://www.perfectxml.com/CPPMSXML/20020710.asp


WriteProcessMemory后,目标进程异常 (VC/MFC 进程/线程/DLL )



1. 程序A 用CreateProcess产生程序B的 M个实例。
2. 当程序B的 实例1 的某一页(为可读可写页)发生改变后,这时程序A用WriteProcessMemory把这一页写到其它M-1个实例中。
3.程序B中有一个查看按钮,单击此按钮会引用到刚才修改的页,平时一切正常,但当程序A中的 WriteProcessMemory执行后,点击此按钮,当前正在执行的实例就会终止运行。
4.通过一些内存查看软件观察,数据其实已经被写入到该页中。
5.我用FPE,发现程序A的WriteProcessMemory执行后,用FPE观察指定页,然后点击fpe上的“刷新”,这时再点击实例中的查看按钮,实例就不会中止了。
6.只想在ring3下解决这个问题,不想用ring0下修改pte绕过copy on write的办法。


a common mistake is trying to access the stack in another process.


如何替换windows启动时的登陆窗口(VC/MFC 基础类)


我想实现用自己的界面来替换windows的登陆窗口,如何实现?
或者说windows启动到桌面之前,先加载我定制的窗口界面,类似网吧客户机那种效果


http://msdn.microsoft.com/library/en-us/secauthn/security/supporting_new_logon_protocols.asp


LPCITEMIDLIST类型的数据如何能做到序列化(VC/MFC 基础类)


我想了两个方案,一转换为路径cstring再序列化.二.从cobject继承,实现一个CLPCITEMIDLIST,不知道行不行


你可以获得pidl的绝对路径之后再序列化。pidl中的数据仅作目录中临时定位用,并不能保证在程序关闭之后仍然有效。


微软的DrawCli例子中如何实现下列功能(VC/MFC 基础类)


问题1:我用例子上画矩形的方法画了一个矩形,这个矩形是如何被拖动的。用到哪些关键函数? 拖动效果是靠画了有擦,擦了再画的方式实现的吗?

问题2:我又添加了一个ToolBar,然后在上面添加了一个按钮。我想一点击此按钮就能在当前窗体上画一个2行2列的表格。此表格应该像矩形一样可以托拽。


1 DrawCli用的是CRectTracker,也就是画了再擦的技术。
2 添加一个自定义的shape,并且设计对应的Tool(就是鼠标和键盘处理啦)

一组还是一个对象,完全看你的数据组织方式。比如矩形,也可以看作4条线,也可以看作很多个点的集合,但是这里作为一个对象处理。你的表格,虽然是很多线条,当然也可以看作一个对象处理,在没有类的年代都可以,有了类只不过更简单了。比如,你可以定义一个CTable类来处理你的表格,可以包装表格大小,可以绘制自己,也可以处理创建、拖动等操作。


DoModal()返回-1(VC/MFC 基础类)


我的一个基于MFC对话框的程序.里面有CWebBrowser和CShockwaveFlash控件,在一台新装的机器上运行程序的时候InitInstance()里的Domodal()函数直接返回-1 ,对话框都没显示出来...重装系统前还可以用的


Shockwave Flash is not present in a fresh machine.

ask your user to go to www.macromedia.com/go/getflashplayer  to download one, or pack a recent version of flash player in your setup program.


怎么通过应用程序产生ctrl+alt+delete的sas消息(VC/MFC 进程/线程/DLL )


 

#include "windows.h" BOOL simulateAltControlDel(); void main() { simulateAltControlDel(); } BOOL simulateAltControlDel() { HDESK hdeskCurrent; HDESK hdesk; HWINSTA hwinstaCurrent; HWINSTA hwinsta; // // Save the current Window station // hwinstaCurrent = GetProcessWindowStation(); if (hwinstaCurrent == NULL) return FALSE; // // Save the current desktop // hdeskCurrent = GetThreadDesktop(GetCurrentThreadId()); if (hdeskCurrent == NULL) return FALSE; // // Obtain a handle to WinSta0 - service must be running // in the LocalSystem account // hwinsta = OpenWindowStation("winsta0", FALSE, WINSTA_ACCESSCLIPBOARD | WINSTA_ACCESSGLOBALATOMS | WINSTA_CREATEDESKTOP | WINSTA_ENUMDESKTOPS | WINSTA_ENUMERATE | WINSTA_EXITWINDOWS | WINSTA_READATTRIBUTES | WINSTA_READSCREEN | WINSTA_WRITEATTRIBUTES); if (hwinsta == NULL) return FALSE; // // Set the windowstation to be winsta0 // if (!SetProcessWindowStation(hwinsta)) return FALSE; // // Get the default desktop on winsta0 // hdesk = OpenDesktop("Winlogon", 0, FALSE, DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW | DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL | DESKTOP_JOURNALPLAYBACK | DESKTOP_JOURNALRECORD | DESKTOP_READOBJECTS | DESKTOP_SWITCHDESKTOP | DESKTOP_WRITEOBJECTS); if (hdesk == NULL) return FALSE; // // Set the desktop to be "default" // if (!SetThreadDesktop(hdesk)) return FALSE; PostMessage(HWND_BROADCAST,WM_HOTKEY,0,MAKELPARAM(MOD_ALT|MOD_CONTROL,VK_DELETE)); // // Reset the Window station and desktop // if (!SetProcessWindowStation(hwinstaCurrent)) return FALSE; if (!SetThreadDesktop(hdeskCurrent)) return FALSE; // // Close the windowstation and desktop handles // if (!CloseWindowStation(hwinsta)) return FALSE; if (!CloseDesktop(hdesk)) return FALSE; return TRUE; }


当前用户需要对登录桌面有DESKTOP_READOBJECTS权限


紧急!!!window.external 我在vc程序实现了自己的接口,但是ie本身的却没有了。(VC/MFC 网络编程)


我用vc,实现了ie的getexternal接口,在网页中可以访问到vc的函数了。但是,ie本身的接口却没有了,如addfavorite,showbrowserui.
关于addfavorte, 前天搜索了一下,一个高手介绍了可以发送消息 message=wm_command, wparam=2261给浏览器窗口。是可以实现的得了,但是其他的接口如showbrowserui等又如何解决。


可以把原来的external对象的IDispatch接口保存下来,getidsofnames和invoke的时候转发一下就可以了。showbrowserui是你自己要实现的……你还要实现一个external对象,需要支持的属性包括menuarguments 和 Shell UI helper的全部属性。

//在GetExternal函数中执行,得到原先的Idisptach接口 if(m_pShell == NULL) { CoCreateInstance(CLSID_ShellUIHelper, NULL, CLSCTX_SERVER, IID_IShellUIHelper, (void**)&m_pShell) }



然后,在自己实现的 GetIDOfNames及Invoke中,对于不是自定定义的函数直接调用
m_pShell->GetIDOfnames(....)及m_pShell->Invoke(....).

其中有个问题需要注意,就是如果在GetIfOfnames中,如果你给rgDispId赋值则可能跟ie内置函数的id重复,如调试中我得到showbrowserui的dispid=13。此时,需要通过另外变量辨别是默认函数或者是自定义函数了。

http://support.microsoft.com/kb/183339/
http://www.codeguru.com/cpp/com-tech/atl/article.php/c3565/
http://www.codeproject.com/atl/multidisp.asp


WinInet依赖IE,如果程序读取网页后关闭程序再打开程序,它还会从cache里读取内容么 (VC/MFC 基础类)


有的参数可以禁止从cache读取.我的意思是,在不使用这些参数的前提下,什么情况使程序直接从网上读取网页而不从cache读取?

可以肯定的是下面这些情况:
如果打开程序,读取网页,再次读取网页肯定是从cache读;如果从IE读取网页,然后再用程序读,肯定是从cache读

我想知道的是:如果读取网页后关闭程序再打开程序,它还会从cache里读取网页么?如果读取网页后重新启动操作系统,再打开程序,它还会从cache里读取网页么


http返回的响应头里包含了下载文件的大小,时间,可以得到这个值和本地的文件大小、时间比较的

IE is based on WinInet.search URLDownloadToFile and URLDownloadToCacheFile in MSDN


CString遇"undeclared identifier"的问题(CLR) (.NET技术 VC.NET )


首先我是用vc.net开了一个CLR项目,可能会出现混合库的问题,这个问题现在还不知道怎么描述

1、最初使用cstring时,告知"error C2065: 'CString' : undeclared identifier"

2、看了一些文档后,增加#include "afx.h",提示"fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]D:/xp/Microsoft Visual Studio 8/VC/atlmfc/include/afx.h24"

3、又看了一些文档,有些人推荐用string 代替cstring,故使用
String ^jc = gcnew String(pHeader->m_pReportV3[i].m_szName);
提示"The pointer passed in as a String must not be in the bottom 64K of the process's address space."


混合库用/CLR可以,但是用MFC的话得要有CWinApp对象,而这个对象又封装了应用程序的入口,所以建议还是用MFC的程序向导生成程序


vc.net lnk2001 unresolved external symbol int _cdecl func1(int) (?func1@@JOYAHH@Z) (.NET技术 VC.NET )


在vc++6中 使用a.h ,a.lib 和a.dll调用函数func1没有任何问题
在vc.net(vs2003.net)中总是报如题错误。


Calling a C function from a C++ program without using extern "C" (which causes the compiler to use the C naming convention) can cause LNK2001. Compiler options /Tp and /Tc cause the compiler to compile files as C or C++, respectively, regardless of the filename extension. These options can cause function names different from what you expect. Also, calling a function with parameter types that do not match those in the function declaration can cause LNK2001. There is currently no standard for C++ naming between compiler vendors or even between different versions of a compiler. Therefore, linking object files compiled with other compilers may not produce the same naming scheme and thus cause error LNK2001.

reference
http://msdn.microsoft.com/library/en-us/vccore/html/_error_Name_Decoration.asp


请问在服务程序中如何知道Windows已登录? (.NET技术 VC.NET )


下面的代码列出控制台用户的用户名
Topic in microsoft.public.vc.language
FindWindow() to terminal service clients

BOOL ShowConsoleUsernameFromSystem(void) { HDESK hdeskCurrent; HDESK hdeskTest; HDESK hdesk; HWINSTA hwinstaCurrent; HWINSTA hwinsta; // Save the current Window station hwinstaCurrent = GetProcessWindowStation(); if (hwinstaCurrent == NULL) return FALSE; // Save the current desktop hdeskCurrent = GetThreadDesktop(GetCurrentThreadId()); if (hdeskCurrent == NULL) return FALSE; // Obtain a handle to WinSta0 - service must be running // in the LocalSystem account hwinsta = OpenWindowStation("winsta0", FALSE, WINSTA_ACCESSCLIPBOARD | WINSTA_ACCESSGLOBALATOMS | WINSTA_CREATEDESKTOP | WINSTA_ENUMDESKTOPS | WINSTA_ENUMERATE | WINSTA_EXITWINDOWS | WINSTA_READATTRIBUTES | WINSTA_READSCREEN | WINSTA_WRITEATTRIBUTES); if (hwinsta == NULL) return FALSE; // Set the windowstation to be winsta0 if (!SetProcessWindowStation(hwinsta)) return FALSE; // Get the desktop hdeskTest = GetThreadDesktop(GetCurrentThreadId()); if (hdeskTest == NULL) return FALSE; // Get the default desktop on winsta0 hdesk = OpenDesktop("default", 0, FALSE, DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW | DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL | DESKTOP_JOURNALPLAYBACK | DESKTOP_JOURNALRECORD | DESKTOP_READOBJECTS | DESKTOP_SWITCHDESKTOP | DESKTOP_WRITEOBJECTS); if (hdesk == NULL) return FALSE; // Set the desktop to be "default" if (!SetThreadDesktop(hdesk)) return FALSE; // Get registry entries {//really, this is a separate function, just inserted here for ease: char szUserName[256]={0}; char szDomainName[256]={0}; DWORD type,size; HKEY hKeyWinlogon = 0; // Open the registry key to WinLogon entries: RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software//Microsoft//Windows NT//CurrentVersion//Winlogon", 0, KEY_READ, &hKeyWinlogon ); // Get the strings from entries: size = sizeof(szUserName); RegQueryValueEx( hKeyWinlogon, "DefaultUserName", 0L, &type, (LPBYTE)szUserName, &size); size = sizeof(szDomainName); RegQueryValueEx( hKeyWinlogon, "DefaultDomainName", 0L, &type, (LPBYTE)szDomainName, &size); RegCloseKey(hKeyWinlogon); szUserName[120]='/0'; szDomainName[120]='/0'; strcat(szDomainName,"//"); strcat(szDomainName,szUserName); MessageBox(NULL, (char *)szDomainName, "User at Console:", MB_OK); }//end of inserted function // Reset the Window station and desktop if (!SetProcessWindowStation(hwinstaCurrent)) return FALSE; if (!SetThreadDesktop(hdeskCurrent)) return FALSE; // Close the windowstation and desktop handles if (!CloseWindowStation(hwinsta)) return FALSE; if (!CloseDesktop(hdesk)) return FALSE; return TRUE; }

对于Windows终端服务器,WinSta0可能不是登录用户的windows station,这时你要调用WTSRegisterSessionNotification来截获用户登录消息。在这之前,需要判断终端服务的状态。
参见
http://msdn.microsoft.com/library/en-us/termserv/termserv/detecting_the_terminal_services_environment.asp


WebBrowser控件怎么禁用js等脚本?(.NET技术 C# )


http://msdn.microsoft.com/workshop/browser/hosting/wbcustomization.asp
http://www.codeproject.com/cs/miscctrl/WebBrowserEx.asp


如何得知ACCESS中表的字段有效性规则(Delphi 数据库相关)


你可以使用Jet Property Manager(Jet属性管理器/JPM)来创建/更改/删除所有属性(通过CreateProperty/Properties.Append, 这在DAO中有效),但是ADO/ADOx/JRO因为没有JPM到ADO的对应,所以只支持Jet Property的一个子集;幸运的是,有效性规则在ADO支持的属性列表中。你可以通过修改Jet OLEDB:Column Validation Rule和Jet OLEDB:Column Validation Text 这两个列属性来设置有效性规则。
参考
http://blog.csdn.net/jiangsheng/archive/2004/03/15/3799.aspx


如何得到显卡支持的分辨率列表(VC/MFC 基础类)


http://www.codeproject.com/system/enum_display_modes.asp


CRichEditCtrl的Debug版本和Release版本的排版差异?(VC/MFC 界面 )


我用SetWindowText设置内容,用/t /r /n控制排版,Debug版本排得好好的,到了release就排乱了.请都何解?


seems like a program caused by uninitialized variables

an uninitialized variable is a variable that is declared but is not set to a definite known value before it is used. It will have some value, but not a predictable one. As such it is a programming error and a common source of bugs in software.

Reference
http://blog.joycode.com/jiangsheng/archive/2006/02/05/71101.aspx


为何我用MFC做的OLE server打开后,在client端用 GetActiveObject 得不到指针(VC/MFC ATL/ActiveX/COM )


 client side:

/////////////////////////////////////// CLSID clsid; CLSIDFromProgID(L"MyServer.Document", &clsid); IUnknown *pUnk = NULL; IDispatch *pDisp = NULL; HRESULT hr = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk); if(SUCCEEDED(hr)) { hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDisp); break; } ///////////////////////////////////////

先运行MyServer, 在运行client,clsid可以正确得到,但GetActiveObject不能成功

难道Server端启动时要用 RegisterActiveObject 来注册吗, 我用MFC作的OLE Server, 这个工作应该MFC帮我做了吧?

 


http://support.microsoft.com/kb/q155690/


基于对话框的程序中放置了一个WebBrowser控件,怎样在另外一个程序中获得该WebBrowser的IHTMLDocument(VC/MFC ATL/ActiveX/COM)


Write a COM server (create the application with automation support, and add a property exporting the IDispatch interface of the WebBrowser control.

Another way is to register a systemwide message with RegisterWindowMessage and return the HWND of the WebBrowser control. The other application can send this message to the dialog application and use the HWND of the WebBrowser control to retrieve the IHTMLDocument interface of the HTMLDocument obejct(see MSDN
KB Q249232 HOWTO: Get IHTMLDocument2 from a HWND http://support.microsoft.com/support/kb/articles/Q249/2/32.asp ).

http://msdn.microsoft.com/msdnmag/issues/01/06/c/default.aspx


IDispatch调用_AppDomain (VC/MFC ATL/ActiveX/COM)


在SDK程序中通过COM得到了一个指向System.AppDomain对象的IDispatch*.然后通过Invoke来进行操作;但是调用ToString之类的无参数方法还可以,但在偶想调用Load之类的方法时就总是不行.Invoke返回的值在MSDN中查不到.
偶想问一下:非托管代码在调用托管代码时传递的字符串应该是那种类型的啊?偶传的是BSTR*.


用IDispatch::GetTypeInfo看看Load方法到底期待什么类型的参数——很有可能是一个string对象的IDispatch接口。重载AppDomain.Load这名字的函数太多。


Run-Time Check Failure #N (C/C++ C++ 语言)


环境:Visual Studio.Net 2003
类型:Debug
以下代码作了简化,有谁有Run-Time Check Failure 资料?

代码1

#include "stdafx.h" void malice() { printf("Hey,you're been attacked./n"); } void foo() { int *ret; ret=(int*)&ret+2; (*ret)=(int)malice; } int _tmain(int argc, _TCHAR* argv[]) { foo(); return 0; }

运行后出现:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.


代码2

#include "stdafx.h" void foo() { int var[2]; var[2] = 0; } int _tmain(int argc, _TCHAR* argv[]) { foo(); return 0; }

运行后出现:
Run-Time Check Failure #2 - Stack around the variable 'var' was corrupted.

#include "stdafx.h" #include <iostream> using namespace std; int a,b; int _tmain(int argc, _TCHAR* argv[]) { int c; cout<<a<<"/n"; cout<<b<<"/n"; cout<<c<<"/n"; return 0; }

运行后出现:
Run-Time Check Failure #3 - The variable 'c' is being used without being defined.


http://msdn.microsoft.com/msdnmag/issues/01/08/bugslayer/default.aspx


获取窗口句柄出现问题(VC/MFC 进程/线程/DLL)


进程A 通过CreateProcess创建了 30个程序B的实例,可以通过进程ID枚举B的30个实例的窗口句柄时,会出现找不到的情况(已经在CreateProcess后延时了一段时间),


WaitForInputIdle.有的程序执行时间比较短


如何在ActiveX控件中获得IE地址栏中的地址(VC/MFC ATL/ActiveX/COM )


http://support.microsoft.com/kb/181678

void CVC404PCtrl::OnSetClientSite()
{
// TODO: Add your specialized code here and/or call the base class

if (m_pControlSite != NULL)
{
// Obtain URL from container moniker.
CComPtr<IMoniker> spmk;
LPOLESTR pszDisplayName;
IOleClientSite
*pClientSite = NULL;
m_pControlSite
->QueryInterface(IID_IOleClientSite, (void**)&pClientSite);
if (SUCCEEDED(pClientSite->GetMoniker(
OLEGETMONIKER_TEMPFORUSER,
OLEWHICHMK_CONTAINER,
&spmk)))
{
if (SUCCEEDED(spmk->GetDisplayName(
NULL, NULL,
&pszDisplayName)))
{
USES_CONVERSION;

CComBSTR bstrURL;
bstrURL
= pszDisplayName;

ATLTRACE(
"The current URL is %s/n", OLE2T(bstrURL));
CoTaskMemFree((LPVOID)pszDisplayName);
CString strServerIP
= OLE2T(bstrURL);
g_strServerIP
= strServerIP.Mid(7);
int nPos = g_strServerIP.Find('/', 0);
if(nPos > 0)
g_strServerIP
= g_strServerIP.Left(nPos);
}

}

}



}

 


关于CListCtrl添加彩色图标的问题(VC/MFC 基础类)


自己实现了一个CMyListCtrl,有一个成员变量m_imgList,其中有个成员函数是AddImage以下是部分添加图标的代码,为什么生成的缩略图是黑白的?怎样生成彩色的?

void AddImage() { SHFILEINFO shFinfo; int iIcon; CString path = "c://windows//"; SHGetFileInfo( path, 0, &shFinfo, sizeof( shFinfo ), SHGFI_ICON | SHGFI_LARGEICON ); iIcon = shFinfo.iIcon; HICON hicon = m_sysImgList.ExtractIcon(iIcon); CFileStatus status; CFile::GetStatus(strPath, status); if(!!(status.m_attribute & 0x10)) { CDC dc; dc.CreateCompatibleDC(GetDC()); CBitmap iconBitmap; iconBitmap.CreateCompatibleBitmap(&dc,ICON_WIDTH, ICON_HEIGHT); CGdiObject *oldObj = dc.SelectObject(&iconBitmap); POINT pt; pt.x = (ICON_WIDTH - 32) / 2; pt.y = (ICON_HEIGHT - 32) / 2; CBrush whiteBrush(RGB(0, 0, 255)); dc.FillRect(CRect(0,0,ICON_WIDTH,ICON_HEIGHT),&whiteBrush); dc.DrawIcon(pt,hicon); dc.SelectObject(oldObj); m_imgList.Add(&iconBitmap,&iconBitmap); } } 

Memory DC created with CreateCompatibleDC() is given a 1x1 monochrome bitmap as its default bitmap. You need to select a bitmap with color before drawing.


如何使用VC多cell拷贝,如何修改单个cell中内容的字体,如何合并excel中的几个单元格(VC/MFC ATL/ActiveX/COM)


我现在要对一个已有的excel文档进行编辑如下:
1 添加title,这就需要把所有的数据向下移动一行,然后把第一行N个格合并。
2 写入title并且修改title的字体

我一开始用的是一个单元格一个单元格的移动,发现速度特别慢。

所以我想知道:如何使用VC多cell拷贝
如何修改单个cell中内容的字体
如何合并excel中的几个单元格


自己录制宏,之后参考http://support.microsoft.com/support/KB/Articles/Q194/9/06.asp

http://www.blogjava.net/jinheking/archive/2005/07/19/5150.html

Office的VBA帮助里有例子.也可以在Office中录制宏
参考

Excel::WorkbooksPtr oBooks; oBooks=oApp->GetWorkbooks(); Excel::_WorkbookPtr oBook; oBook=oBooks->Add(vOpt); Excel::WorksheetsPtr oSheets; oSheets=oBook->GetWorksheets(); Excel::_WorksheetPtr oSheet; oSheet=oSheets->GetItem(1L); Excel::RangePtr oRange; m_pCanvas->SaveCurveData(oSheet,oRange); Excel::PicturesPtr pts=oSheet->Pictures(); pts->Insert((_bstr_t)strBmp); //strBmp 为图片存放的位置 DeleteFile(strBmp); pts->PutTop(m_pCanvas->m_nPicturePos); //COleVariant vstr=strFn; COleVariant vTrue((short)TRUE),vFalse((short)FALSE); oBook->SaveAs(COleVariant(strFn),-4143L,COleVariant(""),COleVariant(""),vFalse, vFalse,Excel::XlSaveAsAccessMode(1L)); oBook->PutSaved(1,VARIANT_BOOL(TRUE)); Excel::PicturesPtr pts=oSheet->Pictures(); pts->Insert((_bstr_t)strBmp); //strBmp 为图片存放的位置 DeleteFile(strBmp); pts->PutTop(m_pCanvas->m_nPicturePos); //COleVariant vstr=strFn;

关于单实例运行,应用程序转到后台时除了发送WM_ACTIVATEAPP还有什么消息(VC/MFC 界面)


smartphone平台,希望应用程序第二个实例启动时激活第一个实例
现在问题时第一个实例有多个窗口,我需要得到第一个实例转入后台时的最上层的窗口然后执行setforegroundwindow

但现在发现smartphone不支持WM_ACTIVATEAPP消息,不支持函数GetLastActivePopup
不知道通过系统函数或消息的方法还有什么办法解决

不然我想只能使用WM_ACTIVATE来记录每次inactive时的窗口,最后一个就是最后显示的,每个窗口都要响应WM_ACTIVATE


你可以在每个顶层窗口都加上同一个注册消息的处理……枚举的时候找到第一个就可以了http://www.codeproject.com/shell/AutomateShellWindow.asp


用wmformat sdk 能否实现 asf 文件放慢读取 (专题开发/技术/项目 多媒体/流媒体开发)


HRESULT Start(
QWORD cnsStart,
QWORD cnsDuration,
float fRate,
void* pvContext
);
fRate
[in] Playback speed. Normal speed is 1.0. Higher numbers cause faster playback, and numbers less than zero indicate reverse rate (rewinding). The valid ranges are 1.0 through 10.0, and -1.0 through -10.0.

可以快速向前读取,后退. 但不能放慢读取


use IWMReaderAdvanced::SetUserProvidedClock to set a custom clock


如何切换到虚拟键盘(VC/MFC 基础类 )


在使用智能输入法的时候,有一个智能输入法,我想通过程序打开他,并切换到PC键盘,


call ImmSetConversionStatus with IME_CMODE_SOFTKBD


如何用程序来设置IE的禁止脚本调试 (VB VBA )


go to take a look at [HKEY_CURRENT_USER/Software/Microsoft/Internet Explorer/Main]
Other debuggers such as Visual Studio Machine Debugger may still try to debug the error.

Private Sub Command1_Click() '首先引用Registry Access Functions Dim mREG As New REGTool5.Registry Dim ret As Boolean ret = mREG.UpdateKey(HKEY_CURRENT_USER, "Software/Microsoft/Internet Explorer/Main", "Disable Script Debugger", "yes") ret = mREG.UpdateKey(HKEY_CURRENT_USER, "Software/Microsoft/Internet Explorer/Main", "DisableScriptDebuggerIE", "yes") End Sub

 


 

如何将剪贴板中的图象复制到WEB上的applet中 (Java Web 开发 )


好象有权限问题


http://forum.java.sun.com/thread.jspa?threadID=576069


编写能适应XP下快速用户切换特性的服务程序的问题(VC/MFC 基础类)


Windows XP下写了一个服务程序,创建时指定了SERVICE_WIN32_OWN_PROCESS和SERVICE_INTERACTIVE_PROCESS标志,还指定了SERVICE_AUTO_START使服务自动启动。服务启动时创建一个线程,该线程只是简单的一个循环:每秒Beep一声。系统启动后,在欢迎界面时该服务就自动启动了,可以听见每秒一次的Beep声,然后点击一个用户登录后,Beep声也正常,然后点击“开始”-〉“注销”-〉“切换用户”回到用户选择界面时,Beep声仍然正常,但是选择另外一个用户登录后,Beep声消失,再切换回原来的用户,Beep声恢复,这是为什么?切换到新用户后Beep线程是否已经被自动挂起?如何才能使切换到新用户后仍然能使Beep正常继续?


切换到新用户后删除线程,然后重新生成与用户交互的线程(注用代码交互,不是设置SERVICE_INTERACTIVE_PROCESS标志)

在开始菜单-》启动里有个程序,负责启动服务程序。这样,服务程序就在用户登陆以后才能运行。服务程序在用户注销/切换的时候就自己结束。

All services run in Terminal Services session 0. Therefore, if an interactive service displays a user interface, it is only visible to the user who connected to session 0. Because there is no way to guarantee that the interactive user is connected to session 0, do not configure a service to run as an interactive service on Terminal Services or Windows XP (fast user switching is implemented using Terminal Services).

If a service running on a multiuser system must interact with a user, the service should create a separate GUI application running within the context of the interactive user. The easiest way to run an application in each session is to add it to the following key: HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Run. This GUI application should be designed to communicate with the service through some method of IPC, for example, named pipes, as described in the previous section. By using named pipes, the server can distinguish between multiple user processes by giving each pipe a unique name based on the session ID.

Reference:

Interacting with Services
http://blogs.msdn.com/larryosterman/archive/2005/09/14/466175.aspx

Architecture of Fast User Switching
http://support.microsoft.com/kb/294737


为什么javascript只能收到控件的事件,而普通的COM不行呢(VC/MFC ATL/ActiveX/COM )


test2是用ATL建立的一个full control,Apartment模型,dual接口,支持连接点.
test是用ATL建立的一个simple object,Apartment模型,dual接口,支持连接点.
这两个对象都增加了事件OnTest,并且都在test方法中调用了Fire_OnTest();
但是网页运行的结果是只弹出对话框"test2".


http://groups.google.com/group/microsoft.public.vc.atl/browse_thread/thread/746df98b5c75f906/65cf79a77ad62795?lnk=st&q=%22simple+object%22+event+atl+internet+explorer&rnum=1&hl=en#65cf79a77ad62795

When using theATL, the following 'lite control' ATL objects do not implement the IProvideClassInfo2 interface by default:

You can easily add support for event handling by implementing the
IProvideClassInfo interfaces. This is done by deriving your control from the
default ATL implementation, IProvideClassInfo2Impl.
1. Add the following line to your class derivation list:
public IProvideClassInfo2Impl<&CLSID_<object_name>, NULL,
&LIBID_<project_name>Lib>
2. Add the following lines to your COM_MAP:
COM_INTERFACE_ENTRY(IProvideClassInfo)
COM_INTERFACE_ENTRY(IProvideClassInfo2)
Hope that helps. For additional information you can take a look at KB Q200839 http://support.microsoft.com/kb/200839


如何向richtextbox中插入flash影片(VB 基础类)


注意:是真正的插入对象,不是setparent之类的实现,要求不用剪贴板,不重新封装播放flash的控件,能实现多个影片同时播放

其实我这个想法是看了的文章后产生的,你可以看一下:
http://blog.csdn.net/dtianx/archive/2004/11/17/184949.aspx


//但多次粘贴时,只能有一个控件处于活动状态

怀疑这是由于Flash控件的刷新机制与Rich Edit的OLE接口存在冲突
所以很可能需要封装Flash控件,为Flash控件做好OLE接口

我也这么想过,但这样一来,通用性就降低了,所以要求,不重新封装播放flash的控件,就是想看看有没有办法从其它方面进行突破

Yes, Flash.ocx supports IOleObject. but it won't update its display like the QQ image lib ActiveX.

private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { HWND h=(HWND)richTextBox1->Handle.ToInt32(); LPRICHEDITOLElpRichEditOle=NULL; LPOLEOBJECTlpObject=NULL; LPSTORAGE lpStorage=NULL; LPOLECLIENTSITElpClientSite=NULL; LPLOCKBYTESlpLockBytes = NULL; REOBJECT reobject; ZeroMemory(&reobject, sizeof(REOBJECT)); reobject.cbStruct = sizeof(REOBJECT); HRESULT hr=S_OK; CLSID clsid=CLSID_NULL; do{ ::SendMessage(h, EM_GETOLEINTERFACE, 0, (LPARAM)&lpRichEditOle); if(lpRichEditOle==NULL)break; hr= ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes); if (hr != S_OK||lpLockBytes==NULL)break; hr= ::StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &lpStorage); if (hr!= S_OK||lpStorage==NULL)break; hr=lpRichEditOle->GetClientSite(&lpClientSite); if (hr!= S_OK||lpClientSite==NULL)break; try { ShockwaveFlashObjects::IShockwaveFlashPtrpFlash; hr = pFlash.CreateInstance(ShockwaveFlashObjects::CLSID_ShockwaveFlash); if( FAILED(hr) )_com_issue_error(hr); /*if(openFileDialog1->ShowDialog()==DialogResult::OK)*/{ //__wchar_t * str = (__wchar_t *)(void*)Marshal::StringToHGlobalUni(openFileDialog1->FileName); //_bstr_t bstrPath(str); //Marshal::FreeHGlobal(str); _bstr_t szMovie = "C://WINDOWS//Help//Tours//mmTour//intro.swf"; pFlash->PutMovie(szMovie); if( FAILED(hr) )_com_issue_error(hr); hr = pFlash.QueryInterface(IID_IOleObject, (void**)&lpObject); if( FAILED(hr)||lpObject==NULL)_com_issue_error(hr); hr=OleSetContainedObject(lpObject, TRUE); if( FAILED(hr) )_com_issue_error(hr); hr=lpObject->GetUserClassID(&clsid); if( FAILED(hr) )_com_issue_error(hr); reobject.clsid = clsid; reobject.cp = REO_CP_SELECTION; reobject.dvaspect = DVASPECT_CONTENT; reobject.dwFlags = REO_BELOWBASELINE; reobject.dwUser = 0; reobject.poleobj = lpObject; reobject.polesite = lpClientSite; reobject.pstg = lpStorage; SIZEL sizel={0,0}; reobject.sizel = sizel; hr=lpRichEditOle->InsertObject(&reobject); pFlash->Play(); } } catch( _com_error e ) { LPCTSTR lpszErrMessage=e.ErrorMessage(); } }while(FALSE); if(lpLockBytes) lpObject->Release(); if(lpLockBytes) lpLockBytes->Release(); if(lpClientSite) lpClientSite->Release(); if(lpRichEditOle) lpRichEditOle->Release(); }

刷新的问题倒是不大,可以这样:

public void UpdateObjects() { int k = this.IRichEditOle.GetObjectCount(); for (int i = 0; i < k; i++) { REOBJECT reoObject = new REOBJECT(); this.IRichEditOle.GetObject(i, reoObject, GETOBJECTOPTIONS.REO_GETOBJ_ALL_INTERFACES); if (reoObject.dwUser == 1) { Point pt = this._richEdit.GetPositionFromCharIndex(reoObject.cp); Rectangle rect = new Rectangle(pt, reoObject.sizel); this._richEdit.Invalidate(rect, false); // repaint } } }

然后加个timer调用UpdateObjects

现在主要的问题是在vb中没法使用QueryInterface语句,直接用set赋值又提示类型不符
找到一种richtextbox加入flash控件的方法。像这样:

' 需要 Command1 和 RichTextBox1。还需要 IOleObject 的 tlb

Private Sub Command1_Click() Dim objOle As IOleObject, objFlash As Object Set objOle = RichTextBox1.OLEObjects.Add(, , , "ShockwaveFlash.ShockwaveFlash") Set objFlash = objOle objFlash.Movie = "http://cardimg.163.com/mcards/1/big/3081.swf" End Sub



不过大概因为用的是 OLE 静态嵌入,还是只能一次激活单个控件。用 spy++ 看的话只有激活的控件才有 MacromediaFlashPlayerActiveX 类的窗口。 :(
其实就我的提问的问题而言,问题已经基本解决了,不过费了很大的力气声明了对应IShockwaveFlash接口的结构体,总想把他用上,另外,对于这个结构体声明的是否正确,心里还不敢肯定,所以有上面的一问,我声明的结构体,哪位帮我看看,对还是不对:

Private Type IShockwaveFlashVB ' IUnknown mQueryInterface As Long 'Function,offset 0 AddRef As Long 'Function,offset 4 mRelease As Long 'Function,offset 8 'IDispatch GetTypeInfoCount As Long 'Function,offset 12 GetTypeInfo As Long 'Function,offset 16 GetIDsOfNames As Long 'Function,offset 20 Invoke As Long 'Function,offset 24 'IShockwaveFlash GetReadyState As Long 'property get,offset 28 GetTotalFrames As Long 'property get,offset 32 GetPlaying As Long 'property get,offset 36 SetPlaying As Long 'property let,offset 40 GetQuality As Long 'property get,offset 44 SetQuality As Long 'property let,offset 48 GetScaleMode As Long 'property get,offset 52 SetScaleMode As Long 'property let,offset 56 GetAlignMode As Long 'property get,offset 60 SetAlignMode As Long 'property let,offset 64 GetBackgroundColor As Long 'property get,offset 68 SetBackgroundColor As Long 'property let,offset 72 GetLoop As Long 'property get,offset 76 SetLoop As Long 'property let,offset 80 GetMovie As Long 'property get,offset 84 SetMovie As Long 'property let,offset 88 GetFrameNum As Long 'property get,offset 92 SetFrameNum As Long 'property let,offset 96 SetZoomRect As Long 'Function,offset 100 Zoom As Long 'Function,offset 104 Pan As Long 'Function,offset 108 Play As Long 'Function,offset 112 Stop As Long 'Function,offset 116 Back As Long 'Function,offset 120 Forward As Long 'Function,offset 124 Rewind As Long 'Function,offset 128 StopPlay As Long 'Function,offset 132 GotoFrame As Long 'Function,offset 136 CurrentFrame As Long 'Function,offset 140 IsPlaying As Long 'Function,offset 144 PercentLoaded As Long 'Function,offset 148 FrameLoaded As Long 'Function,offset 152 FlashVersion As Long 'Function,offset 156 GetWMode As Long 'property get,offset 160 SetWMode As Long 'property let,offset 164 GetSAlign As Long 'property get,offset 168 SetSAlign As Long 'property let,offset 172 GetMenu As Long 'property get,offset 176 SetMenu As Long 'property let,offset 180 GetBase As Long 'property get,offset 184 SetBase As Long 'property let,offset 188 GetScale As Long 'property get,offset 192 SetScale As Long 'property let,offset 196 GetDeviceFont As Long 'property get,offset 200 SetDeviceFont As Long 'property let,offset 204 GetEmbedMovie As Long 'property get,offset 208 SetEmbedMovie As Long 'property let,offset 212 GetBGColor As Long 'property get,offset 216 SetBGColor As Long 'property let,offset 220 GetQuality2 As Long 'property get,offset 224 SetQuality2 As Long 'property let,offset 228 LoadMovie As Long 'Function,offset 232 TGotoFrame As Long 'Function,offset 236 TGotoLabel As Long 'Function,offset 240 TCurrentFrame As Long 'Function,offset 244 TCurrentLabel As Long 'Function,offset 248 TPlay As Long 'Function,offset 252 TStopPlay As Long 'Function,offset 256 SetVariable As Long 'Function,offset 260 GetVariable As Long 'Function,offset 264 TSetProperty As Long 'Function,offset 268 TGetProperty As Long 'Function,offset 272 TCallFrame As Long 'Function,offset 276 TCallLabel As Long 'Function,offset 280 TSetPropertyNum As Long 'Function,offset 284 TGetPropertyNum As Long 'Function,offset 288 TGetPropertyAsNumber As Long 'Function,offset 292 GetSWRemote As Long 'property get,offset 296 SetSWRemote As Long 'property let,offset 300 GetFlashVars As Long 'property get,offset 304 SetFlashVars As Long 'property let,offset 308 GetAllowScriptAccess As Long 'property get,offset 312 SetAllowScriptAccess As Long 'property let,offset 316 GetMovieData As Long 'property get,offset 320 SetMovieData As Long 'property let,offset 324 GetInlineData As Long 'property get,offset 328 SetInlineData As Long 'property let,offset 332 GetSeamlessTabbing As Long 'property get,offset 332 SetSeamlessTabbing As Long 'property let,offset 332 End Type


存在版本问题
Flash没有遵守COM接口规则


D:/WINDOWS/system32/Macromed/Flash/flash.ocx

[ uuid(D27CDB6B-AE6D-11CF-96B8-444553540000), version(1.0), helpstring("Shockwave Flash") ] library ShockwaveFlashObjects { [ odl, uuid(D27CDB6C-AE6D-11CF-96B8-444553540000), helpstring("Shockwave Flash"), dual, oleautomation ] interface IShockwaveFlash : IDispatch { [id(0xfffffdf3), propget, helpstring("property ReadyState")] HRESULT ReadyState([out, retval] long* pVal); [id(0x0000007c), propget, helpstring("property TotalFrames")] HRESULT TotalFrames([out, retval] long* pVal); [id(0x0000007d), propget, helpstring("property Playing")] HRESULT Playing([out, retval] VARIANT_BOOL* pVal); [id(0x0000007d), propput, helpstring("property Playing")] HRESULT Playing([in] VARIANT_BOOL pVal); …… [id(0x0000009f), propget, helpstring("property SWRemote")] HRESULT SWRemote([out, retval] BSTR* pVal); [id(0x0000009f), propput, helpstring("property SWRemote")] HRESULT SWRemote([in] BSTR pVal); [id(0x000000aa), propget, helpstring("property FlashVars")] HRESULT FlashVars([out, retval] BSTR* pVal); [id(0x000000aa), propput, helpstring("property FlashVars")] HRESULT FlashVars([in] BSTR pVal); [id(0x000000ab), propget, helpstring("property AllowScriptAccess")] HRESULT AllowScriptAccess([out, retval] BSTR* pVal); [id(0x000000ab), propput, helpstring("property AllowScriptAccess")] HRESULT AllowScriptAccess([in] BSTR pVal); }; D:/WINDOWS/system32/Macromed/Flash/Flash8.ocx

 

[ uuid(D27CDB6B-AE6D-11CF-96B8-444553540000), version(1.0), helpstring("Shockwave Flash") ] library ShockwaveFlashObjects { // TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046} importlib("STDOLE2.TLB"); // Forward declare all types defined in this typelib interface IShockwaveFlash; dispinterface _IShockwaveFlashEvents; interface IFlashFactory; interface IFlashObjectInterface; interface IDispatchEx; interface IServiceProvider; [ odl, uuid(D27CDB6C-AE6D-11CF-96B8-444553540000), helpstring("Shockwave Flash"), dual, oleautomation ] interface IShockwaveFlash : IDispatch { [id(0xfffffdf3), propget, helpstring("property ReadyState")] HRESULT ReadyState([out, retval] long* pVal); [id(0x0000007c), propget, helpstring("property TotalFrames")] HRESULT TotalFrames([out, retval] long* pVal); [id(0x0000007d), propget, helpstring("property Playing")] HRESULT Playing([out, retval] VARIANT_BOOL* pVal); [id(0x0000007d), propput, helpstring("property Playing")] HRESULT Playing([in] VARIANT_BOOL pVal); …… [id(0x0000009f), propget, helpstring("property SWRemote")] HRESULT SWRemote([out, retval] BSTR* pVal); [id(0x0000009f), propput, helpstring("property SWRemote")] HRESULT SWRemote([in] BSTR pVal); [id(0x000000aa), propget, helpstring("property FlashVars")] HRESULT FlashVars([out, retval] BSTR* pVal); [id(0x000000aa), propput, helpstring("property FlashVars")] HRESULT FlashVars([in] BSTR pVal); [id(0x000000ab), propget, helpstring("property AllowScriptAccess")] HRESULT AllowScriptAccess([out, retval] BSTR* pVal); [id(0x000000ab), propput, helpstring("property AllowScriptAccess")] HRESULT AllowScriptAccess([in] BSTR pVal); [id(0x000000be), propget, helpstring("property MovieData")] HRESULT MovieData([out, retval] BSTR* pVal); [id(0x000000be), propput, helpstring("property MovieData")] HRESULT MovieData([in] BSTR pVal); [id(0x000000bf), propget, helpstring("property inline-data")] HRESULT InlineData([out, retval] IUnknown** ppIUnknown); [id(0x000000bf), propput, helpstring("property inline-data")] HRESULT InlineData([in] IUnknown* ppIUnknown); [id(0x000000c0), propget, helpstring("property SeamlessTabbing")] HRESULT SeamlessTabbing([out, retval] VARIANT_BOOL* pVal); [id(0x000000c0), propput, helpstring("property SeamlessTabbing")] HRESULT SeamlessTabbing([in] VARIANT_BOOL pVal); [id(0x000000c1), helpstring("method EnforceLocalSecurity")] HRESULT EnforceLocalSecurity(); [id(0x000000c2), propget, helpstring("property Profile")] HRESULT Profile([out, retval] VARIANT_BOOL* pVal); [id(0x000000c2), propput, helpstring("property Profile")] HRESULT Profile([in] VARIANT_BOOL pVal); [id(0x000000c3), propget, helpstring("property ProfileAddress")] HRESULT ProfileAddress([out, retval] BSTR* pVal); [id(0x000000c3), propput, helpstring("property ProfileAddress")] HRESULT ProfileAddress([in] BSTR pVal); [id(0x000000c4), propget, helpstring("property ProfilePort")] HRESULT ProfilePort([out, retval] long* pVal); [id(0x000000c4), propput, helpstring("property ProfilePort")] HRESULT ProfilePort([in] long pVal); [id(0x000000c6), helpstring("method Call")] HRESULT CallFunction( [in] BSTR request, [out, retval] BSTR* response); [id(0x000000c7), helpstring("method SetReturnValue")] HRESULT SetReturnValue([in] BSTR returnValue); [id(0x000000c8), helpstring("method DisableLocalSecurity")] HRESULT DisableLocalSecurity(); }; 也就是说存在三个版本:
1)我机子上的flash.ocx
2)你机子上的flash.ocx
3)我机子上的Flash8.ocx


2)比1)多出来了:

 

[id(0x000000be), propget, helpstring("property MovieData")] HRESULT MovieData([out, retval] BSTR* pVal); [id(0x000000be), propput, helpstring("property MovieData")] HRESULT MovieData([in] BSTR pVal); [id(0x000000bf), propget, helpstring("property inline-data")] HRESULT InlineData([out, retval] IUnknown** ppIUnknown); [id(0x000000bf), propput, helpstring("property inline-data")] HRESULT InlineData([in] IUnknown* ppIUnknown); [id(0x000000c0), propget, helpstring("property SeamlessTabbing")] HRESULT SeamlessTabbing([out, retval] VARIANT_BOOL* pVal); [id(0x000000c0), propput, helpstring("property SeamlessTabbing")] HRESULT SeamlessTabbing([in] VARIANT_BOOL pVal);

3)比2)多出来了:

[id(0x000000c1), helpstring("method EnforceLocalSecurity")] HRESULT EnforceLocalSecurity(); [id(0x000000c2), propget, helpstring("property Profile")] HRESULT Profile([out, retval] VARIANT_BOOL* pVal); [id(0x000000c2), propput, helpstring("property Profile")] HRESULT Profile([in] VARIANT_BOOL pVal); [id(0x000000c3), propget, helpstring("property ProfileAddress")] HRESULT ProfileAddress([out, retval] BSTR* pVal); [id(0x000000c3), propput, helpstring("property ProfileAddress")] HRESULT ProfileAddress([in] BSTR pVal); [id(0x000000c4), propget, helpstring("property ProfilePort")] HRESULT ProfilePort([out, retval] long* pVal); [id(0x000000c4), propput, helpstring("property ProfilePort")] HRESULT ProfilePort([in] long pVal); [id(0x000000c6), helpstring("method Call")] HRESULT CallFunction( [in] BSTR request, [out, retval] BSTR* response); [id(0x000000c7), helpstring("method SetReturnValue")] HRESULT SetReturnValue([in] BSTR returnValue); [id(0x000000c8), helpstring("method DisableLocalSecurity")] HRESULT DisableLocalSecurity();

既然micromedia不遵守游戏规则,就不玩vtable了,不过根据种种迹象看来,micromedia公司对这种结果好象是有意为之.

Option Explicit Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Const WM_USER = &H400 Private Const EM_GETOLEINTERFACE = (WM_USER + 60) Public Enum reCharPos reSelection = -1 End Enum Public Enum reObjectAspect reObjectAspectContent = DVASPECT_CONTENT reObjectAspectIcon = DVASPECT_ICON End Enum Public Function AddClass(hWnd As Long, ObjIUnknown As stdole.IUnknown, _ Optional ByVal CharPos As Long = reSelection, _ Optional ByVal InitialAspect As reObjectAspect = reObjectAspectContent) As OleObject Dim OleObject As olelib.IOleObject Dim Storage As olelib.IStorage Dim ClientSite As olelib.IOleClientSite Dim VMSG As olelib.MSG Dim tRECT As olelib.RECT Dim tOUIIO As olelib.OLEUIINSERTOBJECT Dim REOBJ As olelib.REOBJECT Dim CLSID As olelib.UUID Dim hMFPict As Long Dim RichEditOle As IRichEditOle SendMessage hWnd, EM_GETOLEINTERFACE, 0&, RichEditOle Set ClientSite = RichEditOle.GetClientSite Set Storage = StgCreateDocfile(vbNullString, STGM_CREATE Or STGM_READWRITE Or STGM_DELETEONRELEASE Or STGM_SHARE_EXCLUSIVE) Set OleObject = ObjIUnknown OleObject.GetUserClassID CLSID On Error Resume Next If hMFPict = 0 Then hMFPict = OleGetIconOfClass(CLSID, vbNullString, 1) If Err.Number <> 0 Then InitialAspect = reObjectAspectContent On Error GoTo 0 OleSetContainedObject ObjIUnknown, 1 With REOBJ .cbStruct = Len(REOBJ) LSet .CLSID = CLSID .DVASPECT = InitialAspect .cp = CharPos .dwFlags = REO_DYNAMICSIZE Or REO_RESIZABLE Set .pStg = Storage Set .polesite = ClientSite Set .poleobj = ObjIUnknown End With RichEditOle.InsertObject REOBJ Set OleObject = Nothing Set ClientSite = Nothing Set Storage = Nothing SendMessage hWnd, &HF, 0, 0 End Function可以实现我上面说的功能,但是好像刷新有问题。
SendMessage hWnd, &HF, 0, 0 仅对动态GIF起作用,对wmp和flash无效。

 

刷新的问题可以这样:

public void UpdateObjects() { int k = this.IRichEditOle.GetObjectCount(); for (int i = 0; i < k; i++) { REOBJECT reoObject = new REOBJECT(); this.IRichEditOle.GetObject(i, reoObject, GETOBJECTOPTIONS.REO_GETOBJ_ALL_INTERFACES); if (reoObject.dwUser == 1) { Point pt = this._richEdit.GetPositionFromCharIndex(reoObject.cp); Rectangle rect = new Rectangle(pt, reoObject.sizel); this._richEdit.Invalidate(rect, false); // repaint } } }

者QueryInterface flash控件的IViewObjectEx接口,然后调用IViewObjectEx接口的draw方法实现自绘
dim mIViewObject as IViewObject
set mIViewObject=ObjIUnknown

如果不报错的话,说明QI成功,然后就可以调用draw方法

我明白为什么“只有一个Flash控件在刷新”了

这与OLE的设计有关

在位激活(inplace activate)是指:
当点击嵌入的对象时,宿主程序将控制权交给嵌入对象,激活嵌入对象
而嵌入对象没有激活时,宿主程序只维持该嵌入对象的静态图像

解决方法:按楼上的方法手动刷新RichEdit中的所有OLE对象

首先在窗体上画一个richtextbox控件,一个flash控件(这个flash控件没有用上,它是为程序中动态添加flash控件做准备的,事实上这是一种无奈的做法,原因是Licenses.Add方法对flash的progid不感兴趣,当然,你也可以通过其它途径解决这个问题),一个timer控件,一个按钮:

Option Explicit Private Const RDW_ERASE = &H4 Private Const RDW_FRAME = &H400 Private Const RDW_INTERNALPAINT = &H2 Private Const RDW_INVALIDATE = &H1 Private Const RDW_ERASENOW = &H200 Private Const RDW_ALLCHILDREN = &H80 Private Const WM_USER = &H400 Private Const EM_GETOLEINTERFACE = WM_USER + 60 Private Const EM_POSFROMCHAR = (WM_USER + 38) Private Const WM_LBUTTONDBLCLK = &H203 Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT, ByVal bErase As Long) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Sub ZeroMemory Lib "KERNEL32" Alias "RtlZeroMemory" (dest As Any, ByVal numBytes As Long) Private Declare Function RedrawWindow Lib "user32" (ByVal hwnd As Long, lprcUpdate As Any, ByVal hrgnUpdate As Long, ByVal fuRedraw As Long) As Long Private Declare Function IIDFromString Lib "ole32" (ByVal lpszIID As Long, iid As Any) As Long Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long Private Declare Function CoCreateGuid Lib "ole32.dll" (lpGUID As Any) As Long Private Declare Function StringFromGUID2 Lib "ole32" (lpGUID As Any, ByVal lpStr As String, ByVal lSize As Long) As Long Const ProgID_Flash = "ShockwaveFlash.ShockwaveFlash.1" Dim mIRichEditOle As IRichEditOle '实现这个函数的目的是为了产生不重复的字串,为controls.add服务 Private Function GetGuidID() As String Dim pGuid(16) As Byte Dim s As String s = String(255, " ") CoCreateGuid pGuid(0) StringFromGUID2 pGuid(0), s, 255 s = Trim(s) s = StrConv(s, vbFromUnicode) s = Replace(s, "{", "") s = Replace(s, "}", "") s = Replace(s, "-", "") GetGuidID = s End Function Private Sub Command1_Click() RichTextBoxInsertFlash RichTextBox1.hwnd, "e:/MC/11.SWF" End Sub '在richtextbox的当前光标处插入flash,flash的movie为mFile Private Sub RichTextBoxInsertFlash(ByVal mHwnd As Long, ByVal mFile As String) Dim mILockBytes As ILockBytes Dim mIStorage As IStorage Dim mIOleClientSite As IOleClientSite Dim mIOleObject As IOleObject Dim mReObject As REOBJECT Dim mUUID As UUID '创建Global Heap,实例化mILockBytes Set mILockBytes = CreateILockBytesOnHGlobal(0&, True) If ObjPtr(mILockBytes) = 0 Then MsgBox "Error to create Global Heap" Exit Sub End If '创建storage,实例化mIStorage Set mIStorage = StgCreateDocfileOnILockBytes(mILockBytes, STGM_SHARE_EXCLUSIVE _ Or STGM_CREATE Or STGM_READWRITE, 0) If ObjPtr(mIStorage) = 0 Then MsgBox "Error to create storage" Exit Sub End If '向richtextbox发送EM_GETOLEINTERFACE消息获得IRichEditOle接口,实例化mIRichEditOle SendMessage mHwnd, EM_GETOLEINTERFACE, 0, mIRichEditOle If ObjPtr(mIRichEditOle) = 0 Then MsgBox "Error to get IRichEditOle" Exit Sub End If '调用GetClientSite函数,实例化mIOleClientSite Set mIOleClientSite = mIRichEditOle.GetClientSite If ObjPtr(mIOleClientSite) = 0 Then MsgBox "Error to get ClientSite" Exit Sub End If '动态添加flash控件,用于解决插入多个影片的问题 Dim mFlash As ShockwaveFlashObjectsCtl.ShockwaveFlash Set mFlash = Controls.Add(ProgID_Flash, "mc" + GetGuidID) mFlash.Movie = mFile '查询IOleObject接口 Set mIOleObject = mFlash.Object OleSetContainedObject mIOleObject, True mIOleObject.GetUserClassID mUUID '填充mReObject With mReObject .cbStruct = LenB(mReObject) .clsid = mUUID .cp = REO_CP_SELECTION .DVASPECT = DVASPECT_CONTENT .dwFlags = REO_BELOWBASELINE ' Or REO_RESIZABLE .sizel.cx = 0 .sizel.cy = 0 .dwUser = 0 Set .poleobj = mIOleObject Set .polesite = mIOleClientSite Set .pStg = mIStorage End With '在richtextbox的当前光标处插入flash mIRichEditOle.InsertObject mReObject ' '释放资源 ZeroMemory mReObject, LenB(mReObject) ZeroMemory mUUID, LenB(mUUID) Set mIOleClientSite = Nothing Set mIStorage = Nothing Set mILockBytes = Nothing Set mIOleObject = Nothing End Sub Private Sub UpdateObjects() Dim i As Long, RE As REOBJECT If ObjPtr(mIRichEditOle) = 0 Then Exit Sub i = mIRichEditOle.GetObjectCount Dim PT As olelib.Point Dim k As Long, mSIZE As SIZE, RT As RECT For k = 0 To i - 1 RE.cbStruct = LenB(RE) mIRichEditOle.GetObject k, RE, REO_GETOBJ_ALL_INTERFACES SendMessage RichTextBox1.hwnd, EM_POSFROMCHAR, VarPtr(PT), ByVal RE.cp mSIZE = RE.sizel With RT .Left = PT.x .Top = PT.y .Right = mSIZE.cx * 192 / 5080 + PT.x .Bottom = PT.y + mSIZE.cy * 192 / 5080 End With InvalidateRect Me.RichTextBox1.hwnd, RT, False Next End Sub Private Sub Form_Load() Timer1.Interval = 80 '数值越小,闪烁的越厉害 Timer1.Enabled = True End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Dim obj As Object For Each obj In Me.Controls If TypeName(obj) = "shockwaveflash" And Left(obj.Name, 2) = "mc" Then Controls.Remove obj End If Next Set mIRichEditOle = Nothing RichTextBox1.TextRTF = "" '关键代码,释放richtextbox占用的资源,否则程序不能正确退出 End Sub Private Sub Form_Resize() RichTextBox1.Move 0, 0, Me.ScaleWidth End Sub Private Sub Timer1_Timer() UpdateObjects End Sub 目前存在的问题,刷新的时候闪烁的很厉害

 

http://blog.csdn.net/rainstormmaster/archive/2006/02/09/595210.aspx

估计flash是故意不面向桌面程序的……插入对象需要容器和控件都支持一系列特定的接口


在mfc activex控件中怎么得到网页中的参数? (VC/MFC ATL/ActiveX/COM )


参数是网页中的类似 <PARAM NAME...... 格式的


通过IPropertyBag等接口。不过用MFC的话,重载DoPropExchange就可以了


vc++ 使用oracle ole db访问oracle stored procedure (Oracle 开发)


schemaRS = adoConnection->OpenSchema (adSchemaProcedureParameters, vtCriteria);
发现返回的schemaRs的size=4(按照道理似乎应该是1) adoCommand->CommandText应该写怎样的sql语句来执行它。


http://www.oracle.com/technology/sample_code/tech/windows/ole_db/oledb8/index.html


如何向超星阅读器那样可以获取IE中选中或全部的内容(图文混合),然后可以像FrontPage一样可以编辑? (VB 基础类 )


 

Private Sub GetElementUnderInsertionPoint() Dim rg As IHTMLTxtRange Dim ctlRg As IHTMLControlRange ' branch on the type of selection and ' get the element under the caret or the site selected object ' print its outerHTML Select Case DHTMLEdit1.DOM.selection.Type Case "None", "Text" Set rg = DHTMLEdit1.DOM.selection.createRange ' collapse the range so that the scope of the ' range of the selection is the caret. That way the ' parentElement method will return the element directly ' under the caret. If you don't want to change the state of the ' selection, then duplicate the range and collapse it rg.collapse MsgBox rg.parentElement.outerHTML Case "Control" ' an element is site selected Set ctlRg = DHTMLEdit1.DOM.selection.createRange ' there can only be one site selected element at a time so the ' commonParentElement will return the site selected element MsgBox ctlRg.commonParentElement.outerHTML End Select End Sub

 


 

CFileDialog的记忆路径如何在选择文件前得到(VC/MFC 界面 )


CFileDialog每次选文件后路径都会记忆下来,下次再调用,会缺省在该目录下,怎么得到这个这个目录(当然不能选择文件,然后再计算).
问题的由来:
我的程序有两个地方调用CFileDialog,它们的路径不同(都不在程序文件夹,GetCrrentDirectory()不能使),设两个位置为A和B,一般情况都使用B,偶尔会使用A,我想在调用A时,先把B的路径保存起来,在A完后再恢复,现在的问题就是如何取得B的目录.(用一个变量在没次调B时都记一下有点蠢)


http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/userinput/commondialogboxlibrary/commondialogboxreference/commondialogboxstructures/openfilename.asp

lpstrInitialDir


如何设置当前输入法?(.NET技术 C# )


 

[DllImport("imm32.dll")] public static extern int ImmGetContext(int hWnd); [DllImport("imm32.dll")] public static extern int ImmReleaseContext(int hWnd,int hIMC); [DllImport("imm32.dll")] public static extern int ImmSetOpenStatus(int hIMC,int fOpen); private static void imeOnOff(int bOnOff) {int hIMC=ImmGetContext(GetFocus()); if(hIMC!=0) {ImmSetOpenStatus(hIMC,bOnOff); ImmReleaseContext(GetFocus(),hIMC); } }

 


 

warning C4995: 'CDaoDatabase': name was marked as #pragma deprecated(C/C++ C++ 语言 )


.net2002(项目限制), ARX2006, AUTODESK MAP 3D 2006,XP操作系统
现在我们的一个工程需要进行数据库方面的操作,但是加上创建数据库的函数后,编译会出现4个waring,这样将导致CAD加载ARX程序时,不能加载,由于这个是公司保密要求,不能贴出源代码,所以请原谅,现在只能将这四个waring贴出,希望有经验的指点一下:
warning C4995: 'CDaoDatabase': name was marked as #pragma deprecated
warning C4995: 'CDaoTableDef': name was marked as #pragma deprecated
warning C4995: 'CDaoTableDef': name was marked as #pragma deprecated
warning C4995: 'CDaoRecordset': name was marked as #pragma deprecated


#pragma warning(disable : 4995)


请问InstallShield如何做一个多语言选择安装的对话框,其脚本如何写(VC/MFC 非技术类 )


我现在的程序要求支持多语言版本,现在只是装那个语言的把那个动态库(资源库)一起打包到相应的语言版本中,这样,给维护造成很的不便。请问能否把所有资源放在一起,由用户安装时选择安装那个语言


http://blog.joycode.com/hopeq/archive/2004/07/26/28460.aspx


能不能用asp.net调用vc++编译好的exe文件(VC/MFC 基础类 )


http://msdn2.microsoft.com/en-us/library/0w4h05yb.aspx

ASP.NET Web page and server control code executes in the context of the ASP.NET worker process on the Web server. If you use the Start method in an ASP.NET Web page or server control, the new process executes on the Web server with restricted permissions. The process does not start in the same context as the client browser, and does not have access to the user desktop.


怎样给已连接的某个特定客户开一个共享目录(VC/MFC 网络编程)


http://msdn.microsoft.com/library/en-us/netmgmt/netmgmt/netshareadd_sample_windows_95_98_me_.asp

NT always uses user-level security. shi2_permissions structure member will
be ignored on a server running user-level security. To setup a share that
allows Everyone only "Read" access, you have to setup a security descriptor
with level 502 and set shi502_security_descriptor structure member with a
security descriptor that allows Everyone only read access.

try { //initialize the SecurityDescriptor--------------------------------------------- SECURITY_DESCRIPTOR sd; PACL pDacl = NULL; DWORD dwAclSize ; PSID pSid = NULL; DWORD cbSid; TCHAR RefDomain[DNLEN + 1]; DWORD cchDomain = DNLEN + 1; SID_NAME_USE peUse; cbSid = 96; pSid = (PSID)HeapAlloc(GetProcessHeap(), 0, cbSid); if(pSid == NULL) Memo1->Lines->Add("HeapAlloc error!"); String Username = "Everyone"; //or any other existing username in your system... wchar_t* userbuf = new wchar_t[(Username.Length() + 1)]; Username.WideChar(userbuf, Username.WideCharBufSize()); if(!LookupAccountName(NULL, userbuf, pSid, &cbSid, RefDomain, &cchDomain, &peUse )) { if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) // try again { pSid = (PSID)HeapReAlloc(GetProcessHeap(), 0, pSid, cbSid); if(pSid == NULL) Memo1->Lines->Add("HeapReAlloc error!"); cchDomain = DNLEN + 1; if(!LookupAccountName(NULL, userbuf, pSid, &cbSid, RefDomain, &cchDomain, &peUse)) { wchar_t* lpMsgBuf = new wchar_t[100]; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (wchar_t *) &lpMsgBuf, 0, NULL); Memo1->Lines->Add("LookupAccountName error! " + AnsiString(lpMsgBuf)); delete lpMsgBuf; } } else { wchar_t* lpMsgBuf = new wchar_t[100]; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (wchar_t *) &lpMsgBuf, 0, NULL); Memo1->Lines->Add("LookupAccountName error! " + AnsiString(lpMsgBuf)); delete lpMsgBuf; } } delete userbuf; } dwAclSize = sizeof(ACL) + 1 * ( sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) GetLengthSid(pSid); pDacl = (PACL)HeapAlloc(GetProcessHeap(), 0, dwAclSize); if(pDacl == NULL) return; InitializeAcl(pDacl, dwAclSize, ACL_REVISION); AddAccessAllowedAce(pDacl,ACL_REVISION, GENERIC_READ | ACCESS_ATRIB, pSid]); //use both GENERIC_READ and ACCESS_ATRIB or else windows won't recognize the share as read only... InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION) ; SetSecurityDescriptorDacl(&sd, TRUE, pDacl, FALSE); //Initialize all other share variables----------------- temp.shi502_security_descriptor = &sd; // Add the shares----------------- }

 


 

CListCtrl中的CCheckBox问题(VC/MFC 界面 )



我在CListCtrl中添加了CCheckBox,现在想选中某一行的Checkbox的同时,将该行的数据立刻添加到数据库中,取消选中时,将该行数据立刻从数据库中删除。这个功能需要在CListCtrl的那个事件中实现,如何判断我点击的时那一行对应的checkbox


 

void CTestForm::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) { NMITEMACTIVATE* pActivate = (NMITEMACTIVATE*)pNMHDR ; LVHITTESTINFO oInfo ; oInfo.pt = pActivate->ptAction ; m_List.HitTest(&oInfo) ; if(oInfo.flags == LVHT_ONITEMSTATEICON) AfxMessageBox("State") ; *pResult = 0; } void CCBTestDlg::OnKeydownList1(NMHDR* pNMHDR, LRESULT* pResult) { LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR; // please insert code here... if(pLVKeyDow->wVKey == VK_SPACE) AfxMessageBox("State") ; *pResult = 0; }

如何隐藏当前打开ie网页窗口 (VB 基础类 )


http://www.codeproject.com/shell/AutomateShellWindow.asp

http://blog.joycode.com/jiangsheng/archive/2005/10/20/65489.aspx


IE控件右边的Scroll问题(VC/MFC ATL/ActiveX/COM )


我在程序中用了一个IE控件用于显示Html格式的数据,显示通过IHTMLDocument2的IPersistStreamInit接口的Load方法实现。为了能取得IHTMLDocument2,在程序初始化时,我会调用Navigate2("about:blank", ...)来初始化IE的文档对象,这时麻烦来了,右边会出现一个灰掉的ScrollBar,我想不让这个灰掉的ScrollBar显示出来(只有当ScrollBar有效时才显示),


http://support.microsoft.com/kb/324419


ActiveX在网页中显示的问题(VC/MFC ATL/ActiveX/COM )


自己写的ActiveX控件,使用,<OBJECT CLASSID==''>时,显示正常.

使用Javascript:
new ActiveXObject(ProgID),控件方法可以执行,但是不能显示控件.


 

var myObjectElement = document.createElement('<object id="elementid" classid="clsid:098F2470-BAE0-11CD-B579-08002B30BFEB"></object>'); var myParamElement1 = document.createElement('<PARAM NAME=movie value="example.avi">'); var myParamElement2 = document.createElement('<Param name=quality value=high>'); var myParamElement3 = document.createElement('<Param name=bgcolor value=#FFFFFF>'); myObjectElement.appendChild(myParamElement1); myObjectElement.appendChild(myParamElement2); myObjectElement.appendChild(myParamElement3); embedControlLocation.appendChild(myObjectElement);

 


 

在ClistCtrl中用鼠标框选多行的事件是什么?(就像在资源管理器中点左键或右键拖动鼠标,选中多行) (VC/MFC 基础类 )


LVN_MARQUEEBEGIN


怎样得到构成一个函数的所有指令所占内存的大小(VC/MFC 硬件/系统)


举例说明:

int __stdcall Addup(int n) { int sum = 0; int i = n; for(i = n; i >= 0; i--) { sum += i; } return sum; } void *p = Addup;


现在我想知道从“p”开始,在这以后多少字节是函数“Addup”的指令,怎样知道这部分内存的大小


把Addup函数声明为static的,紧接其后再声明一个static的函数,名字自定,这个函数体为空即可。然后用后面的函数名减去前面的函数名,即地址相关,就可得前面函数所占的代码空间。
http://blog.csdn.net/jiangsheng/archive/2003/11/09/3789.aspx


如果在一个线程中,让线程休眠,结果会怎样呢?(VC/MFC 进程/线程/DLL )


如果有与休眠并行的操作,比如下面程序中对ret赋值,那么这个并行的操作在什么时候被执行呢?而且,执行SuspendThread后,线程是立刻进入休眠的么?

如果这么做(在线程内休眠自己,在线程外重新启动),有没有什么副作用?

谢谢各位。

#include <windows.h> #include <iostream> using std::cin; using std::cout; using std::endl; DWORD ret = -1; HANDLE threadHandle = 0; DWORD WINAPI ThreadProc(LPVOID lpParam) { ::Sleep(500); cout<<"123"<<endl; DWORD ret = ::SuspendThread(threadHandle);//程序运行到这里时,会休眠自己,那么ret会在什么时候被赋值呢?休眠前还是休眠后?为什么? while(1) cout<<"abc"<<endl; return 0; } int _tmain(int argc, _TCHAR* argv[]) { DWORD a; threadHandle = ::CreateThread(NULL, 0, ThreadProc, 0, 0, &a); ::Sleep(1000); ::Sleep(1000); a = ::ResumeThread(threadHandle); ::Sleep(1000); return 0; }

 


 

SuspendThread在休眠后才返回。你看看汇编码就知道了
Calling SuspendThread on a thread that owns a synchronization object, such as a mutex or critical section, can lead to a deadlock if the calling thread tries to obtain a synchronization object owned by a suspended thread. To avoid this situation, a thread within an application that is not a debugger should signal the other thread to suspend itself.
如果没有同步对象的存在,是不是这样就是安全的?

还有个问题,线程池一般是如何实现的?我的想法是起一系列的休眠线程,然后在需要用到时替换内部的运行函数,这个函数运行完后,线程将设标志位标志回收,并自己休眠自己,不知道这样是否可行

1 hard to say. deadlock can occur in other conditional waitings
2 http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/vcsample/html/vcsamCThreadPoolSample.asp


CppWebBrowser的Fresh与重复Navigate同一网址有啥区别(CppWebBrowser的Fresh与重复Navigate同一网址有啥区别)


Fresh can repost all form data.


点击网页中控键怎么与后台mfc程序交互(VC/MFC HTML/XML)


http://www.codeguru.com/cpp/i-n/ieprogram/article.php/c4399/
http://msdn.microsoft.com/workshop/browser/mshtml/tutorials/sink.asp
http://www.codeproject.com/miscctrl/luo31.asp
http://www.codeproject.com/shell/dlgdhtmlevents.asp


突然发现VS2005 的 devenv.exe 是在 Common7 目录下(.NET技术 C#)


既然 VS2005 号称 8.0,那么应当是在Common8 目录下才对的啊


It's a long story. I don't know all the gory details, but I understand the problem is due to some component authoring decisions made in the VS 2002 timeframe. Not because of backwards compatibility, but for side-by-side correctness, we're stuck with them now.

--Paul Harrington, Visual Studio Platform Team, Microsoft


如何在windows media player里控制伴唱,原唱 (专题开发/技术/项目 多媒体/流媒体开发 )


First, enable multichannel support (http://www.microsoft.com/windowsxp/using/windowsmediaplayer/expert/bridgman_03january07.mspx)

Second, set the player.settings.balance property. The value zero indicates that the audio plays at equal volume on both left and right channels. A value of –100 indicates that audio plays only on the left channel. A value of 100 indicates that audio plays only on the right channel.

Reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmplay10/mmp_sdk/settingsobject.asp


编程实现WMV/ASF文件用MMS或HTTP协议通过一个端口发送出去 (专题开发/技术/项目 多媒体/流媒体开发)


我想实现对WMV/ASF本地文件的广播,能编程实现吗


可以编程控制Windows Media Encoder(IWMEncPushDistribution ),或者自己用Windows Media Format的IWMWriterNetworkSink 接口创建一个本地点播点

http://msdn.microsoft.com/windowsmedia/downloads/default.aspx 下SDK

http://msdn.microsoft.com/library/en-us/wmform95/htm/sampleapplications.asp

The following samples are installed by default in C:/WMSDK/WMFSDK9/samples. The samples will not work unless the Windows Media Format SDK has been installed.

......
WMVNetWrite This console application shows how a Windows Media file is streamed across the Internet. The sample requires a port to be specified, and then the file can be played using a player.
 


如何通过IHTMLDocument2接口获取网页中的meta信息(VC/MFC HTML/XML )


 

HRESULT TBaseWebBrowserPageletCtrl::GetMetaCollection(IHTMLElementCollection** pCollec, IHTMLDocument2* pDocument) { CComPtr <IDispatch > lDispatch; CComQIPtr <IHTMLDocument2 > lDocument; HRESULT lResult; if (pDocument == NULL) { if (!m_BrowserTree) return E_FAIL; lResult = m_BrowserTree- >get_Document(&lDispatch); lDocument = lDispatch; lDispatch = NULL; ASSERT(SUCCEEDED(lResult) && lDocument); if (FAILED(lResult) ¦ ¦ (lDocument == NULL)) return E_FAIL; } else { lDocument = pDocument; } CComPtr <IHTMLElementCollection > lCollec; lResult = lDocument- >get_all(&lCollec); ASSERT(SUCCEEDED(lResult) && lCollec); if (FAILED(lResult) ¦ ¦ (lCollec == NULL)) return E_FAIL; lResult = lCollec- >tags(CComVariant( "META "), &lDispatch); return lDispatch- >QueryInterface(pCollec); } HRESULT TBaseWebBrowserPageletCtrl::CheckMetaTags() { CComQIPtr <IHTMLElementCollection > lCollec; CComQIPtr <IHTMLMetaElement > lMetaElement; CComPtr <IDispatch > lDispatch; HRESULT lResult; long lIndex = 0; long lLength = 1; lResult = GetMetaCollection(&lCollec); if (SUCCEEDED(lResult) && lCollec) { lResult = lCollec- >get_length(&lLength); ASSERT(SUCCEEDED(lResult)); } while (lIndex < lLength) { if (lCollec) { lResult = lCollec- >item(CComVariant(lIndex), CComVariant(), &lDispatch); lMetaElement = lDispatch; lDispatch = NULL; ASSERT(SUCCEEDED(lResult) && lMetaElement); } if (SUCCEEDED(lResult) && lMetaElement) { // CComBSTR lName; lResult = lMetaElement- >get_name(&lName); if (SUCCEEDED(lResult) && lName && (!wcsicmp(CComBSTR(KEEBOO_PRODUCT_NAME), lName) ¦ ¦ !wcsicmp(CComBSTR(KEEBOO_COMPANY), lName))) { CComBSTR lMetaContent; lResult = lMetaElement- >get_content(&lMetaContent); if (SUCCEEDED(lResult) && lMetaContent) { if (!wcsicmp(L "no-stretch ", lMetaContent)) { m_bNoStretch = TRUE; } else if (!wcsicmp(L "no-cache ", lMetaContent)) { CComQIPtr <IPageletSink > lPageletSink(m_pControlSite); if (lPageletSink) { CComObject <TDeleteCacheEntryCallback >* lCallback; CComQIPtr <IPageletDestroyCallback > lCBInterface; CComObject <TDeleteCacheEntryCallback >::CreateInstance(&lCallback); lCallback- >SetPage(getModel()); lCBInterface = lCallback; lPageletSink- >SetDestroyCallback(lCallback); } } else { TModelPtr <TPropertyObjectModel > lProp; TModelPtr <TContentModel > lContentModel; if (!wcsicmp(L "online-reload ", lMetaContent)) { getModel()- >getContent(&lContentModel); GetModelProperty <TContentModel >(lContentModel, T_CONTENT_NETWORK_PROPERTIES, &lProp, TRUE); ASSERT(lProp); if (lProp) lProp- >putBooleanField( "online-reload ", true); } else if (!wcsicmp(L "online-flush ", lMetaContent)) { getModel()- >getContent(&lContentModel); GetModelProperty <TContentModel >(lContentModel, T_CONTENT_NETWORK_PROPERTIES, &lProp, TRUE); ASSERT(lProp); if (lProp) lProp- >putBooleanField( "online-flush ", true); } } } } } lIndex++; } return S_OK; }

 


 

WebBrowser1的问题(VB 基础类)


用WebBrowser1来浏览硬盘上的文件列表,可是,双击文件夹就会打开新窗口,如何让它在当前窗口下打开文件夹


浏览器控件显示文件夹视图(例如本地目录或者FTP站点)时在其中双击目录,选中的目录会用新的资源管理器窗口打开的问题,是因为浏览器控件中的文件夹视图在打开文件夹的时候并不触发浏览器的NewWindow2事件,而是调用ShellExecuteEx,用DDE的方式和Shell通讯。微软知识库文章Q189634 WebApp.exe Enables User to Move WebBrowser Ctrl(http://support.microsoft.com?kbid=189634 )描述了如何处理这样的DDE会话。


怎么让一个窗体在点“X”的时候是隐藏,而不是关闭?(.NET技术 C# )



 

this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing); private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { // Hide the form... this.Hide(); // Cancel the close... e.Cancel = true; }

必须判断用户是不是要关闭整个程序,否则子窗口永远不关闭,程序就没办法正常退出。


CTreeCtrl 如何用SetItemData使Item保持额外数据? (VC/MFC 界面 )


You should not delete the item data when it is being used by an item;
handle TVN_DELETEITEM to delete the itemdata when it is no longer used.

BTW, you need to reconsider if you need a tree control at all. Tree control sends several messages for each item. Destroying 40,000 items entails 40,000 TVN_DELETEITEM notifications. Just by sheer numbers that's going to take a while. 40,000 items in a treeview is unusably excessive.

Suggest reading:
http://www.codeproject.com/treectrl/waitingtreectrl.asp


问个MFC中document/view结构的问题(VC/MFC 基础类)


CDocTemplate管理document、view、frame,对吧?我现在想创建一种新的文件类型,用自己的程序打开,但这中文件中,记录的只是一些有用的信息,不需要view 和frame窗口,就有点儿象 dsw文件那样。这种情况要怎么实现?也就是说实现的document 不绑定view 和frame。


It is much easier to edit the registry directly. See http://support.microsoft.com/kb/257592/  and http://msdn.microsoft.com/msdnmag/issues/1100/c/default.aspx

To implement custom registration code using MFC classes you needed to override CDocManager::RegisterShellFileTypes().

Unregistration is a bit more complicated, because the corresponding functions in CWinApp and CDocManager were not declared virtual. Therefore, you needed to implement the correct code in an override of CDocManager::UnregisterShellFileTypes(), and copy and paste the code from CWinApp::UnregisterShellFileTypes() and CWinApp::ProcessShellCommand() in our own CWinApp-derived class.

To implement file operations transparently, you overrode CDocManager::DoPromptFileName() and CDocManager::OpenDocumentFile(). To minimize the number of changes, the global function MatchDocType() has been defined to replace the use of CDocTemplate::MatchDocType() member function. The new function behaves as expected when multiple extensions are provided for one document template.

reference:
http://www.codeproject.com/shell/cgfiletype.asp


如何用activex关闭网页(VC/MFC ATL/ActiveX/COM )


call window.close from the activex
see
How To Retrieve the Top-Level IWebBrowser2 Interface from an ActiveX Control
http://support.microsoft.com/kb/257717
INFO: Accessing the Object Model from Within an ActiveX Control
http://support.microsoft.com/kb/172763

0
0

猜你在找
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:705180次
    • 积分:7463
    • 等级:
    • 排名:第3229名
    • 原创:108篇
    • 转载:3篇
    • 译文:0篇
    • 评论:334条
    最新评论
    Google Profile
    知识的泉源