我想使用 C++将WM_APPCOMMAND发送到 Spotify
我当前的代码如下所示:
DWORD dwThreadId = GetCurrentThreadId();
HDESK hDesktop = GetThreadDesktop(dwThreadId);
EnumWindows((WNDENUMPROC)&WndEnumProc, 0);
还有:
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;
}
头文件:
class Remote
{
public:
static BOOL CALLBACK WndEnumProc(HWND, LPARAM);
};
问题是它返回0SpotifyMainWindow。它打印 1 或 0(SendMessage() 的返回值)和句柄的类。总而言之,这意味着它尝试将消息发送到 SpotifyMainWindow 但无法发送。
如何解决这个问题?