Пример #1
0
        protected virtual void RetrieveButtonInfo()
        {
            if (buttonList == null)
            {
                buttonList = new SUIToolbarButtonCollection();

                int processId = 0;
                SUIWinAPIs.GetWindowThreadProcessId(WindowHandle, ref processId);
                IntPtr processHandle = SUIWinAPIs.OpenProcess(SUIMessage.PROCESS_ALL_ACCESS, false, processId);

                IntPtr data = SUIWinAPIs.VirtualAllocEx(processHandle, IntPtr.Zero, Marshal.SizeOf(typeof(TBBUTTON)), SUIMessage.MEM_COMMIT, SUIMessage.PAGE_READWRITE);
                buttonCount = SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.TB_BUTTONCOUNT, IntPtr.Zero, IntPtr.Zero);
                for (int i = 0; i < buttonCount; i++)
                {
                    TBBUTTON btn = new TBBUTTON();
                    IntPtr   ptr = IntPtr.Zero;
                    try
                    {
                        ptr = Marshal.AllocHGlobal(Marshal.SizeOf(btn));

                        SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.TB_GETBUTTON, new IntPtr(i), data);
                        IntPtr numReaded = new IntPtr();
                        SUIWinAPIs.ReadProcessMemory(processHandle, data, ptr, Marshal.SizeOf(typeof(TBBUTTON)), out numReaded);

                        btn = (TBBUTTON)Marshal.PtrToStructure(ptr, btn.GetType());

                        buttonList.Add(new SUIToolbarButton(this, btn, i));
                    }
                    catch (Exception e)
                    {
                        throw new SUIException("Error getting toolbar button information!", e);
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(ptr);
                    }
                }

                SUIWinAPIs.VirtualFreeEx(processHandle, data, Marshal.SizeOf(typeof(TBBUTTON)), SUIMessage.MEM_RESERVE);
                SUIWinAPIs.CloseHandle(processHandle);
            }
        }
Пример #2
0
        protected virtual void RetrieveButtonInfo()
        {
            if (buttonList == null)
            {
                buttonList = new SUIToolbarButtonCollection();

                int processId = 0;
                SUIWinAPIs.GetWindowThreadProcessId(WindowHandle, ref processId);
                IntPtr processHandle = SUIWinAPIs.OpenProcess(SUIMessage.PROCESS_ALL_ACCESS, false, processId);

                IntPtr data = SUIWinAPIs.VirtualAllocEx(processHandle, IntPtr.Zero, Marshal.SizeOf(typeof(TBBUTTON)), SUIMessage.MEM_COMMIT, SUIMessage.PAGE_READWRITE);
                buttonCount = SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.TB_BUTTONCOUNT, IntPtr.Zero, IntPtr.Zero);
                for (int i = 0; i < buttonCount; i++)
                {
                    TBBUTTON btn = new TBBUTTON();
                    IntPtr ptr = IntPtr.Zero;
                    try
                    {
                        ptr = Marshal.AllocHGlobal(Marshal.SizeOf(btn));

                        SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.TB_GETBUTTON, new IntPtr(i), data);
                        IntPtr numReaded = new IntPtr();
                        SUIWinAPIs.ReadProcessMemory(processHandle, data, ptr, Marshal.SizeOf(typeof(TBBUTTON)), out numReaded);

                        btn = (TBBUTTON)Marshal.PtrToStructure(ptr, btn.GetType());

                        buttonList.Add(new SUIToolbarButton(this, btn, i));
                    }
                    catch (Exception e)
                    {
                        throw new SUIException("Error getting toolbar button information!", e);
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(ptr);
                    }
                }

                SUIWinAPIs.VirtualFreeEx(processHandle, data, Marshal.SizeOf(typeof(TBBUTTON)), SUIMessage.MEM_RESERVE);
                SUIWinAPIs.CloseHandle(processHandle);
            }
        }
Пример #3
0
 public SUIToolbarButton(SUIToolbar _toolbar, TBBUTTON _tbButton, int _index)
 {
     toolbar = _toolbar;
     tbButton = _tbButton;
     index = _index;
 }
Пример #4
0
 public SUIToolbarButton(SUIToolbar _toolbar, TBBUTTON _tbButton, int _index)
 {
     toolbar  = _toolbar;
     tbButton = _tbButton;
     index    = _index;
 }