Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.6 KiB

  1. //=============================================================================
  2. // This file contains definitions of classes to implement the pseudo menus
  3. // and menu bars for the msinfo control.
  4. //=============================================================================
  5. #pragma once
  6. //-----------------------------------------------------------------------------
  7. // This class implements a single pseudo-menu on the screen. Caller should
  8. // construct it, attach an HMENU and use Render, HitTest and TrackMenu
  9. // to manage the menu.
  10. //-----------------------------------------------------------------------------
  11. class CPseudoMenu
  12. {
  13. public:
  14. CPseudoMenu(LPCTSTR szCaption, COLORREF crNormal, COLORREF crHighlight);
  15. ~CPseudoMenu();
  16. public:
  17. // Methods for setting the location for this menu (by the upper left
  18. // corner) and getting the bounding rectangle for the label.
  19. void SetLocation(int cx, int cy);
  20. void GetSize(HDC hdc, int * pcx, int * pcy);
  21. const RECT * GetRect() { return &m_rect; };
  22. void GetMenuPoint(POINT * pPoint) { pPoint->x = m_rect.left; pPoint->y = m_rect.bottom; };
  23. CString GetCaption() { return m_strCaption; };
  24. void UpdateColors(COLORREF crNormal, COLORREF crHighlight);
  25. // Render the label for the menu (possibly highlighted if the mouse
  26. // is over the menu). Determine if the given coordinate intersects
  27. // the menu label.
  28. BOOL SetHighlight(BOOL fHighlight);
  29. void Render(HDC hdc);
  30. BOOL HitTest(int cx, int cy) { return PtInRect(&m_rect, CPoint(cx, cy)); };
  31. // Attach new HMENU. Return the original HMENU (for the caller to deal with).
  32. HMENU AttachMenu(HMENU hmenu);
  33. HMENU GetHMENU() { return m_hMenu; };
  34. // Track the user's selection of a menu, and return the ID of the
  35. // selected item.
  36. UINT TrackMenu(HWND hwnd, POINT * pPoint);
  37. private:
  38. RECT m_rect;
  39. HMENU m_hMenu;
  40. CString m_strCaption;
  41. COLORREF m_crNormal;
  42. COLORREF m_crHighlight;
  43. BOOL m_fHighlight;
  44. };
  45. //-----------------------------------------------------------------------------
  46. // This class implements a pseudo menu bar. It contains a collection of
  47. // CPseudoMenu objects, and encapsulates hit testing, rendering, etc. for the
  48. // group of menus.
  49. //-----------------------------------------------------------------------------
  50. class CPseudoMenuBar
  51. {
  52. public:
  53. CPseudoMenuBar();
  54. ~CPseudoMenuBar();
  55. // Functions for inserting and accessing CPseudoMenu objects.
  56. void LoadFromResource(HINSTANCE hinstance, UINT uResourceID, COLORREF crNormal, COLORREF crHighlight);
  57. void InsertMenu(int index, CPseudoMenu * pMenu);
  58. CPseudoMenu * GetMenu(int index);
  59. void UpdateColors(COLORREF crNormal, COLORREF crHighlight);
  60. // Functions for managing the size of the total menu bar, testing for
  61. // hits, rendering, etc.
  62. const RECT * GetRect(HDC hdc) { RecomputeRect(hdc); return &m_rect; };
  63. BOOL HitTest(HDC hdc, int cx, int cy) { RecomputeRect(hdc); return PtInRect(&m_rect, CPoint(cx, cy)); };
  64. void GetMenuPoint(HDC hdc, int index, POINT * pPoint);
  65. void GetMenuPoint(HDC hdc, int cx, int cy, POINT * pPoint);
  66. BOOL NoHighlight();
  67. BOOL TrackHighlight(HDC hdc, int cx, int cy);
  68. UINT TrackMenu(HWND hwnd, POINT * pPoint, int cx, int cy);
  69. void SetOrigin(HDC hdc, POINT point);
  70. void Render(HDC hdc);
  71. private:
  72. void RecomputeRect(HDC hdc);
  73. private:
  74. enum { MaxMenus = 20 };
  75. CPseudoMenu * m_pmenus[MaxMenus]; // TBD - arbitrary limit
  76. RECT m_rect;
  77. BOOL m_fNeedToComputeRect;
  78. POINT m_ptOrigin;
  79. public:
  80. // Temporarily adding on a find button using the menu bar. This will go
  81. // eventually go away.
  82. RECT m_winRect;
  83. };