Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Collapse the table of content
Expand the table of content


Returns the top-level CWnd whose window class is given by lpszClassName and whose window name, or title, is given by lpszWindowName.

static CWnd* PASCAL FindWindow(
   LPCTSTR lpszClassName,
   LPCTSTR lpszWindowName 


Points to a null-terminated string that specifies the window's class name (a WNDCLASS structure). If lpClassName is NULL, all class names match.


Points to a null-terminated string that specifies the window name (the window's title). If lpWindowName is NULL, all window names match.

Identifies the window that has the specified class name and window name. It is NULL if no such window is found.

The CWnd* may be temporary and should not be stored for later use.

This function does not search child windows.

// activate an application with a window with a specific class name
BOOL CMyApp::FirstInstance()
   CWnd *pWndPrev, *pWndChild;

   // Determine if a window with the class name exists...
   pWndPrev = CWnd::FindWindow(_T("MyNewClass"), NULL);
   if (NULL != pWndPrev)
      // If so, does it have any popups?
      pWndChild = pWndPrev->GetLastActivePopup();

      // If iconic, restore the main window
      if (pWndPrev->IsIconic())

      // Bring the main window or its popup to the foreground

      // and you are done activating the other application
      return FALSE;

   return TRUE;

Header: afxwin.h

Community Additions

© 2015 Microsoft