I want to send WM_APPCOMMAND to Spotify using C++
My current code looks like that:
DWORD dwThreadId = GetCurrentThreadId();
HDESK hDesktop = GetThreadDesktop(dwThreadId);
EnumWindows((WNDENUMPROC)&WndEnumProc, 0);
There is also:
BOOL CALLBACK Remote::WndEnumProc(HWND hwnd, LPARAM lParam)
{
TCHAR className[MAX_PATH];
GetClassName(hwnd, className, sizeof(className));
string name = className;
if (name.compare("SpotifyMainWindow") == 0) {
cout << SendMessage(hwnd, WM_APPCOMMAND, 0, APPCOMMAND_MEDIA_PLAY_PAUSE) << name << endl;
}
return TRUE;
}
Header-File:
class Remote
{
public:
static BOOL CALLBACK WndEnumProc(HWND, LPARAM);
};
The problem is that it returns 0SpotifyMainWindow.
It prints 1 or 0 (return value of of SendMessage()) and the class of the handle. All in all it means that it tries to send the message to SpotifyMainWindow but is not able.
How to solve this?
The
WM_APPCOMMANDmessage expects the “command” to be supplied in the high-order word oflParam, you need to do something like: