⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atlcontrols.h

📁 outlook 插件 在outlook 中添加弹出试菜单
💻 H
📖 第 1 页 / 共 5 页
字号:
    LPTSTR lpszText = (LPTSTR)_alloca((nLen + 1) * sizeof(TCHAR));

    if(GetText(nIndex, lpszText) == LB_ERR)
      return FALSE;

    bstrText = ::SysAllocString(T2OLE(lpszText));
    return (bstrText != NULL) ? TRUE : FALSE;
  }
#endif //!_ATL_NO_COM
  int GetTextLen(int nIndex) const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, LB_GETTEXTLEN, nIndex, 0L);
  }

  // Settable only attributes
  void SetColumnWidth(int cxWidth)
  {
    ATLASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, LB_SETCOLUMNWIDTH, cxWidth, 0L);
  }
  BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
  }
  BOOL SetTabStops()
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, 0, 0L);
  }
  BOOL SetTabStops(const int& cxEachStop)    // takes an 'int'
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
  }

  int SetItemHeight(int nIndex, UINT cyItemHeight)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, LB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
  }
  int GetItemHeight(int nIndex) const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, LB_GETITEMHEIGHT, nIndex, 0L);
  }
  int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, LB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
  }
  int GetCaretIndex() const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, LB_GETCARETINDEX, 0, 0);
  }
  int SetCaretIndex(int nIndex, BOOL bScroll = TRUE)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, LB_SETCARETINDEX, nIndex, MAKELONG(bScroll, 0));
  }

// Operations
  // manipulating listbox items
  int AddString(LPCTSTR lpszItem)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem);
  }
  int DeleteString(UINT nIndex)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, LB_DELETESTRING, nIndex, 0L);
  }
  int InsertString(int nIndex, LPCTSTR lpszItem)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, LB_INSERTSTRING, nIndex, (LPARAM)lpszItem);
  }
  void ResetContent()
  {
    ATLASSERT(::IsWindow(m_hWnd));
    ::SendMessage(m_hWnd, LB_RESETCONTENT, 0, 0L);
  }
  int Dir(UINT attr, LPCTSTR lpszWildCard)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, LB_DIR, attr, (LPARAM)lpszWildCard);
  }

  // selection helpers
  int FindString(int nStartAfter, LPCTSTR lpszItem) const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, LB_FINDSTRING, nStartAfter, (LPARAM)lpszItem);
  }
  int SelectString(int nStartAfter, LPCTSTR lpszItem)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, LB_SELECTSTRING, nStartAfter, (LPARAM)lpszItem);
  }
  int SelItemRange(BOOL bSelect, int nFirstItem, int nLastItem)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return bSelect ? (int)::SendMessage(m_hWnd, LB_SELITEMRANGEEX, nFirstItem, nLastItem) : (int)::SendMessage(m_hWnd, LB_SELITEMRANGEEX, nLastItem, nFirstItem);
  }
};

typedef CListBoxT<CWindow>  CListBox;

/////////////////////////////////////////////////////////////////////////////
// CComboBox - client side for a Windows COMBOBOX control

template <class Base>
class CComboBoxT : public Base
{
public:
// Constructors
  CComboBoxT(HWND hWnd = NULL) : Base(hWnd) { }

  CComboBoxT< Base >& operator=(HWND hWnd)
  {
    m_hWnd = hWnd;
    return *this;
  }

  HWND Create(HWND hWndParent, RECT& rcPos, LPCTSTR szWindowName = NULL,
      DWORD dwStyle = 0, DWORD dwExStyle = 0,
      UINT nID = 0, LPVOID lpCreateParam = NULL)
  {
    return CWindow::Create(GetWndClassName(), hWndParent, rcPos, szWindowName, dwStyle, dwExStyle, nID, lpCreateParam);
  }
  HWND Create(HWND hWndParent, LPRECT lpRect = NULL, LPCTSTR szWindowName = NULL,
      DWORD dwStyle = 0, DWORD dwExStyle = 0,
      HMENU hMenu = NULL, LPVOID lpCreateParam = NULL)
  {
    return CWindow::Create(GetWndClassName(), hWndParent, lpRect, szWindowName, dwStyle, dwExStyle, hMenu, lpCreateParam);
  }

// Attributes
  static LPCTSTR GetWndClassName()
  {
    return _T("COMBOBOX");
  }

  // for entire combo box
  int GetCount() const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_GETCOUNT, 0, 0L);
  }
  int GetCurSel() const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_GETCURSEL, 0, 0L);
  }
  int SetCurSel(int nSelect)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_SETCURSEL, nSelect, 0L);
  }
  LCID GetLocale() const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (LCID)::SendMessage(m_hWnd, CB_GETLOCALE, 0, 0L);
  }
  LCID SetLocale(LCID nNewLocale)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (LCID)::SendMessage(m_hWnd, CB_SETLOCALE, (WPARAM)nNewLocale, 0L);
  }
  int GetTopIndex() const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_GETTOPINDEX, 0, 0L);
  }
  int SetTopIndex(int nIndex)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_SETTOPINDEX, nIndex, 0L);
  }
  int InitStorage(int nItems, UINT nBytes)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_INITSTORAGE, (WPARAM)nItems, nBytes);
  }
  void SetHorizontalExtent(UINT nExtent)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    ::SendMessage(m_hWnd, CB_SETHORIZONTALEXTENT, nExtent, 0L);
  }
  UINT GetHorizontalExtent() const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (UINT)::SendMessage(m_hWnd, CB_GETHORIZONTALEXTENT, 0, 0L);
  }
  int SetDroppedWidth(UINT nWidth)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_SETDROPPEDWIDTH, nWidth, 0L);
  }
  int GetDroppedWidth() const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_GETDROPPEDWIDTH, 0, 0L);
  }

  // for edit control
  DWORD GetEditSel() const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return ::SendMessage(m_hWnd, CB_GETEDITSEL, 0, 0L);
  }
  BOOL LimitText(int nMaxChars)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (BOOL)::SendMessage(m_hWnd, CB_LIMITTEXT, nMaxChars, 0L);
  }
  BOOL SetEditSel(int nStartChar, int nEndChar)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (BOOL)::SendMessage(m_hWnd, CB_SETEDITSEL, 0, MAKELONG(nStartChar, nEndChar));
  }

  // for combobox item
  DWORD GetItemData(int nIndex) const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return ::SendMessage(m_hWnd, CB_GETITEMDATA, nIndex, 0L);
  }
  int SetItemData(int nIndex, DWORD dwItemData)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
  }
  void* GetItemDataPtr(int nIndex) const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (LPVOID)GetItemData(nIndex);
  }
  int SetItemDataPtr(int nIndex, void* pData)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return SetItemData(nIndex, (DWORD)(LPVOID)pData);
  }
  int GetLBText(int nIndex, LPTSTR lpszText) const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_GETLBTEXT, nIndex, (LPARAM)lpszText);
  }
#ifndef _ATL_NO_COM
  BOOL GetLBTextBSTR(int nIndex, BSTR& bstrText) const
  {
    USES_CONVERSION;
    ATLASSERT(::IsWindow(m_hWnd));
    ATLASSERT(bstrText == NULL);

    int nLen = GetLBTextLen(nIndex);
    if(nLen == CB_ERR)
      return FALSE;

    LPTSTR lpszText = (LPTSTR)_alloca((nLen + 1) * sizeof(TCHAR));

    if(GetLBText(nIndex, lpszText) == CB_ERR)
      return FALSE;

    bstrText = ::SysAllocString(T2OLE(lpszText));
    return (bstrText != NULL) ? TRUE : FALSE;
  }
#endif //!_ATL_NO_COM
  int GetLBTextLen(int nIndex) const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_GETLBTEXTLEN, nIndex, 0L);
  }

  int SetItemHeight(int nIndex, UINT cyItemHeight)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
  }
  int GetItemHeight(int nIndex) const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_GETITEMHEIGHT, nIndex, 0L);
  }
  int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
  }
  int SetExtendedUI(BOOL bExtended = TRUE)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_SETEXTENDEDUI, bExtended, 0L);
  }
  BOOL GetExtendedUI() const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (BOOL)::SendMessage(m_hWnd, CB_GETEXTENDEDUI, 0, 0L);
  }
  void GetDroppedControlRect(LPRECT lprect) const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    ::SendMessage(m_hWnd, CB_GETDROPPEDCONTROLRECT, 0, (DWORD)lprect);
  }
  BOOL GetDroppedState() const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (BOOL)::SendMessage(m_hWnd, CB_GETDROPPEDSTATE, 0, 0L);
  }

// Operations
  // for drop-down combo boxes
  void ShowDropDown(BOOL bShowIt = TRUE)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    ::SendMessage(m_hWnd, CB_SHOWDROPDOWN, bShowIt, 0L);
  }

  // manipulating listbox items
  int AddString(LPCTSTR lpszString)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_ADDSTRING, 0, (LPARAM)lpszString);
  }
  int DeleteString(UINT nIndex)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_DELETESTRING, nIndex, 0L);
  }
  int InsertString(int nIndex, LPCTSTR lpszString)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString);
  }
  void ResetContent()
  {
    ATLASSERT(::IsWindow(m_hWnd));
    ::SendMessage(m_hWnd, CB_RESETCONTENT, 0, 0L);
  }
  int Dir(UINT attr, LPCTSTR lpszWildCard)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_DIR, attr, (LPARAM)lpszWildCard);
  }

  // selection helpers
  int FindString(int nStartAfter, LPCTSTR lpszString) const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_FINDSTRING, nStartAfter, (LPARAM)lpszString);
  }
  int SelectString(int nStartAfter, LPCTSTR lpszString)
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, CB_SELECTSTRING, nStartAfter, (LPARAM)lpszString);
  }

  // Clipboard operations
  void Clear()
  {
    ATLASSERT(::IsWindow(m_hWnd));
    ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
  }
  void Copy()
  {
    ATLASSERT(::IsWindow(m_hWnd));
    ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
  }
  void Cut()
  {
    ATLASSERT(::IsWindow(m_hWnd));
    ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
  }
  void Paste()
  {
    ATLASSERT(::IsWindow(m_hWnd));
    ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
  }
};

typedef CComboBoxT<CWindow> CComboBox;

/////////////////////////////////////////////////////////////////////////////
// CEdit - client side for a Windows EDIT control

template <class Base>
class CEditT : public Base
{
public:
// Constructors
  CEditT(HWND hWnd = NULL) : Base(hWnd) { }

  CEditT< Base >& operator=(HWND hWnd)
  {
    m_hWnd = hWnd;
    return *this;
  }

  HWND Create(HWND hWndParent, RECT& rcPos, LPCTSTR szWindowName = NULL,
      DWORD dwStyle = 0, DWORD dwExStyle = 0,
      UINT nID = 0, LPVOID lpCreateParam = NULL)
  {
    return CWindow::Create(GetWndClassName(), hWndParent, rcPos, szWindowName, dwStyle, dwExStyle, nID, lpCreateParam);
  }
  HWND Create(HWND hWndParent, LPRECT lpRect = NULL, LPCTSTR szWindowName = NULL,
      DWORD dwStyle = 0, DWORD dwExStyle = 0,
      HMENU hMenu = NULL, LPVOID lpCreateParam = NULL)
  {
    return CWindow::Create(GetWndClassName(), hWndParent, lpRect, szWindowName, dwStyle, dwExStyle, hMenu, lpCreateParam);
  }

// Attributes
  static LPCTSTR GetWndClassName()
  {
    return _T("EDIT");
  }

  BOOL CanUndo() const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (BOOL)::SendMessage(m_hWnd, EM_CANUNDO, 0, 0L);
  }
  int GetLineCount() const
  {
    ATLASSERT(::IsWindow(m_hWnd));
    return (int)::SendMessage(m_hWnd, EM_GETLINECOUNT, 0, 0L);
  }
  BOOL GetModify() const

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -