天天看点

实用!超强VC/MFC 常见问答收集

自编浏览器进入一个网页后,点一个链接后系统自动调用用IE打开网页而不是用自身浏览器打开网页。如何让窗口用我自己的浏览器打开?

答:

控制新的窗口

默认情况下,浏览器收到创建新窗口请求时,会在IE中打开新的窗口。你可以处理NewWindow2事件来在自己指定的窗口中打开请求的页面。

问:

如何枚举系统中视频捕获设备(摄像头)的设备名称

答:

以下代码来 自DirectX9 SDK中的AMCAP示例

// put all installed video and audio devices in the menus

//

void AddDevicesToMenu()

{

……

// enumerate all video capture devices

ICreateDevEnum *pCreateDevEnum=0;

hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,

IID_ICreateDevEnum, (void**)&pCreateDevEnum);

if(hr != NOERROR)

{

ErrMsg(TEXT("Error Creating Device Enumerator"));

return;

}

IEnumMoniker *pEm=0;

hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEm, 0);

if(hr != NOERROR)

{

ErrMsg(TEXT("Sorry, you have no video capture hardware.\r\n\r\n")

TEXT("Video capture will not function properly."));

goto EnumAudio;

}

pEm->Reset();

ULONG cFetched;

IMoniker *pM;

while(hr = pEm->Next(1, &pM, &cFetched), hr==S_OK)

{

IPropertyBag *pBag=0;

hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);

if(SUCCEEDED(hr))

{

VARIANT var;

var.vt = VT_BSTR;

hr = pBag->Read(L"FriendlyName", &var, NULL);

if(hr == NOERROR)

{

AppendMenu(hMenuSub, MF_STRING, MENU_VDEVICE0 + uIndex,

W2T(var.bstrVal));

if(gcap.pmVideo != 0 && (S_OK == gcap.pmVideo->IsEqual(pM)))

bCheck = TRUE;

CheckMenuItem(hMenuSub, MENU_VDEVICE0 + uIndex,

(bCheck ? MF_CHECKED : MF_UNCHECKED));

EnableMenuItem(hMenuSub, MENU_VDEVICE0 + uIndex,

(gcap.fCapturing ? MF_DISABLED : MF_ENABLED));

bCheck = FALSE;

SysFreeString(var.bstrVal);

ASSERT(gcap.rgpmVideoMenu[uIndex] == 0);

gcap.rgpmVideoMenu[uIndex] = pM;

pM->AddRef();

}

pBag->Release();

}

pM->Release();

uIndex++;

}

pEm->Release();

问:

我目前使用 BCG 中的 CBCGPPropList 来实现某一个东西的属性,可是有一项数据特别大,大约500个字符,我希望能把这一项的高度调整可是不知道如何处理,不知道能单独调整其中一项吗

答:从CBCGPProp派生一个函数,重载OnEdit并在其中创建一个需要的大小的编辑框。最后Add自定义的prop类对象。具体实现可以参照CBCGPColorProp和CBCGPFontProp类的实现

问:我想实现一个功能,就是检测一个目录或文件,看它是否存在,如果不存在就创建这个目录或文件。

答:

可以用Win32文件查找来查找文件或者文件夹是否存在,也可以用PathFileExists来判断。GetFileAttributes和PathIsDirectory可以用于判断文件是否是目录。创建文件可以用CreateDirectory或者MakeSureDirectoryPathExists。

bool FileExists(CString FileName)

{

WIN32_FIND_DATA FindFileData;

HANDLE hFind;

bool FindFlag=false;

hFind = FindFirstFile(FileName , &FindFileData);

if (hFind == INVALID_HANDLE_VALUE) {

FindFlag= false;

}

else

{

FindFlag=true;

}

FindClose(hFind);

return FindFlag;

}

DWORD dwFlag = GetFileAttributes(pathname);

if ( 0xFFFFFFFF == dwFlag ) 不存在;

if ( FILE_ATTRIBUTE_DIRECTORY & dwFlag ) 是文件夹

else 是文件

问:

请教一下,html中如果已知Activex的classid,有什么办法可以直接找到它? 通过id来查找比较慢,所以问一下可否通过这种方式?取得IOleObject之后,我需要如何做才可以调用Activex控件中的函数呢?

答:

由于控件所在容器是HTMLDocument对象,你可以用IOleContainer::EnumObjects枚举里面的OLE对象,包括控件和框架

IOleContainer* pContainer;

// Get the container

HRESULT hr = pHtmlDoc2->QueryInterface(IID_IOleContainer,

(void**)&pContainer);

lpDisp->Release();

if (FAILED(hr))

return hr;

IEnumUnknown* pEnumerator;

// Get an enumerator for the frames

hr = pContainer->EnumObjects(OLECONTF_EMBEDDINGS, &pEnumerator);

pContainer->Release();

if (FAILED(hr))

return hr;

IUnknown* pUnk;

ULONG uFetched;

// Enumerate and refresh all the frames

for (UINT i = 0; S_OK == pEnumerator->Next(1, &pUnk, &uFetched); i++)

{

// QI for IOleObject here to see if we have an embedded browser

IOleObject* pOleObject;

hr = pUnk->QueryInterface(IID_IOleObject, (void**)&pOleObject);

pUnk->Release();

if (SUCCEEDED(hr))

{

CLSID clsID;

pOleObject->GetUserClassID(&clsID);

}

}

pEnumerator->Release();

控件的IOleObject接口是用来查询控件的CLSID的。你应该查询控件的IDispatch接口,然后按照http://www.csdn.net/develop/read_article.asp?id=14752里面的方法调用其属性和方法。

问:

已知PIDL怎么得到他对应的IShellFolder指针呢

答:用SHBindtoParent就可以了

IShellFolder *psfParent; //A pointer to the parent folder object's IShellFolder interface

LPITEMIDLIST pidlItem = NULL; //the item's PIDL

LPITEMIDLIST pidlRelative = NULL; //the item's PIDL relative to the parent folder

STRRET str; //the display name's STRRET structure

TCHAR szDisplayName[MAX_PATH]; //the display name's string

HRESULT hres = SHBindToParent(pidlItem, IID_IShellFolder, &psfParent, &pidlRelative);

if(SUCCEEDED(hres))

{

psfParent->GetDisplayNameOf(pidlRelative, SHGDN_NORMAL, &str);

psfParent->Release();

StrRetToBuf(&str, pidlItem, szDisplayName, ARRAYSIZE(szDisplayName));

}

问:如何handle IE的textsize changed event? 我想在用户改变text size 时做些处理,请问该如何handle,在哪个事件中做?谢谢指教。

答:sink HtmlDocument对象的IOleCommandTaget接口。

问: IStream *pStream; CString mString; 怎么样才能把pStream的内容赋给mString呢?

答:下面的代码把一个内存流读到字节数组。你可以根据字符串的类型把字节数组转化成字符串。

COleStreamFile osfRead;

osfRead.Attach(pStream);

long lLength=osfRead.GetLength();

CByteArray baBuf;

baBuf.SetSize(lLength);

osfRead.Read(baBuf.GetData(),lLength);

问:我Create了一个ListControl用来显示文件列表?怎么实现有图标的文件显示阿?

答:SHGetFileInfo可以返回系统图像列表,里面包含每一种文件类型的图标。参见http://www.csdn.net/develop/read_article.asp?id=22243

问题:如何编写无界面的HTML解析器?

答:walkall示例就是一个无界面的HTML解析器。

http://msdn.microsoft.com/downloads/samples/internet/browser/walkall/default.asp

问:用AfxBeginThread创建的线程除了调用AfxEndThread还可以用什么函数关闭?

答:

可以从外部用事件通知来优雅地结束线程

启动线程

m_pThreadWrite=AfxBeginThread(ThreadProc,(LPVOID)this);

线程体。为了避免在静态函数中引用对象指针的麻烦,调用对象参数的线程体成员函数。

UINT CMyClass::ThreadProc(LPVOID lp)

{

CMicrophoneInput* pInput=(CMicrophoneInput*)lp;

return pInput->Run();

}

简单的循环检测退出标志

UINT CMyClass::Run()

{

HRESULT hr;

if(!InitInstance()){

TRACE("InitInstance failed\r\n";

return ExitInstance();

}

while(!IsKilling()){

//do something

}

return ExitInstance();

}

重设退出标志

BOOL CMyClass::InitInstance()

{

m_eventKill.ResetEvent();

m_eventDead.ResetEvent();

//do something

return TRUE

}

设已退出标志

UINT CMyClass::ExitInstance()

{

//do something

m_eventDead.SetEvent();

return 0;

}

检查退出标志

BOOL CMyClass::IsDead()

{

return WaitForSingleObject(m_eventDead,0)==WAIT_OBJECT_0;

}

BOOL CMyClass::IsKilling()

{

return WaitForSingleObject(m_eventKill,0)==WAIT_OBJECT_0;

}

在外部可以这样终止线程

//check if dead

if(!IsDead()&&m_pThreadWrite!=NULL){

m_eventKill.SetEvent();

WaitForSingleObject(m_eventDead,INFINITE);

m_pThreadWrite=NULL;

}

问:怎么实现IEnumString接口?

答:http://www.codeproject.com/wtl/customautocomplete_wtl.asp

IAutoComplete and custom IEnumString implementation for WTL dialogs

下面是我的基于数据库的IEnumString实现

if !defined(AFX_ENUMSTRING_H__4D5D61AD_CD0D_477C_880F_8E5EEB5B1E8F__INCLUDED_)

#define AFX_ENUMSTRING_H__4D5D61AD_CD0D_477C_880F_8E5EEB5B1E8F__INCLUDED_

#if _MSC_VER > 1000

#pragma once

#endif // _MSC_VER > 1000

// EnumString.h : header file

//

//

// CEnumString command target

#include <shldisp.h>

#include "esuihelper.h"

class _ES_UI_EXPORT CEnumString : public IEnumString

{

public:

CEnumString(); // protected constructor used by dynamic creation

// Attributes

public:

ULONG m_nRefCount;

// Operations

public:

STDMETHODIMP_(ULONG) AddRef();

STDMETHODIMP_(ULONG) Release();

STDMETHODIMP QueryInterface(REFIID riid, void** ppvObject);

}

CEnumString::~CEnumString()

{

}

/

// CEnumString message handlers

ULONG FAR EXPORT CEnumString::AddRef()

{

TRACE_LINE("CEnumString::AddRef\n");

return ::InterlockedIncrement(reinterpret_cast<LONG*>(&m_nRefCount));

}

ULONG FAR EXPORT CEnumString::Release()

{

TRACE_LINE("CEnumString::Release\n");

ULONG nCount = 0;

nCount = (ULONG) ::InterlockedDecrement(reinterpret_cast<LONG*>(&m_nRefCount));

if (nCount == 0)

delete this;

return nCount;

}

HRESULT FAR EXPORT CEnumString::QueryInterface(

REFIID riid, void FAR* FAR* ppvObject )

{

HRESULT hr = E_NOINTERFACE;

if (ppvObject != NULL)

{

*ppvObject = NULL;

if (IID_IUnknown == riid)

*ppvObject = static_cast<IUnknown*>(this);

if (IID_IEnumString == riid)

*ppvObject = static_cast<IEnumString*>(this);

if (*ppvObject != NULL)

{

hr = S_OK;

((LPUNKNOWN)*ppvObject)->AddRef();

}

}

else

{

hr = E_POINTER;

}

return hr;

}

STDMETHODIMP CEnumString::Next(ULONG celt, LPOLESTR* rgelt, ULONG* pceltFetched)

{

return E_NOTIMPL;

}

STDMETHODIMP CEnumString::Skip(ULONG celt)

{

return E_NOTIMPL;

}

STDMETHODIMP CEnumString::Reset(void)

{

return E_NOTIMPL;

}

STDMETHODIMP CEnumString::Clone(IEnumString** ppenum)

{

if (!ppenum)

return E_POINTER;

CEnumString* pnew = new CEnumString;

pnew->AddRef();

*ppenum = pnew;

return S_OK;

}

BOOL CEnumString::Bind(HWND p_hWndEdit, DWORD p_dwOptions , LPCTSTR p_lpszFormatString )

{

if ((m_fBound) || (m_pac))

return FALSE;

HRESULT hr = S_OK;

hr = m_pac.CoCreateInstance(CLSID_AutoComplete);

if (SUCCEEDED(hr))

{

if (p_dwOptions)

{

CComQIPtr<IAutoComplete2> pAC2(m_pac);

ATLASSERT(pAC2);

hr = pAC2->SetOptions(p_dwOptions); // This never fails?

pAC2.Release();

}

hr = m_pac->Init(p_hWndEdit, this, NULL, (LPOLESTR)p_lpszFormatString);

if (SUCCEEDED(hr))

{

m_fBound = TRUE;

return TRUE;

}

}

return FALSE;

}

VOID CEnumString::Unbind()

{

if (!m_fBound)

return;

ATLASSERT(m_pac);

if (m_pac)

{

m_pac.Release();

m_fBound = FALSE;

}

}

#include "..\esuihelper\EnumString.h"

#include "DataType.h"

class CDataType;

class _ES_DATATYPE_EXPORT CEnumDataType : public CEnumString

{

public:

CEnumDataType(LPCTSTR lpszDataType);

virtual ~CEnumDataType();

CDataType* m_pDataType;

protected:

CString m_strDataType;

STDMETHODIMP Next(ULONG celt, LPOLESTR* rgelt, ULONG* pceltFetched);

STDMETHODIMP Skip(ULONG celt);

STDMETHODIMP Reset(void);

STDMETHODIMP Clone(IEnumString** ppenum);

ado20::_RecordsetPtr m_pRecordset;

};

CEnumDataType::CEnumDataType(LPCTSTR lpszDataType)

:m_strDataType(lpszDataType)

{

m_pDataType=g_pDataTypeManager->GetDataType(m_strDataType);

ASSERT(m_pDataType);

m_pRecordset.CreateInstance("ADODB.Recordset");

try{

if(m_pRecordset!=NULL){

if( m_pRecordset->State&adStateOpen){

return;

}

}

ESRecordsetOpen((LPCTSTR)m_pDataType->m_strSQLAutoComplete, _variant_t((IDispatch *)g_connection,true),

m_pRecordset,adOpenDynamic,adLockOptimistic, adCmdUnspecified);

m_pRecordset->Requery(adCmdUnknown);

if(m_pRecordset->BOF==VARIANT_FALSE)

m_pRecordset->MoveFirst();

}

catch(_com_error &e)

{

ESErrPrintProviderError(g_connection);

ESErrPrintComError(e);

}

}

CEnumDataType::~CEnumDataType()

{

try{

if(m_pRecordset!=NULL){

if( m_pRecordset->State&adStateOpen){

m_pRecordset->Close();

}

}

}

catch(_com_error &e)

{

ESErrPrintProviderError(g_connection);

ESErrPrintComError(e);

}

}

STDMETHODIMP CEnumDataType::Next(ULONG celt, LPOLESTR* rgelt, ULONG* pceltFetched)

{

if(m_pRecordset==NULL) return OLE_E_BLANK;

HRESULT hr = S_FALSE;

ZeroMemory(rgelt, sizeof(OLECHAR*) * celt);

try{

if (!celt) celt = 1;

for (ULONG i = 0; i < celt; i++){

if (m_pRecordset->EndOfFile== VARIANT_TRUE)

break;

_bstr_t bstrText=

(LPCTSTR)g_GetValueString(

m_pRecordset->Fields->Item[(LPCTSTR)m_pDataType->m_strAutoCompleteField]->Value);

if(bstrText.length()>0){

rgelt[i] = OLESTRDUP(bstrText);

if (pceltFetched)

*pceltFetched++;

}

m_pRecordset->MoveNext();

}

if (i == celt)

hr = S_OK;

}

catch(_com_error &e)

{

ESErrPrintProviderError(g_connection);

ESErrPrintComError(e);

return e.Error();

}

return hr;

}

STDMETHODIMP CEnumDataType::Skip(ULONG celt)

{

if(m_pRecordset==NULL) return OLE_E_BLANK;

try{

m_pRecordset->Move(celt,(long)adBookmarkCurrent);

}

catch(_com_error &e)

{

ESErrPrintProviderError(g_connection);

ESErrPrintComError(e);

return e.Error();

}

return S_OK;

}

STDMETHODIMP CEnumDataType::Reset(void)

{

if(m_pRecordset==NULL) return OLE_E_BLANK;

try{

m_pRecordset->Requery(adCmdUnknown);

if(m_pRecordset->BOF==VARIANT_FALSE)

m_pRecordset->MoveFirst();

}

catch(_com_error &e)

{

ESErrPrintProviderError(g_connection);

ESErrPrintComError(e);

return e.Error();

}

return S_OK;

}

STDMETHODIMP CEnumDataType::Clone(IEnumString** ppenum)

{

if (!ppenum)

return E_POINTER;

CEnumDataType* pnew = new CEnumDataType(m_strDataType);

pnew->AddRef();

*ppenum = pnew;

return S_OK;

}

问:如何在MDI环境下枚举所有打开的窗口?

答:

In MFC, each CMDIChildWnd created by the framework is managed as a child window of the MDIClient window. This MDIClient window is a child of the mainframe window and fills its client area. For MDI applications, the mainframe window is encapsulated by the CMDIFrameWnd class. This class has a public embedded HWND member (m_hWndMDIClient), which is the handle to the MDIClient window. For MDI applications, AppWizard derives the CMainFrame class from CMDIFrameWnd.

The MDIClient maintains an internal list of child windows. In an MFC application, these child windows are either a CMDIChildWnd object or an internal window used to display the title of an iconized window. Note that this is an internal list controlled by Windows; don't make assumptions about the ordering of children in the list after an API function is called.

/

#define EXAMPLE_DIR "C:\\Newdir"

// Include Ifx.h for built-in InstallScript function prototypes.

#include "Ifx.h"

export prototype ExFn_DeleteDir(HWND);

function ExFn_DeleteDir(hMSI)

begin

// Create a directory.

if (CreateDir (EXAMPLE_DIR) != 0) then

// Report the error; then terminate.

MessageBox ("Unable to create directory.", SEVERE);

else

// Report success.

MessageBox (EXAMPLE_DIR + " was created.", INFORMATION);

// Delete the directory. If the directory is not

// empty, it is not deleted.

if (DeleteDir (EXAMPLE_DIR, ONLYDIR) = 0) then

// Report success.

MessageBox (EXAMPLE_DIR + " was deleted.", INFORMATION);

else

MessageBox ("Unable to delete directory.", SEVERE);

endif;

endif;

end;

问:怎样动态显示一个进度对话框呢? 我在主窗体里面执行一个很耗时的计算过程,现在想启动一个对话框,这个对话框中包含一个进度条,能够动态显示我的计算的进度,如何实现呢?

肯定是要用到多线程了?

答:

VC菜单“Project”->"Add components and controls"

有个进度条组件,基本上不要太大修改就可以,

问:怎样把在ACCESS里建立的报表在VC里显示出来

答:DAO对象不能直接访问Access报表和模块,以及在查询中使用这些对象。

在客户机安装了Access的情况下,可以自动化Access,然后把报表另存为HTML,之后用浏览器控件或CHTMLView显示

参见www.codeproject.com/database/access_reports_class.asp

http://codeguru.earthweb.com/Cpp/data/mfc_database/microsoftaccess/article.php/c1107/

问:为何我的ActiveX显示位图正常,但打印不正常。我开发了一个显示位图的控件,在插入到Word2000里显示图形,显示一切正常但打印时就巨小。我试着在OnDraw(CDC *pdc)里在 if(pdc->IsPrinting()) 里做放大处理,可是打印时pdc->IsPrinting() 返回还是false,不起作用。我使用的是CPictureHolder显示位图。

答:不要用基于像素的映射模式,用基于实际尺寸的,打印机的像素大小和屏幕不一样。看看你的逻辑坐标系的Y轴是不是反了

MM_HIMETRIC的Y轴方向和MM_TEXT不一样的

问:

如何取得鼠标位置的文字

比如鼠标在记事本窗口上,并且在WORD的位置,我怎么得到"word"

我知道可以得到NOTEPAD窗口的文字,但是如果打开的是10M的文件,难道

我还要先复制到内存然后来找?

即使我知道了哪个缓冲区,又怎么知道鼠标指的是哪个字呢

DOS到好办,WINDOWS下突然不知道咋办了

________________________________

|无标题-1 |

--------------------------------

| how to get the word ... |

| $ |

| |

|______________________________|

答:Enabling Your Wish and the Needs of Others, Too

Dear Dr. GUI,

How can I grab the text that lies beneath the cursor, independent of the application that the text occurs in?

I am using Visual C++, and, ideally, I would like functionality similar to that found in VC's debugger: When the cursor is placed over a variable, information relevant to the variable is displayed in a box after a short delay, rather like a tool tip.

I have seen translation software give an immediate translation of the word under the cursor, irrespective of the application in which the word resides. How are they doing it? Is it done by using Optical Character Recognition (OCR)? Or is there a more elegant method using the Win32 API?

Thanks in advance,

Henry Brighton

Dr. GUI replies:

Wow, Henry. This turns out to be really interesting because currently there is no single Microsoft Win32&reg; API to get the text underneath the cursor for all Windows-based applications. However, you can get this information for most Windows applications by using the Microsoft Active Accessibility Software Development Kit (SDK).

This technology has been developed by Microsoft for people who have accessibility problems that affect their ability to utilize the standard computer. There are now accessibility aids such as screen review utilities, on-screen keyboard utilities, and so forth. Is this cool or what?

Active Accessibility is based on the Component Object Model (COM) and can be used to obtain or provide information about the system-provided UI elements of Windows applications and the operating system. Currently, it is fully supported on Windows 95, Windows 98, and Windows 2000, and partly supported on Windows NT 4.0 Service Pack 4 and later. The supported UI elements include:

Predefined controls (controls defined in User32.dll), such as list boxes.

Common controls (controls defined in Comctl32.dll), such as toolbars.

Window elements, such as title bars and menus.

Although the UI elements in applications such as Microsoft Office and Visual C++ are supported by this SDK, the Office document content is not.

To obtain more information about the Active Accessibility SDK and where to download its latest version, go to http://www.microsoft.com/enable/msaa/.

问:为什么用CWnd::CreateControl在视图中创建的控件子窗体不能显示?

我的程序是这样的:

void CCreateButtonView::OnRButtonDown(UINT nFlags, CPoint point)

{

CWnd m_ax;

LPCTSTR pszName = "MSDBGrid.DBGrid";

//控件的ProgID ,这里我用的是DBGrid32.ocx

m_ax.CreateControl (pszName,NULL, WS_VISIBLE | WS_CHILD,

CRect(100,100,200,200), this, AFX_IDW_PANE_FIRST);

m_ax.ShowWindow(SW_SHOW);

CView::OnRButtonDown(nFlags, point);

}

想要实现的功能是:在View中右键单击动态创建DBGrid.ocx控件的子窗体,通过调试发现没有问题,创建成功,但就是不能将创建的控件显示出来。

最奇怪的是,如果我在m_ax.ShowWindow(SW_SHOW);之后加上一句 AfxMessageBox("hehe");创建的子窗体居然能显示出来了,请高手指点,这到底是怎么回事啊?应该怎么解决?多谢

答:CWnd::~CWnd会调用DestroyWindow。将CWnd m_ax;不定义为局部变量就ok了!

问:在ACTIVEX中开线程,是用_beginthreadEx还是用Afxbeginthread

我在线程中用到了不少c runtime 的函数,如strlen等等。按照道理似乎应该使用beginthreadEx,但是我的activex是用MFC开发的,这样按照道理,似乎又应该使用Afxbeginthread。还有,如果我在项目设置里选择不使用mfc,整个程序正常运行。请问我到底该使用哪个函数。

beginthreadEx启动的线程中不使用MFC就没问题。否则还是用MFC的Afxbeginthread吧。MFC里面大把的函数引用线程局部存储的。

问:如何对基于对话框的MFC应用程序加入Accelerator,我已经添加了Accelerator资源,却没有作用

答:Q222829 HOWTO: Using Accelerator Keys Within a Modal Dialog Box

http://support.microsoft.com?kbid=222829

问:如何在文件夹浏览对话框中只显示映射文件夹

答:SHGetSpecialFolderLocation/CSIDL_DRIVES

Custom Filtering

Under Microsoft&reg; Windows&reg; XP, SHBrowseForFolder supports custom filtering on the contents of the dialog box. To create a custom filter, follow these steps:

Set the BIF_NEWDIALOGSTYLE flag in the ulFlags member of the BROWSEINFO parameter structure.

Specify a callback function in the lpfn member of the BROWSEINFO parameter structure.

The callback function will receive BFFM_INITIALIZED and BFFM_IUNKNOWN messages. On receipt of the BFFM_IUNKNOWN message, the callback function's LPARAM parameter will contain a pointer to an instance of IUnknown. Call QueryInterface on that IUnknown to obtain a pointer to an IFolderFilterSite interface.

Create an object that implements IFolderFilter.

Call IFolderFilterSite::SetFilter, passing it a pointer to IFolderFilter. IFolderFilter methods can then be used to include and exclude items from the tree.

Once the filter is created, the IFolderFilterSite interface is no longer needed. Call IFolderFilterSite::Release if you have no further use for it.

see also

http://www.codeproject.com/dialog/cfolderdialog.asp

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

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

http://msdn.microsoft.com/msdnmag/issues/0400/c/

http://msdn.microsoft.com/msdnmag/issues/04/03/CQA/default.aspx

问:现在有一个浮动的DialogBar工具条,如保去除其上的系统控制钮,即状态栏上的关闭按钮

答:http://www.codeproject.com/docking/disabletoolbarclose.asp

问:用mfc建立了一个dll,dll里有个对话框,但话框上的工具条没有tooltip功能,该怎么做?

答:代码是在DLL还是在EXE并不是这个问题的关键。你需要从CFrameWnd中复制工具提示相关代码。当然,如果对话框是非模态的,那么你还需要用Hook来确保获取鼠标和键盘消息。

参考文档

微软知识库文章Q233263 PRB: Modeless Dialog Box in a DLL Does Not Process TAB Key

问:为什么我使用SAFEARRAY通过VB向VC程序传递字符串数组时总是不能成功啊?

答:Q207931 HOWTO: Pass Arrays Between Visual Basic and C

问:如何在我的程序中自动化Office?

答:Q196776 Office Automation Using Visual C++

参考文档:

Q216388 FILE: B2CSE.exe Converts Visual Basic Automation Code to Visual C++

Q222101 HOWTO: Find and Use Office Object Model Documentation

Q185125 HOWTO: Invoke a Stored Procedure w/ADO Query using VBA/C++/Java

Q207931 HOWTO: Pass Arrays Between Visual Basic and C

Q238972 INFO: Using Visual C++ to Automate Office

问:如何使CTreeCtrl的节点即使没有子节点也显示+号? 像资源管理器那样?这样就可以在Expand的时候加载其子节点

答:http://www.microsoft.com/msj/archive/S563.aspx

问:在CListCtrl中如何将LVS_EX_CHECKBOXES系统指定的风格换成自己的图标。

即可以标识为选中、未选中及当前指针位置所在项目

答:LVS_EX_CHECKBOXES的作用是添加一个包含两个图像的State Image List以及在鼠标点击和盘操作的时候自动修改ItemState。

自定义方法是重设State Image List或者用Custom Draw自己画State

问:dll中的对话框内ocx控件不能显示,如何解决?

我试图写一个Share MFC DLL,在dll中包含一个属性对话框,属性对话框中的其中一个属性页包含一个vsflexgrid 7.0的控件,在运行时,当我选择含有vsflexgri控件的属性页时,该页立即消失,且属性对话框中对应的tab也不见了。

答:DLL中需要的OLE的初始化最好在放在调用DLL的主应用程序中,而不要放在DLL中。参见Q154320 BUG: AfxOleInit Returns TRUE Without Initializing OLE in a DLL

问: 如何在VC中使用ADO将数据高效地从一个ACCESS数据库移动到另一个ACCESS数据库

答:Select Into/Insert into到链接表就可以了

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1615185

[ 收藏到我的网摘] moon发表于 2007年05月18日 15:31:00 <link href="http://blog.csdn.net/xiaops2005/Services/Pingback.aspx" target="_blank" rel="external nofollow" rel="pingback"> <!--<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"xmlns:dc="http://purl.org/dc/elements/1.1/"xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"><rdf:Descriptionrdf:about="http://blog.csdn.net/xiaops2005/archive/2007/05/18/1615185.aspx"dc:identifier="http://blog.csdn.net/xiaops2005/archive/2007/05/18/1615185.aspx"dc:title="实用!超强VC/MFC 常见问答收集"trackback:ping="http://tb.blog.csdn.net/TrackBack.aspx?PostId=1615185" /></rdf:RDF>-->function hide(){showComment();}

相关文章:

  • 在应用程序中集成自动完成功能 2003-09-10 jiangsheng
  • Win32 & .Net Q&A 200509 2005-09-13 jiangsheng
  • Jiangsheng的CSDN Digest (Dec 2005) 2005-12-24 jiangsheng
  • [翻译]WTL开发者指南 第2章 Win32 SDK windowing 2005-05-30 uoyevoli
  • WINDOWS核心编程笔记(16-21) 2005-12-10 byxdaz