Thread: Next top window

  1. #1
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125

    Next top window

    how could i retrieve the handle to the window that is put on top next. for example if you had an app open and hit a button ,"Retrieve handle" and then go to the window bar on the bottom and click a window. that window opens . how would you retrieve the handle to that window? i hope i explained it good enough and you know what i'm taking about!
    In a perfect world every dog would have a home and every home would have a dog.
    Visit My Web Site, Canine Programming
    I use Win32 API

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Not sure I totally understand what you are doing....but perhaps GetForegroundWindow() ??

  3. #3
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125
    i think i would use GetForegroundWindow() but how would I know that the foregound window has changed from my porgram to another one, and then get the other window's handle.
    I hope that makes a little more sense...
    thank you in advance.
    In a perfect world every dog would have a home and every home would have a dog.
    Visit My Web Site, Canine Programming
    I use Win32 API

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You could trap WM_KILLFOCUS...this is sent when the input focus is lost from your window.....the wParam of that message is the window that gets input focus after you......

    Does that help?

  5. #5
    Registered User canine's Avatar
    Join Date
    Sep 2001
    Posts
    125
    I can't get it to work, mabey a code sample? thanx anyway
    Last edited by canine; 03-20-2002 at 08:11 PM.
    In a perfect world every dog would have a home and every home would have a dog.
    Visit My Web Site, Canine Programming
    I use Win32 API

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by canine
    I can't get it to work, mabey a code sample? thanx anyway
    Hmm..I see your point.........the SDK docs say that WM_KILLFOCUS can pass NULL as the wParam....but it seems to do this a lot....

    Anyway...I tried the following...it is still not foolproof.....

    Code:
    case WM_KILLFOCUS:
               hNewFocus = (HWND)wParam; //First Try
               if(hNewFocus == NULL)
               Sleep(2000);
               hNewFocus = GetForegroundWindow();//Second Try
               if(hNewFocus == NULL)
               MessageBox(hwnd,"Error, could not find window","",MB_OK);
               else
               SendMessage(hNewFocus,WM_SETTEXT,0,
                           (LPARAM)"Damn you!! You stole my focus!!");
               break;
    That code tries to find the new window and change its title......

    If NULL is passed by WM_KILLFOCUS, it waits 2 seconds and tries GetForegroundWindow().......

    Its still far from practicle though...........

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  2. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  3. Taskbars; 'Cannot create top level child window'
    By Gerread in forum Windows Programming
    Replies: 4
    Last Post: 05-18-2007, 06:41 AM
  4. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  5. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM