Hi All,
I dont know anything about windows programming yet.I am trying to Get the active windows title someone advised me to check in windows programming somebody please help me with this.
What I Actually Want ?
I want to write a function that gives me active window title (For example if i open Chrome it should give me its title if i open some other application it should give me title of that window)
#include <windows.h>
#include <string>
using std::string;
string GetActiveWindowTitle()
{
char wnd_title[256];
HWND hwnd=GetForegroundWindow(); // get handle of currently active window
GetWindowText(hwnd,wnd_title,sizeof(wnd_title));
return wnd_title;
}
//
// Callback function. It will be called by EnumWindows function
// as many times as there are windows
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
if(IsWindowVisible(hwnd)) // check whether window is visible
{
char wnd_title[256];
GetWindowText(hwnd,wnd_title,sizeof(wnd_title));
cout <<wnd_title<<endl;
}
returntrue; // function must return true if you want to continue enumeration
}
int main()
{
EnumWindows(EnumWindowsProc,0);
}
This code get titles of all visible (including minimized) windows on the desktop. Although there's a small problem with this code - it will also show things like "start" "program manager" or "View Available Networks (Tooltip)"