Exemplo n.º 1
0
        /// <summary>
        /// Reads the class name of the specified control handle.
        /// </summary>
        /// <param name="handle"></param>
        /// <returns></returns>
        public static string GetClassName(IntPtr handle)
        {
            var sb = new StringBuilder(64000);

            _ = USER32.GetClassName(handle, sb, sb.Capacity);
            KERNEL32.CheckLastError();
            return(sb.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// The GetClassName function retrieves the name of the class to which the specified window belongs.
        /// </summary>
        public static string GetClassName(IntPtr hWnd)
        {
            var size = 1024;

            while (true)
            {
                var stringBuilder = new StringBuilder(size);
                var read          = USER32.GetClassName(hWnd, stringBuilder, size);
                if (read < size)
                {
                    return(stringBuilder.ToString());
                }
                size *= 2;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new SysListView32 instance
        /// </summary>
        /// <param name="processHandle"></param>
        /// <param name="controlHandle"></param>
        public SysListView32(IntPtr processHandle, IntPtr controlHandle)
        {
            var className = USER32.GetClassName(controlHandle);

            if (className != "SysListView32")
            {
                throw new ArgumentException("Control is not a SysListView32");
            }
            ControlHandle = controlHandle;
            _             = USER32.GetWindowThreadProcessId(controlHandle, out ProcessID);
            ProcessHandle = processHandle;

            foreignTextBuffer = KERNEL32.SafeNativeMethods.VirtualAllocEx(ProcessHandle, IntPtr.Zero, 512, MEM_STATE.ALLOCATE_NEW, MEM_PROTECT.PAGE_READWRITE);
            foreignItemBuffer = KERNEL32.SafeNativeMethods.VirtualAllocEx(ProcessHandle, IntPtr.Zero, 512, MEM_STATE.ALLOCATE_NEW, MEM_PROTECT.PAGE_READWRITE);
            localBuffer       = Marshal.AllocHGlobal(512);
        }