2014-04-23 88 views
-1

我试图在我的胜利表单应用中覆盖此WndProc,但得到错误IntPtr WndProc no suitable method found to override。我的代码如下IntPtr WndProc找不到合适的方法来覆盖c#

protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) 
     { 
      if (msg == NativeCalls.APIAttach && (uint)lParam == NativeCalls.SKYPECONTROLAPI_ATTACH_SUCCESS) 
      { 
       // Get the current handle to the Skype window 
       NativeCalls.HWND_BROADCAST = wParam; 
       handled = true; 
       return new IntPtr(1); 
      } 
      // Skype sends our program messages using WM_COPYDATA. the data is in lParam 
      if (msg == NativeCalls.WM_COPYDATA && wParam == NativeCalls.HWND_BROADCAST) 
      { 
       COPYDATASTRUCT data = (COPYDATASTRUCT)Marshal.PtrToStructure(lParam, typeof(COPYDATASTRUCT)); 
       StatusTextBox.Items.Add(data.lpData + Environment.NewLine); 
       // Check for connection 
       //if (data.lpData.IndexOf("CONNSTATUS ONLINE") > -1) 
        // ConnectButton.IsEnabled = false; 
       // Check for calls 
       IsCallInProgress(data.lpData); 
       handled = true; 
       return new IntPtr(1); 
      } 

      return IntPtr.Zero; 
     } 

任何人都可以指导我,我错过了什么。谢谢

+1

您正在混淆您的类库。这是HwndHost.WndProc()方法的重写,仅用于WPF应用程序。 Winforms使用* Message *结构。只要让IntelliSense自动完成你的覆盖,不能搞乱它。 –

+0

可能重复[如何在Windows窗体应用程序中使用此WndProc?](http://stackoverflow.com/questions/23220111/how-to-use-this-wndproc-in-windows-forms-application) – LarsTech

回答

1

您的方法签名不正确,Form.WndProc您被覆盖返回void

protected virtual void WndProc(ref Message m)

我不知道你在哪里得到这些代码,从端口C++可能?但它不适用于WinForms表单。

+0

只看这个网址http://code.google.com/p/sharpdx/source/browse/Source/SharpDX/Win32/MessageFilterHook.cs?name=2.4.2,这里你会看到使用的同类型的wndproc签名。 – Thomas

+0

请参阅此链接http://www.pinvoke.net/default.aspx/Delegates/WndProc.html – Thomas

相关问题