手动添加自己的消息映射函数

evc可以手动添加自己的消息映射函数BEGIN_MESSAGE_MAP,把消息和函数指针联系起来。

1、在CPP添加:

BEGIN_MESSAGE_MAP(CAutoChirperApp, CWinApp)
 //{{AFX_MSG_MAP(CAutoChirperApp)
 //}}AFX_MSG_MAP
 // Standard file based document commands
END_MESSAGE_MAP()

然后在BEGIN_MESSAGE_MAP添加自己的消息函数或系统函数:

BEGIN_MESSAGE_MAP(CAutoChirperApp, CDialog)
 //{{AFX_MSG_MAP(CAutoChirperApp)
 ON_WM_PAINT()
 ON_WM_TIMER()
 ON_WM_LBUTTONDOWN()
 ON_WM_LBUTTONUP()
 ON_WM_WINDOWPOSCHANGED()//系统消息,重画窗口
 ON_MESSAGE(WMU_GRAPHNOTIFY, OnGraphNotify)//自定义消息WMU_GRAPHNOTIFY,及函数指针OnGraphNotify

 ON_MESSAGE(WMU_BROWSER_MSG, OnBrowserMsg)
 ON_MESSAGE(WMU_PAGE_STU, OnPageMsg)
 ON_MESSAGE(WMU_MENU_CANCEL, OnMenuMsg)
 ON_MESSAGE(WM_DEVICECHANGE, OnDeviceChange) 
 //}}AFX_MSG_MAP
 //ON_WM_DEVICECHANGE()
END_MESSAGE_MAP()

在CPP文件中添加消息响应函数

LRESULT CAutoChirperApp::OnGraphNotify(WPARAM wParam, LPARAM lParam)//SD卡状态函数
{
 CString msg;
 // msg.Format(TEXT("%d"), mFilterGraph->GetGraphNotifyEvent());
 //MessageBox( msg, L"INIT ERROR!!!", MB_OK );

 switch( mFilterGraph->GetGraphNotifyEvent() )
 {
  case EC_COMPLETE:
   if( mFilterGraph->GetClipState() != CLIPSTATE_INIT )
   {
    m_bCompleteNext = TRUE;

    if(m_bShowControls == FALSE)
    {
    mFilterGraph->InitVideoWindow(0);
    //mFilterGraph->MoveVideoWindow( rectClient.left, rectClient.top, rectClient.Width(), rectClient.Height() );
    m_bShowControls = TRUE;
    }

    OnBtnNext();

    g_lFlagPaint = 0xffffffff;
    InvalidateRect( NULL, FALSE );
   }
  break;
  case EC_ACTIVATE:
   // AfxMessageBox(L"EC_ACTIVATE Failed!");
  break;
  case EC_BUFFERING_DATA:
   //AfxMessageBox(L"EC_BUFFERING_DATA Failed!");
  break;
  case EC_CLOCK_CHANGED:
   // AfxMessageBox(L"EC_CLOCK_CHANGED Failed!");
  break;
  // case EC_CLOCK_UNSET:
   //    AfxMessageBox(L"EC_CLOCK_UNSET Failed!");
  //    break;
  //case EC_DEVICE_LOST:
   //      AfxMessageBox(L"EC_DEVICE_LOST Failed!");
  //    break;
  case EC_DISPLAY_CHANGED:
   // AfxMessageBox(L"EC_DISPLAY_CHANGED Failed!");
  break;
  case EC_END_OF_SEGMENT:
   // AfxMessageBox(L"EC_END_OF_SEGMENT Failed!");
  break;
  case EC_ERROR_STILLPLAYING:
   // AfxMessageBox(L"EC_ERROR_STILLPLAYING Failed!");
  break;
  case EC_ERRORABORT:
   //AfxMessageBox(L"EC_ERRORABORT Failed!");
   
  break;
  case EC_EXTDEVICE_MODE_CHANGE:
   // AfxMessageBox(L"EC_EXTDEVICE_MODE_CHANGE Failed!");
  break;
  case EC_FULLSCREEN_LOST:
   // AfxMessageBox(L"EC_FULLSCREEN_LOST Failed!");
  break;
  // case EC_GRAPH_CHANGED:
   //      AfxMessageBox(L"EC_GRAPH_CHANGED Failed!");
  //     break;
  case EC_LENGTH_CHANGED:
   // AfxMessageBox(L"EC_LENGTH_CHANGED Failed!");
  break;
  case EC_NEED_RESTART:
   // AfxMessageBox(L"EC_NEED_RESTART Failed!");
  break;
  case EC_NOTIFY_WINDOW:
   // AfxMessageBox(L"EC_NOTIFY_WINDOW Failed!");
  break;
  case EC_OLE_EVENT:
   // AfxMessageBox(L"EC_OLE_EVENT Failed!");
  break;
  case EC_OPENING_FILE:
   //  AfxMessageBox(L"EC_OPENING_FILE Failed!");
  break;
  case EC_PALETTE_CHANGED:
   // AfxMessageBox(L"EC_PALETTE_CHANGED Failed!");
  break;
  case EC_PAUSED:
   // AfxMessageBox(L"EC_PAUSED Failed!");
  break;
  case EC_QUALITY_CHANGE:
   // AfxMessageBox(L"EC_QUALITY_CHANGE Failed!");
  break;
  case EC_REPAINT:
   //  AfxMessageBox(L"EC_REPAINT Failed!");
  break;
  case EC_SEGMENT_STARTED:
   // AfxMessageBox(L"EC_SEGMENT_STARTED Failed!");
  break;
  case EC_SHUTTING_DOWN:
   // AfxMessageBox(L"EC_SHUTTING_DOWN Failed!");
  break;
  //  case EC_SNDDEV_IN_ERROR:
   //       AfxMessageBox(L"EC_SNDDEV_IN_ERROR Failed!");
  //      break;
  //  case EC_SNDDEV_OUT_ERROR:
   //     AfxMessageBox(L"EC_SNDDEV_OUT_ERROR Failed!");
  //    break;
  case EC_STARVATION:
   // AfxMessageBox(L"EC_STARVATION Failed!");
  break;
  //   case EC_STATE_CHANGE:
   //       AfxMessageBox(L"EC_STATE_CHANGE Failed!");
  //      break;
  //  case EC_STEP_COMPLETE:
   //       AfxMessageBox(L"EC_STEP_COMPLETE Failed!");
  //      break;
  case EC_STREAM_CONTROL_STARTED:
   //AfxMessageBox(L"EC_STREAM_CONTROL_STARTED Failed!");
  break;
  case EC_STREAM_CONTROL_STOPPED:
   // AfxMessageBox(L"EC_STREAM_CONTROL_STOPPED Failed!");
  break;
  case EC_STREAM_ERROR_STILLPLAYING:
   // AfxMessageBox(L"EC_STREAM_ERROR_STILLPLAYING Failed!");
  break;
  case EC_STREAM_ERROR_STOPPED:
   // AfxMessageBox(L"EC_STREAM_ERROR_STOPPED Failed!");
  break;
  case EC_TIMECODE_AVAILABLE:
   // AfxMessageBox(L"EC_TIMECODE_AVAILABLE Failed!");
  break;
  case EC_USERABORT:
   //AfxMessageBox(L"EC_USERABORT Failed!");
  break;
  case EC_VIDEO_SIZE_CHANGED:
   // AfxMessageBox(L"EC_VIDEO_SIZE_CHANGED Failed!");
  break;
  case EC_WINDOW_DESTROYED:
   //AfxMessageBox(L"EC_WINDOW_DESTROYED Failed!");
  break;

 }

 return 0;
}

2、接下来就是添加消息了

在相关的头文件里添加如下代码:

#define WMU_GRAPHNOTIFY  (WM_USER+1004)//自定义的消息,应该在WM_USER基础上增加,但是前100最好不用

然后在头文件的类定义中在public下添加函数定义

class CAutoChirperApp: public CDialog
{

........

protected:

    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);//系统消息函数

    DECLARE_MESSAGE_MAP()//一定要添加这个宏定义,使BEGIN_MESSAGE_MAP生效

public:

    LRESULT OnGraphNotify(WPARAM wParam, LPARAM lParam);//由于是自定义函数,所以不用在函数前面加afx_msg

......

}

 

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭