Your window procedure is wrong:
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
Note that the msg
parameter is an Integer
, not a string. This should be giving you a compile-time error, so I don't know what you mean about it crashing your app, though.
You need the Windows header files to find out the ID of the WM_APPCOMMAND
message, or they're sometimes given in the documentation. In this case, it is. The value is &H0319
(in VB hex notation).
So change the code to look like this:
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