SendMessage to Control WMP

SendMessage to Control WMP

先用 spy 得到 wmp 的 windows class 及 caption,並只觀察「WM_COMMAND」message,可發現當 pause、stop、resume 時,wParam 參數會隨之變化。

 
void main(int argc, char** argv)
{
    if (argc> 1)
    {
        int n = atoi(argv[1]);
        HWND wmp = FindWindow("WMPlayerApp", "Windows Media Player");
 
        switch(n)
        {
            case 0: //pause,play
            SendMessage(wmp, WM_COMMAND, 18808, 0);
            break;
           
            case 1: //stop
            SendMessage(wmp, WM_COMMAND, 18809, 0);
            break;
           
            case 2: //next
            SendMessage(wmp, WM_COMMAND, 18811, 0);
            break;
           
            case 3: //prev
            SendMessage(wmp, WM_COMMAND, 18810, 0);
            break;
 
            case 4: //random
            SendMessage(wmp, WM_COMMAND, 18842, 0);
            break;
        }
    }
}

 

Dotblogs 的標籤: ,