Finding windows

This is a discussion on Finding windows within the C++ Programming forums, part of the General Programming Boards category; I'm trying to get the process name of a window that changes, but always contains a certain substring.. is there ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    67

    Finding windows

    I'm trying to get the process name of a window that changes, but always contains a certain substring.. is there any way to do this without knowing the process and only knowing part of the window? I've heard to use EnumWindows.. but I don't know how it works and how to get window titles using it. Thanks

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    55
    EnumWindows takes a function pointer to a callback function which is passed the window handles one at a time (and an application-defined LPARAM):
    Code:
    BOOL CALLBACK
    enumWindowsProc( HWND hwnd, LPARAM lp)
    {
        char buf[ BUFSIZE];
        GetWindowText( hwnd, buf, BUFSIZE);
        // check it for substring ...
        return TRUE; // or FALSE to end enumeration
    }
    
    ...
    EnumWindows( enumWindowsProc, 0);

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    67
    thanks, I got it.. I essentially used that.. my code is

    Code:
    // check if a window is the one you're looking for
    BOOL CALLBACK checkWindow(HWND hwnd,LPARAM param)
    {
    	// where to copy the window title
    	char window_title[128] = {0};
    	// politely ask the target window to copy its title into our buffer
    	SendMessageA(hwnd,WM_GETTEXT,sizeof(window_title),(LPARAM)(char*)window_title);
    	// if the target window title is bigger than the current window title, null terminate the target window title,
    	// otherwise, null terminate the current window title
    	((sizeof(target_windowtitle)>sizeof(window_title)) ? target_windowtitle[sizeof(window_title)-1] : window_title[sizeof(target_windowtitle)-1]) = 0;
    	// search for our wanted title inside the passed title,
    	// and if it's found...
    	if(!strcmp(lowercase(window_title),lowercase(target_windowtitle)))
    	{
    		// cast our parameter to a pointer and set its target to the current window (AKA success)
    		*(HWND*)param = hwnd;
    		// stop checking the windows
    		return false;
    	}
    	// otherwise keep checking windows
    	else return true;
    }

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You should have read nucleon's post, or MSDN:
    Quote Originally Posted by MSDN
    EnumWindows continues until the last top-level window is enumerated or the callback function returns FALSE.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 07:14 AM
  2. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  3. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21