2013-03-18 140 views
0

我仍然試圖找出與此錯誤發生:包含類型不實現接口IMessageFilter

OCR.test.IMessageFilter.PreFilterMessage(ref System.Windows.Forms.Message): containing type does not implement interface System.Windows.Forms.IMessageFilter

這裏是我的代碼:

bool IMessageFilter.PreFilterMessage(ref Message m) // Error with this line 
{ 
    TwainCommand cmd = tw.PassMessage(ref m); 
    if (cmd == TwainCommand.Not) 
     return false; 

    switch (cmd) 
    { 
     case TwainCommand.CloseRequest: 
     { 
      EndingScan(); 
      tw.CloseSrc(); 
      break; 
     } 
     case TwainCommand.CloseOk: 
     { 
      EndingScan(); 
      tw.CloseSrc(); 
      break; 
     } 
     case TwainCommand.DeviceEvent: 
     { 
      break; 
     } 
     case TwainCommand.TransferReady: 
     { 
      ArrayList pics = tw.TransferPictures(); 
      EndingScan(); 
      tw.CloseSrc(); 
      picnumber++; 
      for (int i = 0; i < pics.Count; i++) 
      { 
       IntPtr img = (IntPtr)pics[i]; 
       PicForm newpic = new PicForm(img); 
       newpic.MdiParent = this; 
       int picnum = i + 1; 
       //newpic.Text = "ScanPass " + picnumber.ToString() + "_Pic " + picnum.ToString(); 
       newpic.Show(); 
      } 
      break; 
     } 
    } 

    return true; 
} 
+0

我覺得你的一個類需要實現IMessageFilter接口。 – 2013-03-18 09:53:12

+0

我該如何執行?你能告訴我一些例子嗎? – MrKrahoz 2013-03-18 10:16:50

+0

查看本教程以瞭解如何實現接口:http://msdn.microsoft.com/en-us/library/aa288461(v=vs.71).aspx。您需要在您的方法中需要的任何類型上實現'IMessageFilter'接口。你定義的是'Message'和'TwainMessage'類嗎? – 2013-03-18 14:12:12

回答

2

類,你實現PreFilterMessage方法需要從IMessageFilter接口派生。你可能錯過了它

public class Foo: IMessageFilter 
{ 
    bool IMessageFilter.PreFilterMessage(ref Message m) 
    { 
     // your code 
    } 
} 
+0

以下是完整的錯誤消息: 錯誤\t \t 2「OCR.test.IMessageFilter.PreFilterMessage(參照System.Windows.Forms.Message)」:含有型不實現接口「System.Windows.Forms.IMessageFilter」 \tÇ :\ Users \ Faesal \ Documents \ Visual Studio 2008 \ Projects \ OCR \ OCR \ test.cs OCR – MrKrahoz 2013-03-18 10:16:04

+0

@MrKrahoz - 重讀斯羅德里格茲的答案。你有一個名爲test的類沒有實現IMessageFilter接口。你需要改變你的測試類到這樣的:'公共類測試:IMessageFilter' – 2013-03-18 15:52:08