Problem capturing the titles of one window
Okay, I have this code below just to illustrate what my problem is, I want to capture the title of the active window and display that in the output. And then it would not do anything unless the user switched to another window. For that it works fine, but I also want it to log all the titles in the active window, so for example if I open firefox( my homepage is google), it would log the google part but if I continue browsing it doesn't log all the other new websites. So I'm just looking for a code that will log all the new titles regardless if you switched between those windows. You can try the code below and have two windows open and switching between them will output the titles, but if you just have one window and you're just browsing that it doesn't log the new titles, just the first one. I hope I've made it clear what I'm trying to do, maybe this is the wrong function call so I hope someone can tell me that but if it's right I'd appreciate if someone could fix it for or give me a hint or two thanks.
Code:
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
char name[MAX_PATH];
HWND currentWin = GetForegroundWindow();
HWND temporaryWin;
int main(){
while(1){
temporaryWin = currentWin;
currentWin = GetForegroundWindow();
if(temporaryWin != currentWin){
GetWindowText(currentWin, name, 256);
cout << name << endl;}}
return 0;
}