Thread: window handles

  1. #1
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62

    window handles

    i need to get the handle to the top window from any other app. GetActiveWindow needs my prog to be in the same thread so that doesnt work.

    Any ideas? Please help.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    How about FindWindow()?

  3. #3
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62
    i know about that but i need to get the handle without knowing the window name or class name.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Here's some other window handle returning fns to look into - if you haven't already done so:

    1. WindowFromPoint
    2. WindowFromDC
    3. GetWindow.
    4. EnumChildWindows (wnd handle sent to EnumChildProc
    )
    5. EnumWindows (wnd handle sent to EnumWindowsProc
    )

  5. #5
    _Unregistered_
    Guest
    How can I use Enum windows for Win3.x app? And not crash...
    What's the correct way to use it, when to put it? Loop is ideal for this application, is it?

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by _Unregistered_
    How can I use Enum windows for Win3.x app? And not crash...
    What's the correct way to use it, when to put it?
    According to the SDK you need 95 or NT3.1 AT LEAST........

    Why are you using such an outdated OS?

    Originally posted by _Unregistered_

    Loop is ideal for this application, is it?
    Nope....you need a callback....if you have an os that allows this fuction you would do something along the lines of

    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    BOOL CALLBACK EnumProc(HWND hwnd,LPARAM lParam);
    
    int nNoWnd = 0;
    
    int main(void)
    
    {
    	cout << "Enumerating..." << endl;
    	EnumWindows((WNDENUMPROC) EnumProc,NULL);
    	
    	cout << "Total of " << nNoWnd << " windows" << endl;
     
        return 0;
    }
    
    
    BOOL CALLBACK EnumProc(HWND hwnd,LPARAM lParam)
    {
    	char buff[MAX_PATH+1];
    
    	if(GetWindowText(hwnd,buff,MAX_PATH+1) <= 0)
    		cout << "\"No Title\"" << endl;
    
    	else
    		cout << buff << endl;
    
    	nNoWnd++;
    	
        
        return TRUE;
    }

  7. #7
    _Unregistered_
    Guest

    Post Thanks Fordy!

    thanks for the code. outdated OS? just my outdated compiler.

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, 08:14 AM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM