为什么 WM_APPCOMMAND LPARAM 必须乘以 65536 [英] Why do WM_APPCOMMAND LPARAM have to be multiplied by 65536

查看:28
本文介绍了为什么 WM_APPCOMMAND LPARAM 必须乘以 65536的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试控制主音量.我能够成功地做到这一点:

I am trying to control the master volume. I am able to succesfully do that with this:

HWND mainhwnd = CreateWindow(szWindowClass, _T("window-noit-ext-profilist"), 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, wcex.hInstance, NULL);
if (!mainhwnd) {
    MessageBox(NULL, _T("Profilist: Call to CreateWindow failed!"), _T("window-noit-ext-profilist"), NULL);
    return 1;
}


SendMessage(mainhwnd, WM_APPCOMMAND, (WPARAM)mainhwnd, (LPARAM)(APPCOMMAND_VOLUME_MUTE * 65536)); // mute

SendMessage(mainhwnd, WM_APPCOMMAND, (WPARAM)mainhwnd, (LPARAM)(APPCOMMAND_VOLUME_DOWN * 65536)); // vol down

SendMessage(mainhwnd, WM_APPCOMMAND, (WPARAM)mainhwnd, (LPARAM)(APPCOMMAND_VOLUME_UP * 65536)); // vol up

为什么我必须乘以 65,536?文档没有说明这一点.如果我不乘,那么它不起作用.

Why do I have to multiply by 65,536? The docs do not state this. IF I don't multiply, then it doesn't work.

推荐答案

对于 WM_APPCOMMAND,lParam 参数 将三个值打包成一个整数.

For WM_APPCOMMAND, the lParam parameter packs three values in a single integer.

低16bit字dwKeys,表示各种虚拟按键是否按下.

The lower 16bit word, dwKeys, indicates whether various virtual keys are down.

较高的 16 位字包含两个字段:最高 4 位,uDevice,指定正在生成输入事件的输入设备.低 12 位,cmd,包含应用命令.

The higher 16bit word packs two fields: the highest 4 bits, uDevice, specifies the input device that is generating the input event. The lower 12 bits, cmd, contains the application command.

乘以 65536 与向左移动 16 位相同(因为 65536 = 0x10000 十六进制).因此,当您使用 APPCOMMAND_VOLUME_UP * 65536 发送消息时,您指定的 cmdAPPCOMMAND_VOLUME_UP,而 uDevice> 和 dwKeys 都为零.

Multiplying by 65536 is same as bit shifting by 16 bits to the left (because 65536 = 0x10000 in hexadecimal). So, when you send the message with APPCOMMAND_VOLUME_UP * 65536, you are specifying the cmd is APPCOMMAND_VOLUME_UP, and the uDevice and dwKeys are both zero.

这篇关于为什么 WM_APPCOMMAND LPARAM 必须乘以 65536的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆