window handles

This is a discussion on window handles within the Windows Programming forums, part of the Platform Specific Boards category; How do I find the handle of a window that is currently in use? Is there any way to do ...

  1. #1
    Unregistered
    Guest

    window handles

    How do I find the handle of a window that is currently in use? Is there any way to do this?
    What I want to do is something like the following:

    Code:
    HWND hWnd;
    hWnd = /* something*/;
    Thanks

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Go to MSDN and look up FindWindow()

  3. #3
    Unregistered
    Guest
    I'm trying to get the handle of a dialog box window. Would this function work for that? If so, could you give me a code example of how to use this function? (The stuff at MSDN was confusing). IF not, is there a way to return the handle of a dialog box ?

    Thanks

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    Code:
    The FindWindow function retrieves the handle to the top-level 
    window whose class name and window name match the specified 
    strings. This function does not search child windows. 
    
    HWND FindWindow(
    
        LPCTSTR lpClassName,	// pointer to class name
        LPCTSTR lpWindowName 	// pointer to window name
       );	
    Parameters
    
    lpClassName
    
    Points to a null-terminated string that specifies the class name or 
    is an atom that identifies the class-name string. If this parameter 
    is an atom, it must be a global atom created by a previous call to 
    the GlobalAddAtom function. The atom, a 16-bit value, must be 
    placed in the low-order word of lpClassName; the high-order 
    word must be zero. 
    
    lpWindowName
    
    Points to a null-terminated string that specifies the window name 
    (the window’s title). If this parameter is NULL, all window names 
    match. 
    
    Return Values
    
    If the function succeeds, the return value is the handle to the 
    window that has the specified class name and window name.
    If the function fails, the return value is NULL. To get extended 
    error information, call GetLastError.
    that is what my reference says

    [EDIT]Made it readable by Lower-Resolution Computers[/EDIT]
    Last edited by Okiesmokie; 05-12-2002 at 10:15 AM.
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  5. #5
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    I think you use GetDlgItem() for dialogs. But that might be control only.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    hWnd=GetActiveWindow();

    but only if the window was created by your app.
    (I am assuming you don't use threads)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

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, 09: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, 03:33 PM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM

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