C#从C ++应用程序捕获Windows消息

时间:2017-08-03 14:23:32

标签: c# c++ winapi visual-c++ mfc

我正在移植与另一个应用程序通信的MFC C ++应用程序。在C ++代码中,我看到了类型

的定义
ON_MESSAGE(NVH_NOTIFY,OnFCNotify)

并在OnFCNotify中输入以下代码

LRESULT CDllTestDlg::OnFCNotify(WPARAM wParam, LPARAM lParam)
{
  UpdateData(TRUE);
  CString temp;
  short Msg = LOWORD(wParam);
  switch(Msg) {
  case NVH_CONN_ERR:        //It's error when to connect NVH.
    GetDlgItem(IDC_NVCHECK)->EnableWindow(TRUE);
    GetDlgItem(IDC_SELFDIAG)->EnableWindow(TRUE);
    AddResult("It's error when to connect NVH.");
    break;
}

现在我无法从被叫应用程序获取返回消息。 我试图覆盖WndProc但没有成功。我只收到C#应用程序的消息。

private const int NVH_NOTIFY = WM_USER + 2;

// Override WndProc to watch for messages.
protected override void WndProc(ref Message m)
{
    if (m.Msg == NVH_NOTIFY)
        Console.WriteLine("Message received!");

    base.WndProc(ref m);
}

0 个答案:

没有答案