3、VS2005(c/c++)外壳扩展编程之windows右键菜单(3)

摘要:
第三部分SHELLAdditional一、编程中的一些关键点1、WeimplementedtheIShellExtInitinterface,whichwashowExplorerinitializedourobject.Thereisanotherinitializationinterfaceusedforsomeshellextensions,IPersistFile,andthisisthe

第三部分 SHELL Additional

一、编程中的一些关键点

1We implemented the IShellExtInit interface, which was how Explorer initialized our object. There is another initialization interface used for some shell extensions, IPersistFile, and this is the one an infotip extension uses. IShellExtInit::Initialize() receives an IDataObject pointer with which it can enumerate all of the files that were selected. Extensions that can only ever operate on a single file use IPersistFile. Since the mouse can't hover over more than one object at a time, an infotip extension only works on one file at a time, so it uses IPersistFile.

2AFX_MANAGE_STATE(AfxGetStaticModuleState()); // init MFC

The AFX_MANAGE_STATE macro is necessary for MFC to work properly. Because our DLL is being loaded by a non-MFC app, every exported function that uses MFC must initialize MFC manually. If you don't include that line, many MFC functions (mostly the ones related to resources) will break or have assertion failures.

3In order to have a dialog which has the XP theme enabled, it was necessary to set the following values in stdafx.h before any of the #includes:

#define VC_EXTRALEAN //necessary

#ifndef _WIN32_WINNT

#define _WIN32_WINNT 0x501

#endif

#define _ATL_APARTMENT_THREADED

#define ISOLATION_AWARE_ENABLED 1 //XP style awareness

4A shell extension is a COM DLL

5Note that DllRegisterServer() and DllUnregisterServer() are not called by Explorer, but by the installer. If you downloaded the source files instead of the installer, you will have to register the DLL yourself using the command line tool regsvr32. If you compile the source from within Visual C++, then regsvr32 runs as part as the build process.

6、整体而言,使用SHELL时流程基本如下:

In short, this is what happens: When the user right-clicks inside an Explorer window, Explorer calls CtxMenu's Initialize() function. At this point, the context menu isn't visible yet. Explorer then calls the QueryContextMenu() function to add the Select... item to the menu, and shows it. When the user moves over this menu item, Explorer obtains a description from GetCommandString(). Finally, when the user picks the Select... item, Explorer calls InvokeCommand().

The only place where we can figure out whether the user clicked on a file or on the background of the window is in Initialize().

http://www.codeproject.com/KB/shell/wildcardselect.aspx

http://www.allyoursoftware.com/

第四部分 相关的API

1GlobalLock Function

Locks a global memory object and returns a pointer to the first byte of the object's memory block.

2DragQueryFile Function

Retrieves the names of dropped files that result from a successful drag-and-drop operation.

http://msdn.microsoft.com/en-us/library/bb776408%28VS.85%29.aspx

3GetProcAddress Function

Retrieves the address of an exported function or variable from the specified dynamic-link library (DLL).

http://msdn.microsoft.com/en-us/library/ms683212%28VS.85%29.aspx

4InsertMenu Function

Inserts a new menu item into a menu, moving other items down the menu.

Note The InsertMenu function has been superseded by the InsertMenuItem function. You can still use InsertMenu, however, if you do not need any of the extended features of InsertMenuItem.

http://msdn.microsoft.com/en-us/library/ms647987%28VS.85%29.aspx

5SetMenuItemBitmaps Function

Associates the specified bitmap with a menu item. Whether the menu item is selected or clear, the system displays the appropriate bitmap next to the menu item.

http://msdn.microsoft.com/en-us/library/ms647998%28VS.85%29.aspx

6GetCurrentDirectory Function

Retrieves the current directory for the current process.

SetCurrentDirectory

7lstrcpyn Function

Copies a specified number of characters from a source string into a buffer.

Warning Do not use. Consider using StringCchCopy instead. See Remarks.

8CStdioFile::ReadString

Reads text data into a buffer, up to a limit of nMax1 characters, from the file associated with the CStdioFile object.

Reading is stopped by the first newline character. If, in that case, fewer than nMax1 characters have been read, a newline character is stored in the buffer. A null character ('\0') is appended in either case.

http://msdn.microsoft.com/en-us/library/x5t0zfyf%28VS.80%29.aspx

9FindFirstFile Function

Searches a directory for a file or subdirectory with a name that matches a specific name (or partial name if wildcards are used).

To specify additional attributes to use in a search, use the FindFirstFileEx function.

To perform this operation as a transacted operation, use the FindFirstFileTransacted function.

http://msdn.microsoft.com/en-us/library/aa364418%28VS.85%29.aspx

10SHGetPathFromIDList Function

Converts an item identifier list to a file system path.

http://msdn.microsoft.com/en-us/library/bb762194%28VS.85%29.aspx

11GetTopWindow Function

Examines the Z order of the child windows associated with the specified parent window and retrieves a handle to the child window at the top of the Z order.

http://msdn.microsoft.com/en-us/library/ms633514%28VS.85%29.aspx

12HIWORD Macro

Retrieves the high-order word from the specified 32-bit value.

http://msdn.microsoft.com/en-us/library/ms632657%28VS.85%29.aspx

13SHGetMalloc

Retrieves a pointer to the shell's IMalloc interface

12FindNextFile

Continues a file search from a previous call to the FindFirstFile or FindFirstFileEx function.

http://msdn.microsoft.com/en-us/library/aa364428%28VS.85%29.aspx

3、VS2005(c/c++)外壳扩展编程之windows右键菜单(3)第1张3、VS2005(c/c++)外壳扩展编程之windows右键菜单(3)第2张代码
1 voidCShellExtentionToVirC::RecursiveObtainDirFiles(WCHAR *lpPath)
2 {
3 WCHAR szFind[MAX_PATH];
4 WCHAR szFile[MAX_PATH];
5 WIN32_FIND_DATA FindFileData;
6 7 wcscpy(szFind, lpPath);
8 wcscat(szFind, TEXT("\\*.*"));
9 10 HANDLE hFind=::FindFirstFile((LPCWSTR)szFind, &FindFileData);
11 if(INVALID_HANDLE_VALUE ==hFind)
12 return;
13 14 while(TRUE)
15 {
16 if(FindFileData.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY)
17 {
18 if(FindFileData.cFileName[0] !=L'.')
19 {
20 wcscpy(szFile, lpPath);
21 wcscat(szFile, TEXT("\\"));
22 wcscat(szFile, FindFileData.cFileName);
23 RecursiveObtainDirFiles(szFile);
24 }
25 }
26 else27 {
28 std::wcout <<FindFileData.cFileName <<std::endl;
29 }
30 if(!FindNextFile(hFind, &FindFileData))
31 break;
32 }
33 FindClose(hFind);
34 }
35 36 37 HRESULT CShellExtentionToVirC::InvokeCommand(LPCMINVOKECOMMANDINFO pInfo)
38 {
39 //If lpVerb really points to a string, ignore this function call and bail out.40 if( 0!=HIWORD( pInfo->lpVerb ))
41 returnE_INVALIDARG;
42 43 //Check that lpVerb is one of our commands (0 or 1)44 45 switch( LOWORD( pInfo->lpVerb ))
46 {
47 case0:
48 case1:
49 {
50 TCHAR szMsg[MAX_PATH +32];
51 wsprintf( szMsg, _T("Only a test"));
52 MessageBox( pInfo->hwnd, szMsg, _T("VirCS"),MB_ICONINFORMATION );
53 54 strCurrentDirectory =L"C:\\Intel\\Logs";
55 RecursiveObtainDirFiles(const_cast<WCHAR*>(strCurrentDirectory.data()));
56 returnS_OK;
57 }
58 break;
59 60 default:
61 returnE_INVALIDARG;
62 break;
63 }
64 }

参考

[1]http://www.codeproject.com/KB/shell/shellextguideindex.aspx

关于ShellExtension,CodeProject讲解了更多,如draganddrophandler(用右键拖拽时显示的菜单)propertysheethandler(在属性页中显示的菜单),iconhandler(不同类型文件图标不同)等。

[2]相关文档下载地址

http://download.csdn.net/source/2878021

[3] http://www.codeproject.com/KB/shell/wildcardselect.aspx

[4] http://msdn.microsoft.com/en-us/library/bb776426%28VS.85%29.aspx

[5] http://blog.csdn.net/luckyboy101/archive/2009/11/25/4866408.aspx

[6]http://www.programbbs.com/

[7]http://www.cnblogs.com/MaxWoods/archive/2010/06/23/1764036.html

[8]http://www.cnblogs.com/MaxWoods/archive/2010/06/23/1764034.html

[9]http://www.cnblogs.com/lemony/archive/2007/04/16/715833.html

[10]http://www.cnblogs.com/lemony/archive/2007/04/16/715833.html

[11]DinoEsposito'sgreatbookVisualC++WindowsShellProgramming(ISBN1861001843)

免责声明:文章转载自《3、VS2005(c/c++)外壳扩展编程之windows右键菜单(3)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇hiveserver2的配置和启动opencv 绘制半透明图形 (下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

Java 读取ANSI文件中文乱码问题解决方式[转]

Filefile=newFile(路径);InputStreamin=newjava.io.FileInputStream(文件);BufferedReader读取器=新的BufferedReader(读取);FileInputStreamin=newFileInputStream(文件);byte[]b=新字节[3];内容如下(b);...

vant上传文件到后端

Html代码&lt;Ts代码文件列表=[]/image/[a-zA-z]+/。test(file.file.type)){this.$toast(“请上传图片”);returnfalse;config).then(res=&gt;})。捕获(()=&gt;拒绝)=&gt;ts=“+newDate().getTime()).然后...

Fiddler抓包7-post请求(json)(转载)

2.查看上图中的红色框:这里只支持application/x-www-form-urlencoded格式的body参数,即json格式。您需要检查JOSN列中的five和xml。1.如果遇到text/xml格式的正文,如下图所示...

uniapp之页面间传递和接收数组

uni-app如何在页面之前发送和传递数组?如果阵列是直接发送和传递的,则收到的消息如下所示。无法获取更多的对象值。接收数组对象的参数。您可以首先将数组转换为JSON字符串,然后在将其传递到页面后将其解析为JavaScript对象。...

VS调试异常问题解决(一)

VisualStudio必须是"以管理员身份运行",即鼠标右键"以管理员身份运行",不是指你当前登录的账户是不是Administrator的问题。参考:VS调试时断点无法进入或命中的原因及解决方法当前不会命中断点,还没有为该文档加载任何符号参考:VS2017调试代码显示“当前无法命中断点,还没有为该文档加载任何符号”注:在mvc中视图cshtml中,如果代码...

centos登录密码正确但一直报login incorrect错误(错误赋予权限)

3、 若要修改文件权限,请在无法登录之前仔细调用操作。回想一下,您以前在Linux中遇到过由文件权限引起的问题。尝试检查系统日志/var/log/secure。...