Thread: Problem capturing the titles of one window

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    4

    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;
        }
    Last edited by newbie421; 06-07-2007 at 11:39 PM.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    May-be you should compare the title of the active window with the previous title and not if it is a different window?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Jun 2007
    Posts
    4
    Quote Originally Posted by anon View Post
    May-be you should compare the title of the active window with the previous title and not if it is a different window?
    Okay thanks, it just never crossed my mind that I could do this, but I'm still having a problem. I think I kind of know what I should do, that is capture the title and display that, then capture the title again under a different name and compare if they both are same, if they are not, then display the title again. I tried this like putting sleep intervals in between of like 10 seconds etc and then just visiting 2-3 diff sites and it captured them all, but I can't find a way to put all this like in a loop, function, or omg goto statement so it's constantly checking for change in title. I hate to ask for this, but I hope you or someone can actually post the actual code cuz I just can't think of a way how I would put it all together. Thanks. That's the code I have, I just need a way to put it in a while loop and then maybe make another boolean function which returns true if it changed or false etc but I don't know how to do this?
    Code:
    GetWindowText(GetForegroundWindow(), title, GetWindowTextLength(GetForegroundWindow()) + 1);
      cout << title<< endl; 
      GetWindowText(GetForegroundWindow(), title2, GetWindowTextLength(GetForegroundWindow()) + 1);
      if(!strstr(title, title2))

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. Capturing window content
    By leojose in forum Windows Programming
    Replies: 4
    Last Post: 06-30-2005, 08:30 AM
  3. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 05:55 PM
  4. How to change window style at runtime?
    By Mr. Bitmap in forum Windows Programming
    Replies: 5
    Last Post: 06-09-2002, 04:49 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM