Example #1
0
        /// <summary>
        /// Creates a service named <paramref name="serviceName"/> and creates an item in Miranda IM contact list.
        /// </summary>
        /// <param name="serviceName">Unique name of service to be created.</param>
        /// <param name="menuItemText">Text of menu item.</param>
        /// <param name="action">Method to be called when user selects menu item.</param>
        public ContactListMenuItem(string serviceName, string menuItemText, Action action)
        {
            _action = action;
            _service = Service;
            Plugin.m_CreateServiceFunction(serviceName, _service);

            var cListMenuItem = new CListMenuItem
            {
                position = -0x7FFFFFFF,
                flags = 0,
                name = menuItemText,
                service = serviceName
            };

            using (var pCListMenuItem = new AutoPtr(Marshal.AllocHGlobal(Marshal.SizeOf(typeof (CListMenuItem)))))
            {
                Marshal.StructureToPtr(cListMenuItem, pCListMenuItem, false);
                Plugin.m_CallService("CList/AddMainMenuItem", IntPtr.Zero, pCListMenuItem);
            }
        }
Example #2
0
        /// <summary>
        /// Load method will be called on plugin load.
        /// </summary>
        protected override void Load()
        {
            this.CreateServiceFunction("TestPlug/MenuCommand",
                menuCommand);

            var mi = new CListMenuItem();
            mi.position = -0x7FFFFFFF;
            mi.flags = 0;
            // TODO: Load icon:
            // mi.hIcon = LoadSkinnedIcon(SKINICON_OTHER_MIRANDA);
            mi.name = "&Test Plugin...";
            mi.service = "TestPlug/MenuCommand";

            // You can use raw IntPtr instead of AutoPtr here, but then do not
            // forget to call Marshal.FreeHGlobal to prevent memory leaks.
            using (var pClistMenuItem = new AutoPtr(
                Marshal.AllocHGlobal(Marshal.SizeOf(typeof (CListMenuItem)))))
            {
                Marshal.StructureToPtr(mi, pClistMenuItem, false);
                this.CallService("CList/AddMainMenuItem", IntPtr.Zero,
                    pClistMenuItem);
            }
        }