The context menu of the integrated housing in the application (below)

zhaozj2021-02-16  53

(2) Responding to the mouse click message, obtain the IconTextMenu interface and pop up the menu;

The GetuiObjectof method of the ISHELLFOLDER interface through the C drive We can get the IconTextMenu interface of one or more specified child nodes of the node. The prototype is as follows:

HRESULT GETUIOBJECTOF

HWND HWNDOWNER,

UINT CIDL, / / ​​Specify the number of PIDLs of the PIDL in the array of APIDL points to the APIDL

LPCITEMIDLIST * APIDL, // Point to CIDL PIDL, you need to note that these PIDL must be relative

Refiid riid, // We want a context menu interface, here is specified as IID_ICONTEXTMENU_

Uint * rgfreserved,

Void ** PPV

);

HRESULT HR;

ContextMenu * pcm = null;

HR = m_psffolderc-> getuiObjectof (GetSafehWnd (), Arylistboxsel.getsize (),

(Lpcitemidlist *) PPIDLS, IID_ICONTEXTMENU, NULL, (VOID **) & PCM);

After getting IconTextMenu, we have to provide a handle of a pop-up menu and pass him to IconTextMenu :: queryContextMenu,

If the method is successful, add the appropriate menu item in our menu.

CMenu Menu;

Menu.createPopupnupmenu ();

HR = PCM-> QueryContextMenu (menu.m_hmenu, 0, 1, 0x7ft, cmf_normal | cmf_explore);

With a menu item, we can pop up the menu, we specify the TPM_RETURNCMD flag to specify that the TRACKPOPUPMENU must return the ID of the user's selected menu item to call the true shell action by IconTextMenu :: InvokeCommand later:

IDCMD = menu.trackpopupmenu (TPM_LEFTALIGN | TPM_RETURNCMD | TPM_RightButton,

Pt.x,

Pt.y,

AFXGETMAINWND ());

IF (idcmd)

{

CMinvokeCommandInfo CMI;

Cmi.cbsize = sizeof (cminvokeCommandInfo);

CMI.Fmask = 0;

CMI.hwnd = getsafehwnd ();

Cmi.lpverb = (lpcstr) (int_ptr) (idcmd - 1);

Cmi.lpparameters = NULL;

Cmi.lpdirectory = NULL;

CMI.NSHOW = SW_SHOWNORMAL;

cmi.dwhotkey = 0;

Cmi.hicon = NULL;

HR = PCM-> InvokeCommand (& CMI);

}

// Note: In fact, there are two interfaces associated with the context menu, which is IconTextMenu2 and IconTextMenu3, which is used to implement the self-drawing behavior of the extended menu item. Here is the simplicity, there is no call to us, in common use We must have the relevant methods of querying these two interfaces and receives the two interfaces related to the messages related to the menu of WM_DRAWITEM / WM_INITMENUPOPUP, otherwise the self-painting menu items and child menu items will not normal. display. Please see the source code included in this article.

(3) Do not pop up the menu directly call the menu item corresponding to the command? Do you still remember how to display a file or folder attribute dialog box?

YES, use shellexecuteEx and specify the LPVERB domain of shellexecuteInfo to Properties, but this method can only view the properties of a file, how do you view multiple?

To know that shellexecuteex view file properties ultimately relying on IconTextMenu, the answer is still on IconTextMenu, we only need to pass the file or file PIDL you want to view when calling getuiObjectof, then call the InvokeCommand method to OK. .

IF (m_psffolderc! = null)

{

HRESULT HR;

IconTextMenu * pcm = null;

HR = m_psffolderc-> getuiObjectof (GetSafehWnd (), AryListBoxSel.getsize (), (lpcitemidlist *) PPIDLS, IID_ICONTEXTMENU, NULL, (Void **) & PCM);

En (ac) && pcm! = null)

{

CMinvokeCommandInfo CMI;

Cmi.cbsize = sizeof (cminvokeCommandInfo);

CMI.Fmask = 0;

CMI.hwnd = getsafehwnd ();

CMI.lpverb = "Properties"; // When the menu is pop-up, this is the cmdid selected by the user, but at this time we have no pop-up menu, so you can only call in Verb, please refer to MSDN for more information on Verb.

Cmi.lpparameters = NULL;

Cmi.lpdirectory = NULL;

CMI.NSHOW = SW_SHOWNORMAL;

cmi.dwhotkey = 0;

Cmi.hicon = NULL;

HR = PCM-> InvokeCommand (& CMI);

PCM-> Release ();

}

}

Postscript and reference

In fact, there are a lot of articles for shell programming in the Internet (of course, most of them are English, how to find more tray program L), there are many good articles on www.codeproject.com, but because they focus on Reusable On the same, C puts the chaos and seven-eight-piece, so that we can't learn the mechanism of the shell extension and calls, this article shows you the most straightforward way to call the shell in your program.

Of course, the younger brother is limited, there is a mistake in the text, and I hope to get your correct.

This article demonstrates the source code: http://iunknown.com.cn/9cbs/kshellcontextMenu.rar

reference:

View of Windows Shell Name Space By Jiang Weihua (a few introduction shell's Chinese article, recommended)

Use shell contextmenu in your application (This author provides a class, call shell contextmenu in your program only need two three lines of code, very convenient J)

Platform Sample: ENUMDESK

MSDN Library-> Platform SDK Document-> User Interface Services-> Windows Shell

转载请注明原文地址:https://www.9cbs.com/read-21830.html

New Post(0)