我正在浏览此代码here和:
Private Sub Button3_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button3.Click
SendMessage(Me.Handle, WM_APPCOMMAND, &H200EB0,
APPCOMMAND_VOLUME_MUTE * &H10000)
End Sub
我不知道sendmessage函数的最后两个参数是什么以及这两个参数中发生了什么? “& H200EB0”和“APPCOMMAND_VOLUME_MUTE *& H10000”参数?
这是完整的代码:
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function SendMessage(ByVal hWnd As IntPtr,
ByVal Msg As UInteger, ByVal wParam As IntPtr,
ByVal lParam As IntPtr) As IntPtr
End Function
Const WM_APPCOMMAND As UInteger = &H319
Const APPCOMMAND_VOLUME_UP As UInteger = &HA
Const APPCOMMAND_VOLUME_DOWN As UInteger = &H9
Const APPCOMMAND_VOLUME_MUTE As UInteger = &H8
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
SendMessage(Me.Handle, WM_APPCOMMAND, &H30292,
APPCOMMAND_VOLUME_UP * &H10000)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button2.Click
SendMessage(Me.Handle, WM_APPCOMMAND, &H30292,
APPCOMMAND_VOLUME_DOWN * &H10000)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button3.Click
SendMessage(Me.Handle, WM_APPCOMMAND, &H200EB0,
APPCOMMAND_VOLUME_MUTE * &H10000)
End Sub
End Class
答案 0 :(得分:4)
SendMessage是一种可用于将指定消息发送到一个或多个窗口的方法。
文档在这里:http://msdn.microsoft.com/en-us/library/windows/desktop/ms644950%28v=vs.85%29.aspx
第一个参数是&#34;句柄&#34;消息发送到的(HWND)。第二个参数是消息ID(有关系统定义的消息,请参阅http://msdn.microsoft.com/en-us/library/windows/desktop/ms644927(v=vs.85).aspx#system_defined)。
最后两个参数可用于将更多数据传递给接收器。 - 通常两个参数都有消息相关的含义。
在你的情况下传递WM_APPCOMMAND消息(http://msdn.microsoft.com/en-us/library/windows/desktop/ms646275%28v=vs.85%29.aspx)(这里是键盘命令)。我认为第一个参数也可以是NULL(根据上面的链接,它应该是用户单击按钮或按下键的窗口的句柄),但第二个参数必须指定应该传递的命令(如一个APPCOMMAND)。第二个参数是8(根据链接页面上的列表,8 = APPCOMMAND_VOLUME_MUTE),但是我们必须进行bithift,因为信息必须在参数的高位中进行编码(即0x80000 - 即&# 39; s APPCOMMAND_VOLUME_MUTE *&amp; H10000;请参阅我链接的页面上的lParam部分。