2013-08-02 5 views
0

내 winforms 프로젝트를 WPF로 변환하고 WPF를 배우면서 수행 중입니다. WPF VB.NET WM_APPCOMMAND

나는이 코드는 미디어 키보드 또는 미디어 센터 리모컨을 누르면 버튼을 감지이 코드

에 문제가 다 퉜다.

Protected Overrides Sub WndProc(ByRef msg As Message) 
    If msg.Msg = &H319 Then 
     ' WM_APPCOMMAND message 
     ' extract cmd from LPARAM (as GET_APPCOMMAND_LPARAM macro does) 
     Dim cmd As Integer = CInt(CUInt(msg.LParam) >> 16 And Not &HF000) 
     Select Case cmd 
      Case 13 
       MessageBox.Show("Stop Button") 
       Exit Select 
      Case 47 
       MessageBox.Show("Pause Button") 
       Exit Select 
      Case 46 
       MessageBox.Show("Play Button") 
       Exit Select 
     End Select 
    End If 
    MyBase.WndProc(msg) 
end sub 

WPF에서 작동 시키거나 유사한 작업을 수행 할 수있는 방법이 있는지 궁금합니다.

편집

내 최신 시도, 나는 그것이 어쩌면 잘못 될 수 있도록 C 번호로 변환하려고 노력했다.

Dim src As HwndSource = HwndSource.FromHwnd(New WindowInteropHelper(Me).Handle) 
src.AddHook(New HwndSourceHook(AddressOf WndProc)) 

Public Function WndProc(hwnd As IntPtr, msg As Integer, wParam As IntPtr, lParam As IntPtr, ByRef handled As Boolean) As IntPtr 

'Do something here 
If msg = "WM_APPCOMMAND" Then 
MessageBox.Show("dd") 
End If 

Return IntPtr.Zero 
End Function 

은 내가 곧 정상 궤도에 오전 또는 내가 해제 방법입니다 (이것은 단지 내 응용 프로그램 충돌)?

+0

그래서 당신은 WPF 응용 프로그램에서의 WndProc을 대체하려면? –

+0

예, 멀티미디어 키를 쉽게 캡처 할 수있는 경우가 아니면. – Mattigins

+0

가능한 중복 [WPF에서 WndProc 메시지를 처리하는 방법] (http://stackoverflow.com/questions/624367/how-to-handle-wndproc-messages-in-wpf) –

답변

3

귀하의 윈도우 프로 시저가 잘못 다음 msg 매개 변수가 Integer 아닌 문자열

Public Function WndProc(hwnd As IntPtr, msg As Integer, wParam As IntPtr, lParam As IntPtr, ByRef handled As Boolean) As IntPtr 

    'Do something here 
    If msg = "WM_APPCOMMAND" Then 
     MessageBox.Show("dd") 
    End If 

    Return IntPtr.Zero 
End Function 

하는 것으로. 이 당신에게 컴파일 타임 오류를 제공해야합니다, 그래서 당신의 응용 프로그램을 충돌에 대해 당신이 무슨 뜻인지 모르겠지만.

WM_APPCOMMAND 메시지의 ID를 확인하려면 Windows 헤더 파일이 필요하며, 때때로 문서에 나와 있습니다. 이 경우 it is입니다. 값은 &H0319 (VB 16 진수 표기}입니다.

그래서 같이하는 코드를 변경 :

Private Const WM_APPCOMMAND As Integer = &H0319 

Public Function WndProc(hwnd As IntPtr, msg As Integer, wParam As IntPtr, lParam As IntPtr, ByRef handled As Boolean) As IntPtr 

    ' Check if the message is one you want to handle 
    If msg = WM_APPCOMMAND Then 
     ' Handle the message as desired 
     MessageBox.Show("dd") 

     ' Indicate that you processed this message 
     handled = True 
    End If 

    Return IntPtr.Zero 
End Function 
+0

고맙습니다. 완벽하게 작동합니다.내가 추가 할 필요가있는 것은'Dim cmd As Integer = CInt (CUInt (lParam) >> 16 and Not HF000)'였고 이전과 같이 작동합니다. – Mattigins