0

我想使用 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 但无法发送。

如何解决这个问题?

4

1 回答 1

3

WM_APPCOMMAND消息希望以 的高位字提供“命令” lParam,您需要执行以下操作:

SendMessage(hwnd, WM_APPCOMMAND, 0, MAKELPARAM(0,APPCOMMAND_MEDIA_PLAY_PAUSE));
于 2012-09-16T21:31:40.970 回答