C#은 Windows API를 사용하여 제목 없는 컨트롤에서 컨트롤 핸들을 가져옵니다.

  /// <summary>
        /// 창 핸들 함수 가져오기
        /// </summary>
        /// <param name="lpClassName">창 클래스 이름</param>
        /// <param name="lpWindowName" >창 제목 이름</param>
        /// <returns>리턴 핸들</returns>
        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName) ;

  [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("user32.dll")]
        public static extern int EnumChildWindows(IntPtr hWndParent, CallBack lpfn, int lParam);

[DllImport("user32.dll")]
        public static extern int GetWindowText(IntPtr hwnd, StringBuilder sb, int length);

 공개 대리자 bool CallBack(IntPtr hwnd, int lParam);

        /// <summary>
        /// 양식에서 컨트롤 핸들 찾기
        /// </summary>
        /// <param name="hwnd">부모 양식 핸들</param>
        /// <param name="lpszWindow ">컨트롤 제목(Text)</param>
        /// <param name="bChild">자식 폼에서 검색 여부 설정</param>
        /// <returns>컨트롤 핸들이 없으면 IntPtr을 반환합니다. 0 </returns>
        public static IntPtr FindWindowExMy(IntPtr hwnd, string lpszWindow, bool bChild)
        {             IntPtr iResult = IntPtr.Zero;             // 먼저 부모 폼에서 컨트롤 찾기             iResult = FindWindowEx(hwnd, 0, null, lpszWindow);             / / 찾으면 제어 핸들을 직접 반환             if (iResult != IntPtr.0)                 iResult를 반환합니다.





            // 자식 폼에서 검색하지 않도록 설정한 경우
            if (!bChild)
                return iResult;

            // 자식 창 열거, 컨트롤 핸들 찾기
            int i = EnumChildWindows(
            hwnd,
            (h, l) =>
            {                 IntPtr f1 = FindWindowEx(h, 0, null, lpszWindow);                 if (f1 == IntPtr.Zero)                     return true;                 else                 {                     StringBuilder 제목 = new StringBuilder(200);                     int len;                     len = GetWindowText(hwnd, 제목, 200);







                    iResult = f1;
                    return false;
                }
            },
            0);
            // 검색 결과 반환
            return iResult;
        }

추천

출처blog.csdn.net/yunxiaobaobei/article/details/91801987#comments_25621242