Comments (3)
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.
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.
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)
- Can't use the handle to read vhdx HOT 2
- `HRESULT.ToString()` is not thread-safe due to mutable global state. HOT 2
- Usage of `LibraryImport` instead of `DllImport` HOT 1
- RtlGetVersion not found in NtDll HOT 6
- A great project! HOT 1
- #nullableenabled brunch is not being merged into master HOT 4
- Kernel32.FILE_ID_128.Identifier returns incorrect values
- [Bug] MB_GetString make exe crashed and ExitCode is 3221226356 (0xc0000374) HOT 2
- RobiniaDocs API Explorer HOT 1
- Can not GetLastError HOT 1
- CM_REGISTER_NOTIFICATION callback: Incomplete eventData.u.DeviceInstance.InstanceId HOT 2
- FindNextPrinterChangeNotification SafePRINTER_NOTIFY_INFO is invalid HOT 2
- missing definition for StorageDeviceSeekPenalty. HOT 1
- [Bug] GetRawInputDeviceInfo can not use CharSet = CharSet.Auto HOT 4
- Interface not supported Exception while using the set operaiton in IMAPI HOT 2
- User32.GetWindowLongAuto throws an exception if result is 0 HOT 1
- OverlappedAsyncBaseResult does not make processed bytes available. HOT 1
- How to use native Win32 Shell ImageList in WinUI3 - Implementing ExplorerBrowser for WinUI3 HOT 17
- Missing unions in FwpUClnt FWPM_* structures HOT 1
- PInvoke.IpHlpApi.GetExtendedUdpTable give wrong port HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vanara.