怎样获得任一窗口的句柄?谢谢!!

解决方案 »

  1.   

    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
    );
      

  2.   

    HWND hWnd = ::FindWindow( .../* 窗体标题 */ );
      

  3.   

    用EnumWindows遍历可以得到所有的窗口句柄,每次得到一个句柄,直到最后一个
    用法如下
    EnumWindows(EnumWindowsProc, (LPARAM)...);BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
    {
         //hwnd就是得到得窗口的句柄,可以在这个函数里面判断,保存所需的句柄
    }