0

I am using WMP SDK to control Windows Media Player. I first created a new project using Windows Media Player Plug-in Wizard and then added code which communicates with my application using a named pipe. When my application needs music to be muted, for example, it send a message to the WMP plugin and then the plugin mutes the music:

CComPtr<IWMPSettings> settings;
if (SUCCEEDED(core_->get_settings(&settings)))
{
    settings->put_mute(VARIANT_TRUE);
}

It works, and when I send commands, they get executed, but the UI doesn't get updated. So, for example, if I send a mute command, music gets muted (there's no sound), but the mute button still displays as if music isn't muted. To prove this, I can change the skin at this point or skip to another song, and the UI gets updated and correctly shows mute state. If I click it, it unmutes, and then again displays unmuted state (which is now the correct state).

So, is there any way to force refreshing of the UI, for example, or some other workaround?

kolufild
  • 712
  • 1
  • 9
  • 20

1 Answers1

0

Yes. If put_mute isn't working with your window dialog, you can use Interop and WM_APPCOMMAND as mentioned in this related question. Specifically, you'll want to use APPCOMMAND_VOLUME_MUTE.

Merging the two code snippets, we get:

private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
private const int WM_APPCOMMAND = 0x319;

[DllImport("user32.dll")]
public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

CComPtr<IWMPSettings> settings;
if (SUCCEEDED(core_->get_settings(&settings)))
{
    SendMessageW(new WindowInteropHelper(this).Handle, WM_APPCOMMAND, new (IntPtr)APPCOMMAND_VOLUME_MUTE);
}

(Warning: untested code.)

This seems suboptimal, and every bit of documentation I could find indicates your prior solution should just work. You may want to consider contacting Microsoft about this one.

Community
  • 1
  • 1
MrGomez
  • 23,788
  • 45
  • 72
  • You seem to have merged C# and C++ code here. Also, I don't understand how expression `new WindowInteropHelper(this).Handle` will resolve to a handle of the WMP window. – kolufild Apr 05 '12 at 10:27