0

I have the HWND of a window which has some audio output. How can I capture the magnitude like the windows mixer is doing it?

this is the code how to get the HWND of all windows:

BOOL CALLBACK FindWindowBySubstr(HWND hWnd, LPARAM substring)
{
    const DWORD TITLE_SIZE = 1024;
    TCHAR windowTitle[TITLE_SIZE];

    std::string sTitle = CWinAPI::GetTheWindowText(hWnd);
    unsigned int nTitleLength = CWinAPI::GetWindowTextlength(hWnd);
    RECT rect = CWinAPI::GetWindowRectangle(hWnd);

    if(nTitleLength > 0)
    {
        vecAllWindows.push_back(CWinAPI::SWindow(hWnd, sTitle, nTitleLength, rect));
    }
    return true; // Need to continue enumerating windows 
}

void CWinAPI::ListAllWindows(bool bShowWindowsWithoutTitle)
{
    vecAllWindows.clear();
    const TCHAR substring[] = TEXT("A");
    EnumWindows(FindWindowBySubstr, (LPARAM)substring);
}

from that list I can select the window I am looking for.

The following picture is the Microsoft windows audio mixer:

enter image description here

sorry, that this is in german, but I hope everyone understands... What i am trying to do is to capture the actual values of the current audio (magnitude) of my specific window HWND.

Is it possible? Is it also possible with the windows api? If so: which command can help me?

EDIT:

This code gives me the processID (maybe this is more usefull)

DWORD CWinAPI::GetProcessIDFromHWND(HWND hWnd)
{
    return GetWindowThreadProcessId(hWnd, NULL);
}
Thomas
  • 2,093
  • 3
  • 21
  • 40
  • Audio is not tied to windows. Chances are, those apps have explicitly registered themselves with the OS for managing their audio output, or are otherwise using an audio API that the OS manages implicitly – Remy Lebeau Sep 15 '18 at 19:15
  • @RemyLebeau(apps have explicitly registered themselves with the OS for managing their audio output) if they do, they are in the windows audio mixer app right? – Thomas Sep 15 '18 at 19:22
  • @RemyLebeau okay, I am using right now the command GetWindowThreadProcessId(). Now I have the processId from the window from which I whant to have the sound... does this help me? – Thomas Sep 15 '18 at 19:37
  • @Ron I don't want to set any audio... I have a process, which is doing audio (this process is not written by me) I just want to capture the audio which this process is producing – Thomas Sep 15 '18 at 19:41
  • 1
    AFAIK, you can't capture another program's audio, unless you hook into the audio subsystem/hardware itself – Remy Lebeau Sep 15 '18 at 19:47
  • what I am absolutly not understand is: windows has this audio mixer... (see picture above) they can capture the actual audio level of each process... why should it be impossible for a programmer to capture it? there must be a way to do that – Thomas Sep 15 '18 at 19:52
  • Windows does mixing internally and even reports levels on request, but it does not mean it exposes individual streams for application to capture. No you cannot capture audio from specific windows/process/application/session without hooking APIs as @RemyLebeau wrote above. – Roman R. Sep 15 '18 at 20:15
  • + another duplicate is [Capture audio of a single application on Windows 7](https://stackoverflow.com/q/6084550/868014) + yet another one [How to capture audio from specific application and route to specific audio device in Windows 7?](https://stackoverflow.com/a/31623980/868014) – Roman R. Sep 15 '18 at 20:17
  • @Thomas the audio mixer is part of the OS. System tools have various capabilities that normal apps simply don't have access to – Remy Lebeau Sep 15 '18 at 21:56
  • @Thomas when you say "why shohuld it be impossible for a programmer to capture it" consider a malware recording all your Skype or other IM calls;) – Rudolfs Bundulis Sep 16 '18 at 15:14
  • @RudolfsBundulis you can link into the global audioOutput. So there are malwares which have access to it... so I think this is not the best example ;) – Thomas Sep 18 '18 at 17:44

0 Answers0