MSDN上说:
WM_DEVICECHANGEThe WM_DEVICECHANGE device message notifies an application of a change to the hardware configuration of a device or the computer.A window receives this message through its WindowProc function.LRESULT CALLBACK WindowProc(
  HWND hwnd,       // handle to window
  UINT uMsg,       // message identifier
  WPARAM wParam,   // device-change event
  LPARAM lParam    // event-specific data
);
程序中在框架类中和View类中分别在WindowProc中        if (message == WM_DEVICECHANGE)
{
TRACE("WM_DEVICECHANGE\n");
        }
在框架类中能够捕捉到该消息,在视图类中怎么捕捉不到呢?另外用
 
afx_msg BOOL OnDeviceChange( 
   UINT nEventType, 
   DWORD_PTR dwData  
);
 这种方法也不行。请指点一下,我想在view类中捕捉到该消息。谢谢。

解决方案 »

  1.   

    放在框架类CMainFrame中来响应。另外,消息映射添加了没有?
      

  2.   

    添加了。CMainFrame 能捕捉到。我的问题是怎么能在view类中捕捉到?是我忘了什么步骤?
    我是是在view类的WindowProc 加了段代码。有问题么
      

  3.   

    你要view的话就用这个RegisterDeviceNotification注册一下
    否则WM_DEVICECHANGE 只发给顶层窗口
    msdn里面有说明
    The DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE events are automatically broadcast to all top-level windows for port devices.