HWND FindWindow(         
    LPCTSTR lpClassName,
    LPCTSTR lpWindowName
);
在VC中我怎么找到我当前项目的类名:lpClassName
我要做的操作是:
HWND hWnd = ::FindWindow("RAINFALL_CLASS", 0);

if (hWnd)
{
  ::ShowWindow(hWnd, SW_SHOWMAXIMIZED);
  AfxWinTerm();
  ExitProcess(1);
  return FALSE;
}

解决方案 »

  1.   

    GetClassName Function--------------------------------------------------------------------------------The GetClassName function retrieves the name of the class to which the specified window belongs. Syntaxint GetClassName(          HWND hWnd,
        LPTSTR lpClassName,
        int nMaxCount
    );
    ParametershWnd
    [in] Handle to the window and, indirectly, the class to which the window belongs. 
    lpClassName
    [out] Pointer to the buffer that is to receive the class name string. 
    nMaxCount
    [in] Specifies the length, in TCHAR, of the buffer pointed to by the lpClassName parameter. The class name string is truncated if it is longer than the buffer and is always null-terminated. 
    Return ValueIf the function succeeds, the return value is the number of TCHAR copied to the specified buffer.If the function fails, the return value is zero. To get extended error information, call GetLastError. 
    ResWindows 95/98/Me: GetClassNameW is supported by the Microsoft® Layer for Unicode (MSLU). To use this version, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.Function InformationHeader Declared in Winuser.h, include Windows.h 
    Import library User32.lib 
    Minimum operating systems Windows 95, Windows NT 3.1 
    Unicode Implemented as Unicode and ANSI versions on Windows NT, Windows 2000, Windows XP See AlsoWindow Classes Overview, FindWindow, GetClassInfo, GetClassLong, GetClassWord
      

  2.   

    谢谢大家的回复,因为我刚开始学习VC,对spy++还不怎么会使用,出来的结果哪一个才是呢?
    Rainfall - Microsoft Visual C++ [design] - Rainfall.cpp
    这是显示的结果:RainFall就是类名吗?
      

  3.   

    spy++很难用吗?找到指定窗体,弹出窗口属性对话框,选择 类->类名,后面整个就是类名了
      

  4.   

    你的程序没有创建窗口类吗?这个类名应该是你自己来起的呀?
    如果是由VC自己起的会有一个类名字符串,你可以用
    FindWindow(szClassName,NULL);
      

  5.   

    你可以不用类名,只用窗体标题(窗休左上角),如下所示:
    FindWindow(NULL,lpWindowName);同样可以返回窗体的句柄。
      

  6.   

    spy++   既能看到你当前窗口的类名称,也能看到标题名称...
      

  7.   

    这些我已经知道了.
    BOOL CRainfallApp::InitInstance()
    {
    HWND hWnd = ::FindWindow("RAINFALL_CLASS", 0);

    if (hWnd)
    {
    ::ShowWindow(hWnd, SW_SHOWMAXIMIZED);
    AfxWinTerm();
    ExitProcess(1);
    return FALSE;
    }
    }
    我的这段代码其实是为了完成程序只运行一个实例的效果。
    这段代码只是在系统运行了这个程序时才会调用的!
    用spy++好像行到的不对
      

  8.   

    HWND hWnd = ::FindWindow("RAINFALL_CLASS", 0);

    if (hWnd)
    {
    ::ShowWindow(hWnd, SW_SHOWMAXIMIZED);
    }
      

  9.   

    bdb的db_cxx.h中的DBTYPE跟vs带的oledb.h中定义的DBTYPE冲突,报DBTYPE redefine错误,怎么办?
      

  10.   

    代码中RAINFALL_CLASS请问在程序的什么地方可以找到他!用spy++得到的并不是这个。
    因为小弟要将VC程序代码读懂。有很多不明白的地方(没办法公司要求这么做的!)因为以后我要修改这个程序!!!对于VC很多细节方面还请多多帮忙
      

  11.   

    static LPCSTR className=NULL;
    if( !CMDIFrameWnd::PreCreateWindow(cs) )
    return FALSE;
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs
    if (className==NULL) {
    WNDCLASS wndcls;
    ::GetClassInfo(AfxGetInstanceHandle(),cs.lpszClass,&wndcls);
    wndcls.lpszClassName="RAINFALL_CLASS";
    wndcls.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    VERIFY(AfxRegisterClass(&wndcls));
    className=RAINFALL_CLASS;
    }
    cs.lpszClass=className;
    return TRUE;
    问题已解决:希望大家如果遇到同类问题能从上面的代码得到启发。也就是在MFC中有一个奇怪的窗口类名称!修改它为你自己想要的名称就可以了!!谢谢!大家的回复!!
      

  12.   

    BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
    static LPCSTR className=NULL;
    if( !CMDIFrameWnd::PreCreateWindow(cs) )
    return FALSE;
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs
    if (className==NULL) {
    WNDCLASS wndcls;
    ::GetClassInfo(AfxGetInstanceHandle(),cs.lpszClass,&wndcls);
    wndcls.lpszClassName=RAINFALL_CLASS;
    wndcls.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    VERIFY(AfxRegisterClass(&wndcls));
    className=RAINFALL_CLASS;
    }
    cs.lpszClass=className;
    return TRUE;
    }