Code Monkey home page Code Monkey logo

Comments (3)

jcljb avatar jcljb commented on August 28, 2024 1

I rewrite to use BasicMessageWindow and it works i.e. the behavoir is correct (the context menu is correctly displayed based on selected item(s) and returned cmd id as well); the m_ComInterface3 is always returned (based on my tests) and it seems that INITMENUPOPUP is the only msg to intercept...

   private static bool WindowMessageFilter(HWND hwnd, uint msg, IntPtr wParam, IntPtr lParam, out IntPtr lReturn)
    {
        lReturn = default;
        try
        {
            Debug.WriteLine($"msg = {msg}");

            switch (msg)
            {
                case (uint)WM.INITMENUPOPUP:
                //case (uint)WM.DRAWITEM:
                //case (uint)WM.MEASUREITEM:
                //case (uint)WM.MENUCHAR:
                    {
                        var com_interface3 = (IContextMenu3)Shell32.ShellUtil.QueryInterface(ComInterfaceContextMenu, new Guid("{bcfce0a0-ec17-11d0-8d10-00a0c90f2719}"));
                        if (com_interface3 is not null)
                        {
                            Debug.WriteLine($"com_interface3 = {msg}");
                            if (com_interface3.HandleMenuMsg2(msg, wParam, lParam, out var lRet).Succeeded)
                                lReturn = lRet;
                            return true;
                        }
                        else
                        {
                            var com_interface2 = (IContextMenu2)Shell32.ShellUtil.QueryInterface(ComInterfaceContextMenu, new Guid("{000214f4-0000-0000-c000-000000000046}"));
                            if (com_interface2 is not null)
                            {
                                if (com_interface2.HandleMenuMsg(msg, wParam, lParam).Succeeded)
                                    lReturn = default;
                                return true;
                            }
                        }
                    }
                    break;
            }
        }
        catch { }

        return false;


    }

from vanara.

jcljb avatar jcljb commented on August 28, 2024

Perhaps pb with IContextMenu3 interface ?
I try to call methods directly and pass Handle to main window in order to take a look to received messages (wndproc)
and it seems that some messages must be filtered too
this is poor and not complete but now the contextmenu is fully shown :

private void button1_Click(object sender, EventArgs e)
{
// shellItem.ContextMenu.ShowContextMenu(GetMousePosition(),CMF.CMF_CANRENAME);

        hmenu = Vanara.PInvoke.User32.CreatePopupMenu();
        shellItem.ContextMenu.ComInterface.QueryContextMenu(hmenu, 0, 0x8000, int.MaxValue, CMF.CMF_EXTENDEDVERBS).ThrowIfFailed();
        var command = Vanara.PInvoke.User32.TrackPopupMenuEx(hmenu, TrackPopupMenuFlags.TPM_RETURNCMD, GetMousePosition().X, GetMousePosition().Y, Handle);
        if (command > 0)
            shellItem.ContextMenu.InvokeCommand((int)command - 0x800);
    }

    protected override void WndProc(ref Message msg)
    {
        switch (msg.Msg)
        {
            case 0x11f:
            case 0x117:
            case 0x2b:
            case 0x2c:
            case 288:

                {
                    if (hmenu != null)
                    {
                        m_ComInterface3 = (IContextMenu3)Shell32.ShellUtil.QueryInterface(shellItem.ContextMenu.ComInterface, new Guid("{bcfce0a0-ec17-11d0-8d10-00a0c90f2719}"));

                        if (m_ComInterface3 is not null)
                        {
                            IntPtr lres;

                            m_ComInterface3.HandleMenuMsg2((uint)msg.Msg, msg.WParam, msg.LParam, out lres);
                        }
                    }
                    else
                        base.WndProc(ref msg);
                        break;
                }
        }
        
            base.WndProc(ref msg);
        
    }

from vanara.

dahall avatar dahall commented on August 28, 2024

Have you found functional examples using IContextMenu3? I would follow those. Vanara simply exposes the interfaces. From light reading, it does appear that HandleMenuMsg and HandleMenuMsg2 must be called in the user code.

from vanara.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.