I am setting up a plugin for KDE Connect where I pause any playing media as and when I get a call on my phone. For the Windows build of this plugin, I am currently using VK_MEDIA_PLAY_PAUSE. Is there some instruction(s) I can use to simply PAUSE or simply PLAY the media? That is, not a toggle, instruction(s) with "only one" of the two behaviours?
IF not, is there some other way I can reliably determine if there is any media playing on my system?
I have read Media Play/Pause Simulation . but a toggle is not reliable in my use case.
WM_APPCOMMAND has APPCOMMAND_MEDIA_PAUSE. Send it directly to a player if you know its HWND or send it to yourself and let DefWindowProc turn it into a shell hook event.
Related
If you use firefox (and I assume it works similarily with Chrome/Edge) or Spotify, and you press audio play/pause button, it pauses video/music you are listening to. When my headphones start running out of battery they pause audio for a moment, tell me battery is about to run out, and resume playing. Ergo, I assume there is a way to send "pause music" message, or sth similar.
So my question is: If I have an app (in this case unity game), is there a way in which I can send similar "pause" message to browsers/spotify?
Is there a way to pause the currently running media - like, the media that displays on the windows lock screen?
I wish to programmatically achieve the same thing as clicking that pause button in that image in the bottom right (except when the machine is not locked). What COM interface could I use to do this? They are very confusing to look through and there seems to be at least a couple related to media on Windows.
My application is a fullscreen window which is rendering a designated other window (from dwm), for example Google Chrome. I would like to know if it's possible to send events (such as mouse keyboard events) to the specified window.
Of course the designated window has to stay in background, and my current application on the foreground.
My application is written in C++. I'm working on Windows 7/8.
Just to put it into an answer.
Based on this question Does any program/language/library that interacts with windows do it via the WIN32 API? you should be able to use the windows API to send a windows message to any window. All you need to get is that windows handle, or you could do a broadcast to all windows.
The specific function http://msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx
Though that function will block until the windows responds and processes the message, this could hurt GUI performance. If you notice issues try implementing http://msdn.microsoft.com/en-us/library/windows/desktop/ms644951(v=vs.85).aspx instead.
Under Win2K(or later), by sending a Virtual-Key VK_LAUNCH_MEDIA_SELECT, can start a player.
If more than one player software installed, how to determine which one it will start?
A sample VBS code:
Wscript.CreateObject("Wscript.Shell").Sendkeys chr(&h88b5)
http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
http://msdn.microsoft.com/zh-cn/library/dd375731
VK_LAUNCH_MEDIA_SELECT
0xB5
Select Media key
VK_LAUNCH_MEDIA_SELECT is actually received by the system and translated into a WM_APPCOMMAND with lParam as APPCOMMAND_LAUNCH_MEDIA_SELECT. So theoretically, any program implementing a handler for this could be launched. This page (albeit old) lists default applications which listen for WM_APPCOMMAND:
Internet Explorer
Windows Help
DVD Player
CD Player
Media Player
Volume Control system tray applet
Obviously, only a few of those are actually applicable for APPCOMMAND_LAUNCH_MEDIA_SELECT.
However, I don't know how the translation mechanism actually works. It appears not every application will receive the translated WM_APPCOMMAND message. On my keyboard, I tried pressing the button which sends VK_VOLUME_UP. The volume goes up as expected because it is handled by the volume control system tray applet. However, I opened an instance of notepad.exe and monitored its messages with Spy++. It did not receive any message even when it was in the foreground. Curiously, VK_MEDIA_PLAY_PAUSE is received through WM_APPCOMMAND if the play/pause button is pressed as long as notepad.exe had the focus. I would test with VK_LAUNCH_MEDIA_SELECT, but I'm not actually sure what button that corresponds to (or whether my keyboard has it).
Thanks, for Mike Kwan's reply.
Through testing a lot of settings a program associated with a variety of audio files.
Finalized, this will depend on the CDA (CD Audio) files associated with which program.
If you set the default association for the CDA (CD Audio) files to Notepad or Paint or any other program, it can still send the same virtual key to open the corresponding program.
The foreground window can do whatever it wants in response to the WM_APPCOMMAND message, if it does not handle the message then shell hooks (HSHELL_APPCOMMAND) gets to handle it, if no hooks handle the message then Windows checks the AppKey key in the registry. (You can use Process Monitor to find the number for a specific key-press)
is there a way (on Windows XP+) to redirect the output of a window created by a process created with e.g. CreateProcess to a window of your own program?
I'd like to make a nicer GUI for ffplay.exe which is an open source video player. It is a command line tool, which opens a simple window in which it plays back the video. Can I "capture" this window and display the output in my own program somehow?
Thanks for any hints you can provide.
Start with this. Then set a timer. I realize that it isn't what you want, but I think that you need a kernel driver to accomplish seamless video capture. I suspect that people sell things for this. I think this (with a timer) is the best you will get in user space.
You are probably best off simply obtaining the HWND of the video output (use EnumWindows() and GetWindowThreadProcessId() to locate all of the HWNDs that belong to the ffplay.exe process your app is launching) and then re-position it within the confines of your own UI using SetWindowPos() or MoveWindow() as needed. You can't actually make the video HWND be a child of your UI's windows because of the process boundaries, but moving the video HWND around as your own UI moves around accomplishes almost the same effect.