设为首页 加入收藏

TOP

C/C++中宏使用总结(一)
2012-11-03 14:42:41 来源: 作者: 【 】 浏览:1585
Tags:C/C 使用 总结
  用Windows提供的Shell类,用户可以在C++(www.cppentry.com)中查询和执行鼠标右键的弹出菜单。如下面的例子通过模拟鼠标右键操作来达到将notepad.exe pin到taskbar的目的。注意其中的项名是带快捷键符的。
  
  [cpp]
  
  #define _CRT_SECURE_NO_WARNINGS
  
  #include <cstdio>
  
  #include <cstdlib>
  
  #include <cassert>
  
  #include <cstring>
  
  #include <windows.h>
  
  #include <iostream>
  
  #include <string>
  
  #include <shellapi.h>
  
  #include <Shobjidl.h>
  
  #include <shlobj.h>
  
  #import <Shell32.dll>
  
  using namespace std;
  
  int InvokeItemInPopupMenu(const char * path, const char * file_name, const char * item_name)
  
  {
  
  CoInitialize(NULL);
  
  Shell32::IShellDispatchPtr ptrShell;
  
  ptrShell.CreateInstance(__uuidof(Shell32::Shell));
  
  _variant_t var((short)Shell32::ssfRECENT);
  
  Shell32::FolderPtr ptrFolder = ptrShell->NameSpace(path);
  
  Shell32::FolderItemPtr ptrItem = ptrFolder->ParseName(file_name);
  
  Shell32::FolderItemVerbsPtr t_verbs = ptrItem->Verbs();
  
  for (long i = 0; i < t_verbs->Count; ++i) {
  
  Shell32::FolderItemVerbPtr t_verb = t_verbs->Item(i);
  
  cout 《 t_verb->Name 《 endl;
  
  if (!strcmp(t_verb->Name, item_name)) {
  
  t_verb->DoIt();
  
  Sleep(100);
  
  }
  
  }
  
  ptrItem.Release();
  
  ptrFolder.Release();
  
  ptrShell.Release();
  
  CoUninitialize();
  
  return 0;
  
  }
  
  int main()
  
  {
  
  InvokeItemInPopupMenu(“C:\\Windows”, “notepad.exe”, “Pin to Tas&kbar”);
  
  return 0;
  
  }
  
  #define _CRT_SECURE_NO_WARNINGS
  
  #include <cstdio>
  
  #include <cstdlib>
  
  #include <cassert>
  
  #include <cstring>
  
  #include <windows.h>
  
  #include <iostream>
  
  #include <string>
  
  #include <shellapi.h>
  
  #include <Shobjidl.h>
  
  #include <shlobj.h>
  
  #import <Shell32.dll>
  
  using namespace std;
  
  int InvokeItemInPopupMenu(const char * path, const char * file_name, const char * item_name)
  
  {
  
  CoInitialize(NULL);
  
  Shell32::IShellDispatchPtr ptrShell;
  
  ptrShell.CreateInstance(__uuidof(Shell32::Shell));
  
  _variant_t var((short)Shell32::ssfRECENT);
  
  Shell32::FolderPtr ptrFolder = ptrShell->NameSpace(path);
  
  Shell32::FolderItemPtr ptrItem = ptrFolder->ParseName(file_name);
  
  Shell32::FolderItemVerbsPtr t_verbs = ptrItem->Verbs();
  
  for (long i = 0; i < t_verbs->Count; ++i) {
  
  Shell32::FolderItemVerbPtr t_verb = t_verbs->Item(i);
  
  cout 《 t_verb->Name 《 endl;
  
  if (!strcmp(t_verb->Name, item_name)) {
  
  t_verb->DoIt();
  
  Sleep(100);
  
  }
  
  }
  
  ptrItem.Release();
  
  ptrFolder.Release();
  
  ptrShell.Release();
  
  CoUninitialize();
  
  return 0;
  
  }
  
  int main()
  
  {
  
  InvokeItemInPopupMenu(“C:\\Windows”, “notepad.exe”, “Pin to Tas&kbar”);
  
  return 0;
  
  }
首页 上一页 1 2 3 4 5 下一页 尾页 1/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇编程实现测试CPU的速度 下一篇[C/C++] Windows下模拟鼠标..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: