当前位置: 首页>>代码示例>>C#>>正文


C# RECT.GetType方法代码示例

本文整理汇总了C#中RECT.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# RECT.GetType方法的具体用法?C# RECT.GetType怎么用?C# RECT.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RECT的用法示例。


在下文中一共展示了RECT.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTBButton


//.........这里部分代码省略.........

                bool b4 = Kernel32.ReadProcessMemory(
                    hProcess,
                    ipRemoteBuffer,
                    ipLocalBuffer,
                    new UIntPtr(BUFFER_SIZE),
                    ipBytesRead);

                if (!b4) { Debug.Assert(false); return false; }

                text = Marshal.PtrToStringUni(ipLocalBuffer, chars);

                if (text == " ") text = String.Empty;
            }

            // window handle
            fixed (byte* pLocalBuffer = localBuffer)
            {
                IntPtr ipLocalBuffer = new IntPtr(pLocalBuffer);

                Int32 dwBytesRead = 0;
                IntPtr ipBytesRead = new IntPtr(&dwBytesRead);

                var ipRemoteData = tbButton.dwData;

                bool b4 = Kernel32.ReadProcessMemory(
                    hProcess,
                    ipRemoteData,
                    ipLocalBuffer,
                    new UIntPtr(4),
                    ipBytesRead);

                if (!b4) { Debug.Assert(false); return false; }

                if (dwBytesRead != 4) { Debug.Assert(false); return false; }

                Int32 iWindowHandle = BitConverter.ToInt32(localBuffer, 0);
                if (iWindowHandle == -1) { Debug.Assert(false); }//return false; }

                ipWindowHandle = new IntPtr(iWindowHandle);
            }

            var rect = default(RECT);
            uint dwTrayProcessID = 0;
            GetWindowThreadProcessId(hToolbar, out dwTrayProcessID);
            if (dwTrayProcessID <= 0) { return false; }
            IntPtr hTrayProc = Kernel32.OpenProcess(PROCESS_ALL_ACCESS, 0, dwTrayProcessID);
            if (hTrayProc == IntPtr.Zero) { return false; }
            IntPtr lpData = Kernel32.VirtualAllocEx(hTrayProc, IntPtr.Zero, Marshal.SizeOf(tbButton.GetType()), MEM_COMMIT, PAGE_READWRITE);
            if (lpData == IntPtr.Zero) { Kernel32.CloseHandle(hTrayProc); return false; }

            // Show tray icon if hidden
            //if ((tbButton.fsState & (byte)TBSTATE_HIDDEN) == (byte)TBSTATE_HIDDEN) SendMessage(hToolbar, TB_HIDEBUTTON, tbButton.idCommand, 1);
            // Get rectangle of tray icon
            Int32 dwBytesRead2 = -1;
            var rectNotifyIcon = new RECT(0, 0, 0, 0);
            byte[] byteBuffer3 = new byte[Marshal.SizeOf(rectNotifyIcon.GetType())];

            SendMessage(hToolbar, TB.GETITEMRECT, tbButton.idCommand, lpData);
            Kernel32.ReadProcessMemory(hTrayProc, lpData, byteBuffer3, Marshal.SizeOf(rectNotifyIcon.GetType()), out dwBytesRead2);
            if (dwBytesRead2 < Marshal.SizeOf(rectNotifyIcon.GetType())) { return false; }

            IntPtr ptrOut2 = Marshal.AllocHGlobal(Marshal.SizeOf(rectNotifyIcon.GetType()));
            Marshal.Copy(byteBuffer3, 0, ptrOut2, byteBuffer3.Length);
            rectNotifyIcon = (RECT)Marshal.PtrToStructure(ptrOut2, typeof(RECT));
            //MapWindowPoints(hToolbar, IntPtr.Zero, ref rectNotifyIcon, 2);

            // Display coordinates
            var c = GetRect(hToolbar);
            System.Diagnostics.Debug.Print("{4} ICONS COORDINATES ARE: Top: {0}, Left: {1}, Bottom: {2}, Right: {3}",
            rectNotifyIcon.Top - c.Top,
            rectNotifyIcon.Left - c.Left,
            (rectNotifyIcon.Bottom - c.Bottom) + rectNotifyIcon.Height,
            rectNotifyIcon.Right - c.Right,
            text);
            Kernel32.VirtualFreeEx(hTrayProc, lpData, UIntPtr.Zero, MEM_RELEASE);
            Kernel32.CloseHandle(hTrayProc);
            rect = new RECT(
                rectNotifyIcon.Left - c.Left,
                rectNotifyIcon.Top - c.Top,
                rectNotifyIcon.Right - c.Right,
                (rectNotifyIcon.Bottom - c.Bottom) + rectNotifyIcon.Height);

            Kernel32.VirtualFreeEx(
                hProcess,
                ipRemoteBuffer,
                UIntPtr.Zero,
                MemAllocationType.RELEASE);

            Kernel32.CloseHandle(hProcess);
            notificationAreaWindow = new NotificationAreaWindow()
            {
                TBBUTTON = tbButton,
                MainWindowHandle = ipWindowHandle,
                ToolBarIconHandle = hToolbar,
                Text = text,
                RECT = rect
            };
            return true;
        }
开发者ID:Mpdreamz,项目名称:tabalt,代码行数:101,代码来源:User32.cs


注:本文中的RECT.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。