VC中用api函数FindWindow()查找窗口时的第1个参数'ClassName'应该是什么?

解决方案 »

  1.   

    是说这个窗口是什么类型的:比如 CEdit,CToolBar 之类的
      

  2.   


    窗口类名,每个窗口创建的时候需要指定窗口类名,可以用RegisterClass可以注册自己的窗口类。FindWindow可以查找窗口类等于classname的所有窗口。
      

  3.   

    FindWindow
    The FindWindow function retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search. To search child windows, beginning with a specified child window, use the FindWindowEx function. HWND FindWindow(
      LPCTSTR lpClassName,  // class name
      LPCTSTR lpWindowName  // window name
    );
    Parameters
    lpClassName 
    [in] Pointer to a null-terminated string that specifies the class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero. 
    If lpClassName is a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names. lpWindowName 
    [in] Pointer 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 a 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. Res
    If the lpWindowName parameter is not NULL, FindWindow calls the GetWindowText function to retrieve the window name for comparison. For a description of a potential problem that can arise, see the Res for GetWindowText. 
      

  4.   

    有一个对话框它的base class 是CDialog,class name是Cmydialog,为什么我用这个名字查不到窗口?
      

  5.   

    第一个参数设为NULL
     CWnd::FindWindow(NULL,"程序名“);
      

  6.   

    窗口类名class name不是C++的类名,api函数GetClassName可以取得对话框窗口类名。如果想要用FindWindow找窗口,最好自己定义窗口类,用AfxRegisterClass注册类名。