正在阅读:Internet Explorer编程简述(五)Internet Explorer编程简述(五)

2004-09-24 09:59 出处:CSDN 作者:CathyEagle 责任编辑:linjixiong


  根据图中显示的从属关系,顺藤摸瓜,最内层的窗口“Internet Explorer_Server”的句柄就是我们需要的东西。为了简化问题,我这里使用了来自MSDN Magazine资深专栏撰稿人Paul Dilascia的CFindWnd类,非常好用。


  ////////////////////////////////////////////////////////////////
  // MSDN Magazine -- August 2003
  // If this code works, it was written by Paul DiLascia.
  // If not, I don't know who wrote it.
  // Compiles with Visual Studio .NET on Windows XP. Tab size=3.
  //
  // ---
  // This class encapsulates the process of finding a window with a given class name
  // as a descendant of a given window. To use it, instantiate like so:
  //
  // CFindWnd fw(hwndParent,classname);
  //
  // fw.m_hWnd will be the HWND of the desired window, if found.
  //
  class CFindWnd {
  private:
  //////////////////
  // This private function is used with EnumChildWindows to find the child
  // with a given class name. Returns FALSE if found (to stop enumerating).
  //
  static BOOL CALLBACK FindChildClassHwnd(HWND hwndParent, LPARAM lParam) {
  CFindWnd *pfw = (CFindWnd*)lParam;
  HWND hwnd = FindWindowEx(hwndParent, NULL, pfw->m_classname, NULL);
  if (hwnd) {
  pfw->m_hWnd = hwnd; // found: save it
  return FALSE; // stop enumerating
  }
  EnumChildWindows(hwndParent, FindChildClassHwnd, lParam); // recurse
  return TRUE; // keep looking
  }
  public:
  LPCSTR m_classname; // class name to look for
  HWND m_hWnd; // HWND if found
  // ctor does the work--just instantiate and go
  CFindWnd(HWND hwndParent, LPCSTR classname)
  : m_hWnd(NULL), m_classname(classname)
  {
  FindChildClassHwnd(hwndParent, (LPARAM)this);
  }
  };

 

  再写一个函数InvokeIEServerCommand,调用就很方便了,《Internet Explorer 编程简述(四)“添加到收藏夹”对话框》中最后给出的方法就是从这里来的。


  void CMyHtmlView::InvokeIEServerCommand(int nID)
  {
  CFindWnd FindIEWnd( m_wndBrowser.m_hWnd, "Internet Explorer_Server");
  ::SendMessage( FindIEWnd.m_hWnd, WM_COMMAND, MAKEWPARAM(LOWORD(nID), 0x0), 0 );
  }

 


察看评论详细内容 我要发表评论
作者笔名简短内容 发表时间
:

键盘也能翻页,试试“← →”键

相关文章

关注我们

最新资讯离线随时看 聊天吐槽赢奖品