Jiangsheng的CSDN Digest(March 4, 2006)

爲了便於搜索,這裏儘可能保留了論壇上討論的原文,但是這並不表示本人贊同帖子中的表述方式和觀點。

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章