/// <summary> /// The windows message pump. /// </summary> /// <param name="m">The Windows <see cref="T:System.Windows.Forms.Message" /> to process.</param> protected override void WndProc(ref Message m) { base.WndProc(ref m); // Do we have a comamnd and a shell context menu we're testing? if (m.Msg == WM_COMMAND && TestContextMenu != null) { var loword = LowWord(m.WParam.ToInt32()); var hiword = HighWord(m.WParam.ToInt32()); // If the hiword is 0 it's a menu command. if (hiword == 0) { // Create command info. var commandInfo = new CMINVOKECOMMANDINFO(); commandInfo.cbSize = (uint) Marshal.SizeOf(commandInfo); commandInfo.verb = new IntPtr(loword); // Get a pointer to the structure. var commandInfoPointer = Marshal.AllocHGlobal(Marshal.SizeOf(commandInfo)); Marshal.StructureToPtr(commandInfo, commandInfoPointer, false); ((IContextMenu) TestContextMenu).InvokeCommand(commandInfoPointer); } } }
/// <summary> /// Saves the invoke command information. /// </summary> /// <param name="isUnicode">if set to <c>true</c> the unicode structure is used.</param> /// <param name="ici">The ici.</param> /// <param name="iciex">The iciex.</param> private void SaveInvokeCommandInfo(bool isUnicode, CMINVOKECOMMANDINFO ici, CMINVOKECOMMANDINFOEX iciex) { if (isUnicode) { // Create command info from the Unicode structure. currentInvokeCommandInfo = new InvokeCommandInfo { WindowHandle = iciex.hwnd, ShowCommand = iciex.nShow }; } else { // Create command info from the ANSI structure. currentInvokeCommandInfo = new InvokeCommandInfo { WindowHandle = ici.hwnd, ShowCommand = ici.nShow }; } }