cwinapihwnd

How to print the title of the active window in C - WinAPI


Well i have only one semester of C so i am little confused with HWND and how to use it. I just want to print active window. I found - GetActiveWindow, GetForegroundWindow.

But i just dont understand how to use this function to print that active window.

I was trying to do something like.

HWND GetActiveWindow();
printf("%s", GetActiveWindow);

But that is probably bad use and not working.
If someone can gave me a working example i will be very thankfull.


Solution

  • TCHAR buf[256], out[280];
    
    GetWindowText( GetActiveWindow(), buf, sizeof buf / sizeof *buf );
    wsprintf( out, TEXT( "Window text: %s\n" ), buf );