예제 #1
0
        public string GetControlText(IntPtr hWnd)
        {
            StringBuilder title = new StringBuilder(256);

            // Get the size of the string required to hold the window title.
            Int32 size = WinUser.SendMessage(hWnd, (int)WindowMessage.WM_GETTEXTLENGTH, 0, 0);

            // If the return is 0, there is no title.
            if (size > 0)
            {
                title = new StringBuilder(size + 1);
                WinUser.SendMessage(hWnd, (int)WindowMessage.WM_GETTEXT, title.Capacity, title);
            }
            else
            {
                WinUser.GetWindowText(hWnd, title, title.Capacity);
            }

            return(title.ToString());
        }