2010-03-08 45 views

Trả lời

30

Vì bạn không thể xác định một WndProc trực tiếp trong WPF, bạn cần phải có được một HwndSource, và thêm một cái móc với nó:

public Window1() 
{ 
    InitializeComponent(); 

    this.SourceInitialized += Window1_SourceInitialized; 
} 

private void Window1_SourceInitialized(object sender, EventArgs e) 
{ 
    WindowInteropHelper helper = new WindowInteropHelper(this); 
    HwndSource source = HwndSource.FromHwnd(helper.Handle); 
    source.AddHook(WndProc);  
} 

const int WM_SYSCOMMAND = 0x0112; 
const int SC_MOVE = 0xF010; 

private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) 
{ 

    switch(msg) 
    { 
     case WM_SYSCOMMAND: 
      int command = wParam.ToInt32() & 0xfff0; 
      if (command == SC_MOVE) 
      { 
      handled = true; 
      } 
      break; 
     default: 
      break; 
    } 
    return IntPtr.Zero; 
} 
+0

okay, 1 cho bạn; bài học kinh nghiệm cho tôi :) –

+0

WndProc nên trở lại như thế nào? IntPtr.Zero? – naeron84

+0

Nó hoạt động, giá trị trả lại không quan trọng. Vì vậy, IntPrt.Zero là tốt. – naeron84

Các vấn đề liên quan