2009-08-26 53 views
0

當我使用鼠標滾輪滾動WPF工具包的DataGrid在Vista的64機我得到一個神祕的低級錯誤:怎樣才能避免溢出當輪scolling WPF的DataGrid

at System.IntPtr.op_Explicit(IntPtr value) 
    at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
    at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
    at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
    at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) 
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) 

我記錄一個issue on CodePlex

但有沒有人發現了一種已經解決這個問題?

回答

0

此錯誤是微軟的庫中,這是令人難以置信的是它仍然存在。

爲了規避它假設你有Visual Studio和你是開發商:

右鍵單擊該項目並選擇 - >屬性

選擇Build選項卡。 平臺目標:86

然後重新生成項目。

背景:

我有一個完美的程序在32位操作系統的工作。然後我買了一臺帶有Windows 7 64位操作系統的新筆記本電腦。安裝了Visual Studio和我的解決方案。使用WndProc處理Windows消息來處理用戶輸入的一個項目失敗。你的類似處理鼠標消息。

發現微軟的Visual Studio團隊沒有補丁後,我改變了目標平臺從「任何CPU」到「86」,它重新部署到64位操作系統,只見程序正常運行。這是唯一的變化。

0

我只是自己碰到這個問題。

不知道,如果它仍然是有用的給你,但這裏是我在找到固定的情況下任何人都需要它。

我發現this線程在OpenTK項目,聞起來很像我在一臺vista 64機器中使用WPF項目的問題。就像在該線程中解釋的那樣,問題似乎是MouseWheel消息的wParam上的一個未處理的單詞。溢出異常發生在HwndMouseInputProvider調用中,當它試圖將wParam IntPtr轉換爲int時。

所以解決方法是增加一個鉤到主窗口上濾波器窗口的消息。掛鉤回調檢查WM_MOUSEWHEEL消息的wparam的值。如果該值溢出,則值移位器周圍以恢復正確的位信息,當前消息被標記爲已處理,並且新消息與新值一起發佈。

public partial class Window1 : Window 
{  
    private const int WM_MOUSEWHEEL = 0x020A; 

    public Window1() 
    { 
     InitializeComponent(); 

     SourceInitialized += (o, e) => 
     { 
      HwndSource source = PresentationSource.FromVisual(this) as HwndSource; 
      source.AddHook(WndProc); 
     }; 
    } 

    [DllImport("user32.dll")] 
    private static extern IntPtr PostMessage(IntPtr hwnd, IntPtr msg, IntPtr wParam, IntPtr lParam); 

    private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) 
    { 
     switch (msg) 
     { 
      case WM_MOUSEWHEEL: 
       // Check that wParam won't cause an OverflowException 
       if ((long)wParam >= (long)Int32.MaxValue) 
       { 
        // Filter the evenet 
        handled = true; 

        HwndSource source = PresentationSource.FromVisual(this) as HwndSource; 
        // Repost the event with the proper value 
        PostMessage(source.Handle, new IntPtr(msg), new IntPtr((long)wParam <<32>> 32), lParam); 
       } 

       break; 
     } 

     return IntPtr.Zero; 
    } 

這很適合我。如果任何人都可以添加或更正任何東西會很棒! K