Reputation: 37268
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
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.
Upvotes: 3
Views: 873
Reputation: 21956
For WM_APPCOMMAND, the lParam
parameter packs three values in a single integer.
The lower 16bit word, dwKeys
, indicates whether various virtual keys are down.
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.
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.
Upvotes: 8