有本书《Inside COM》好象讲了

解决方案 »

  1.   

    实现连接点可以得到一些消息,但不像WindowProc那样全,你可以试试CallBack的方式来从client传递消息。
      

  2.   

    机制和MFC类似,使用消息映射The Message Map
    To enable us to process window messages in a CWindowImpl-derived class, ATL inherits from the abstract base class CMessageMap. CMessageMap declares one pure virtual function, ProcessWindowMessage. The entire class is shown here: class ATL_NO_VTABLE CMessageMap
    {
    public:
    virtual BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg,
        WPARAM wParam, LPARAM lParam,
        LRESULT& lResult, DWORD dwMsgMapID) = 0;
    }; 
    Your CWindowImpl-derived class must implement the ProcessWindowMessage function, which is called from the WindowProc function in the CWindowImpl base class CWindowImplBaseT. If ProcessWindowMessage returns TRUE, the message has been handled by your derived class and WindowProc shouldn't continue with default message processing. A FALSE return value allows default processing.BEGIN_MSG_MAP(CMainFrame)
        MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
    END_MSG_MAP()Message handlers are processed in order from top to bottom until something handles the message or processing falls through, which results in default processing. The bHandled parameter is set to TRUE by default before the handler function is called. You can manually set it to FALSE (as OnDestroy does) to allow default processing after the handler function returns and ProcessWindowMessage exits.ATL has a large selection of message-handler macros to choose from. The basic types are MESSAGE_HANDLER, NOTIFY_HANDLER, and COMMAND_HANDLER for normal window messages, WM_NOTIFY messages, and WM_COMMAND messages. Ranges of messages are handled using the corresponding macros MESSAGE_RANGE_HANDLER, NOTIFY_RANGE_HANDLER, and COMMAND_RANGE_HANDLER. The easiest way to add handlers to a message map is to right-click on the class in ClassView and choose Add Windows Message Handler from the context menu. Microsoft Visual C++ then inserts the correct macro based on the message you choose to handle. You can't use ClassWizard to add handlers to ATL message maps. Here's a summary of the available message-handler macros:
    MESSAGE_HANDLER Maps a window message to a handler function 
    MESSAGE_RANGE_HANDLER Maps a contiguous range of window messages to a handler function 
    COMMAND_HANDLER Maps a WM_COMMAND message to a handler function based on the notification code and the identifier of the menu item, control, or accelerator
    COMMAND_ID_HANDLER Maps a WM_COMMAND message to a handler function based on the identifier of the menu item, control, or accelerator
    COMMAND_CODE_HANDLER Maps a WM_COMMAND message to a handler function based on the notification code
    COMMAND_RANGE_HANDLER Maps a contiguous range of WM_COMMAND messages to a handler function based on the identifier of the menu item, control, or accelerator
    NOTIFY_HANDLER Maps a WM_NOTIFY message to a handler function based on the notification code and the control identifier 
    NOTIFY_ID_HANDLER Maps a WM_NOTIFY message to a handler function based on the control identifier 
    NOTIFY_CODE_HANDLER Maps a WM_NOTIFY message to a handler function based on the notification code 
    NOTIFY_RANGE_HANDLER Maps a contiguous range of WM_NOTIFY messages to a handler function based on the control identifier