How to host an IContextMenu, part 3 – Invocation location

Date:September 23, 2004 / year-entry #346
Tags:code
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20040923-00/?p=37773
Comments:    5
Summary:One of the bugs you may have noticed in our first attempt at displaying the context menu to the user is that the Properties dialog doesn't show up at the point you clicked. The Properties dialog isn't psychic; it doesn't know where the original mouse click occurred. You have to tell it. CMINVOKECOMMANDINFOEX info =...

One of the bugs you may have noticed in our first attempt at displaying the context menu to the user is that the Properties dialog doesn't show up at the point you clicked. The Properties dialog isn't psychic; it doesn't know where the original mouse click occurred. You have to tell it.

          CMINVOKECOMMANDINFOEX info = { 0 };
          info.cbSize = sizeof(info);
          info.fMask = CMIC_MASK_UNICODE | CMIC_MASK_PTINVOKE;
          info.hwnd = hwnd;
          info.lpVerb  = MAKEINTRESOURCEA(iCmd - SCRATCH_QCM_FIRST);
          info.lpVerbW = MAKEINTRESOURCEW(iCmd - SCRATCH_QCM_FIRST);
          info.nShow = SW_SHOWNORMAL;
          info.ptInvoke = pt;

You tell it by setting the CMIC_MASK_PTINVOKE flag in the fMask and specifying the invocation point in the ptInvoke member of the CMINVOKECOMMANDINFOEX structure.

Make this change and observe that now the Properties dialog appears at the point you clicked the mouse rather than in a random location on the screen.

Next time, we'll clean up another minor problem with our sample program.


Comments (5)
  1. Mike Dunn says:

    hmm, the properties dlg always shows up at about (0,20) for me, not at the click location.

  2. Jack Mathews says:

    That’s funny, I never even noticed that the properties dialog showed up where the menu popped up in Explorer. Subtle, but nice.

  3. Raymond Chen says:

    Mike: Odd, I took a brand new project, re-created the program and the properties dialog shows up at the click position.

  4. IContextMenu のホスト方法 – Shell

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index