如题?听说可以自己处理消息循环?可是怎么实现呢?各位看看,给点tips!
解决方案 »
- linux
- IOCP投递I/O问题?
- 怎样得到CSplitterWnd分割条的区域?
- 急救!!GB2312的问题
- 怎样做出一个好的数据库软件,请大家进来看看?
- 不用api还有什么办法可以取到ftp服务器上文件的最后修改时间
- 请问如何把摄像头捕捉的视频以数据流的形式保存为Avi文件?
- @@@@@@@ 如何将imagelist 和 Microsoft ListView 6.0 控件相关联??@@@@@
- 流程图的作用?
- 公司不让用UltraEdit和EditPlus这类商业软件,请问有没有好的开源免费的文本编辑工具?
- 在对话框中加入了一个richedit控件,程序运行后出现错误,编译时没有问题。
- 有个 edit 控件,想使输入的(输入是字母)是大写,怎么做?
like
Getmessge
{
dispatchmessage()
{
我自己写了一个类。百来行代码,不需要MFC及ATL的支持,要的话留个email给我。
// 事件: _ICountdownEvents
#import "timers.dll" no_namespace, named_guids#define ICOUNTDOWN_DISP_EVENT_IMPL \
IDispEventImpl<I,ICountdownPrtWithEvents, \
&DIID_ICountdownEvents), \
&LIBID_TIMERSLib, \
1,0>template<UINT I, class T>
class ICountdownPrtWithEvents:
public ICOUNTDOWN_DISP_EVENT_IMPL,
public ICountdownPtr // 注意这里
{
public:
ICountdownPrtWithEvents()
{
}
~ICountdownPrtWithEvents()
{
}
public:
BEGIN_SINK_MAP(ICountdownPrtWithEvents)
SINK_ENTRY_EX(I,DIID_ICountdownEvents,1,OnHander)
...........
END_SINK_MAP() STDMETHOD(OnHander)()
{
// 事件处理函数
} ......... HRESULT DispEventAdvie(T* pDisplay) // 用这个函数来建立连接
{
HRESULT hr;
m_pDisplay = pDisplay;
IUnknownPtr pUnk;
hr = QueryInterface(_uuidof(IUnknown),&pUnk);
if( SUCCEEDED(hr))
{
hr = ICOUNTDOWN_DISP_EVENT_IMPL::DispEventAdvise(pUnk);
}
return hr;
}
HRESULT DispEventUnadvise() // 用这个函数来取消连接
{
HRESULT hr;
m_pDisplay = NULL;
IUnknownPtr pUnk;
hr = QueryInterface(_uuidof(IUnknown),&pUnk);
if( SUCCEEDED(hr))
{
hr = ICOUNTDOWN_DISP_EVENT_IMPL::DispEventUnadvise(pUnk);
}
return hr;
} ICountdownPtr& operator = (int null)
{
return ICountdownPtr::operator=(null);
}private:
T* m_pDisplay;
};客户端调用:
ICountdownPtrWithEvents< 1, CYouDlg> m_DispEvent; CYouDlg::OnInitDialog()
{
m_DispEvent.DispEventAdvise(this);
} CYouDlg::OnCancel()
{
m_DispEvent.DispEventUnadvise();
}
The template class IDispEventImpl can be used to provide support for connection points in your ATL COM object. A connection point allows your COM object to handle events fired from external COM objects. These connection points are mapped with an event sink map, provided by your COM object.To properly implement a connection point or points for your COM object, the following steps must be completed: Import the type libraries for each external
Declare the IDispEventImpl interfaces
Declare an event sink map
Advise and unadvise the connection points
In this procedure, you will be modifying only the header file (.h) of your COM class.Importing the Type Libraries
For each external object whose events you wish to handle, you must import the type library. This step defines the events that can be handled and provides information that is used when declaring the event sink map. The #import directive can be used to accomplish this. Add the necessary #import directive lines for each dispatch interface you will support to the header file (.h) of your COM class.The following example imports the type library of an external COM server (MyServer):#import "D:\MyServer.dll" raw_interfaces_only, no_namespace, named_guidsNote You must have a separate #import statement for each external dispatch interface you will support.Declaring the IDispEventImpl Interfaces
Now that you have imported the type libraries of each dispatch interface, you need to declare separate IDispEventImpl interfaces for each external dispatch interface. Modify the declaration of your COM class by adding an IDispEventImpl interface declaration for each external object. For more information on the parameters, see IDispEventImpl.The following lines of code declare two connection points, for the custom IExtEvents1 and IExtEvents2 interfaces, for the COM object implemented by class CMyObj:public IDispEventImpl<0, CMyObj, &DIID__IExtEvents1,
&LIBID_EXTEVENTS1Lib, 1, 0>,
public IDispEventImpl<1, CMyObj, &DIID__IExtEvents2,
&LIBID_EXTEVENTS2Lib, 1, 0>Declaring an Event Sink Map
In order for the event notifications to be handled by the proper function, your COM object must route each event to its correct handler. This is achieved by declaring an event sink map.ATL provides several macros, BEGIN_SINK_MAP, END_SINK_MAP, and SINK_ENTRY, that make this mapping easier. The standard format is as follows:BEGIN_SINK_MAP(comClass)
SINK_ENTRY(id, dispid, func)
. . . //additional external event entries
END_SINK_MAP()The following example declares an event sink map with two event handlers:BEGIN_SINK_MAP(CMyObj)
SINK_ENTRY(0, Events1, OnClick1)
SINK_ENTRY(0, Events2, OnClick2)
END_SINK_MAP()The implementation is nearly complete. The last step concerns the advising and unadvising of the external interfaces.Advising and Unadvising the IDispEventImpl Interfaces
The final step is to implement a method that will advise (or unadvise) all connection points at the proper times. This advising must be done before communication between the external clients and your object can take place. Before your object becomes visible, each external dispatch interface supported by your object is queried for outgoing interfaces. A connection is established and a reference to the outgoing interface is used to handle events from the control. This procedure is referred to as "advising."After your object is finished with the external interfaces, the outgoing interfaces should be notified that they are no longer used by your COM object. This process is referred to as "unadvising."Because of the unique nature of COM objects, this procedure varies, in detail and execution, between implementations. These details are beyond the scope of this topic and are not addressed.