Source code of Windows XP (NT5)
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.

183 lines
5.7 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: CREATETB.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 12/22/2000
  12. *
  13. * DESCRIPTION: Toolbar helpers
  14. *
  15. *******************************************************************************/
  16. #ifndef __CREATETB_H_INCLUDED
  17. #define __CREATETB_H_INCLUDED
  18. #include <windows.h>
  19. #include <commctrl.h>
  20. namespace ToolbarHelper
  21. {
  22. class CToolbarBitmapInfo
  23. {
  24. private:
  25. HBITMAP m_hBitmap;
  26. HWND m_hWndToolbar;
  27. HINSTANCE m_hToolbarInstance;
  28. UINT_PTR m_nBitmapResId;
  29. int m_nButtonCount;
  30. private:
  31. CToolbarBitmapInfo();
  32. public:
  33. CToolbarBitmapInfo( HINSTANCE hToolbarInstance, UINT_PTR nBitmapResId )
  34. : m_hToolbarInstance(hToolbarInstance),
  35. m_nBitmapResId(nBitmapResId),
  36. m_nButtonCount(0),
  37. m_hBitmap(NULL),
  38. m_hWndToolbar(NULL)
  39. {
  40. }
  41. CToolbarBitmapInfo( const CToolbarBitmapInfo &other )
  42. : m_hToolbarInstance(other.ToolbarInstance()),
  43. m_nBitmapResId(other.BitmapResId()),
  44. m_nButtonCount(other.ButtonCount()),
  45. m_hBitmap(other.Bitmap()),
  46. m_hWndToolbar(other.Toolbar())
  47. {
  48. }
  49. CToolbarBitmapInfo &operator=( const CToolbarBitmapInfo &other )
  50. {
  51. if (this != &other)
  52. {
  53. m_hToolbarInstance = other.ToolbarInstance();
  54. m_nBitmapResId = other.BitmapResId();
  55. m_nButtonCount = other.ButtonCount();
  56. m_hBitmap = other.Bitmap();
  57. m_hWndToolbar = other.Toolbar();
  58. }
  59. return *this;
  60. }
  61. HBITMAP Bitmap() const
  62. {
  63. return m_hBitmap;
  64. }
  65. void Bitmap( HBITMAP hBitmap )
  66. {
  67. WIA_PUSH_FUNCTION((TEXT("CToolbarBitmapInfo::Bitmap: 0x%p"), hBitmap ));
  68. m_hBitmap = hBitmap;
  69. }
  70. HWND Toolbar() const
  71. {
  72. return m_hWndToolbar;
  73. }
  74. void Toolbar( HWND hWndToolbar )
  75. {
  76. m_hWndToolbar = hWndToolbar;
  77. }
  78. HINSTANCE ToolbarInstance() const
  79. {
  80. return m_hToolbarInstance;
  81. }
  82. UINT_PTR BitmapResId() const
  83. {
  84. return m_nBitmapResId;
  85. }
  86. int ButtonCount() const
  87. {
  88. return m_nButtonCount;
  89. }
  90. void ButtonCount( int nButtonCount )
  91. {
  92. m_nButtonCount = nButtonCount;
  93. }
  94. bool ReloadAndReplaceBitmap()
  95. {
  96. WIA_PUSH_FUNCTION((TEXT("CToolbarBitmapInfoReloadAndReplaceBitmap( m_hWndToolbar: 0x%p, m_hBitmap: 0x%p, m_hToolbarInstance: 0x%p, m_nBitmapResId: %d )"), m_hWndToolbar, m_hBitmap, m_hToolbarInstance, m_nBitmapResId ));
  97. bool bResult = false;
  98. if (m_hWndToolbar && m_hBitmap && m_hToolbarInstance && m_nBitmapResId)
  99. {
  100. HBITMAP hNewBitmap = CreateMappedBitmap( m_hToolbarInstance, m_nBitmapResId, 0, NULL, 0 );
  101. if (hNewBitmap)
  102. {
  103. TBREPLACEBITMAP TbReplaceBitmap = {0};
  104. TbReplaceBitmap.nIDOld = reinterpret_cast<UINT_PTR>(m_hBitmap);
  105. TbReplaceBitmap.nIDNew = reinterpret_cast<UINT_PTR>(hNewBitmap);
  106. TbReplaceBitmap.nButtons = m_nButtonCount;
  107. if (SendMessage( m_hWndToolbar, TB_REPLACEBITMAP,0,reinterpret_cast<LPARAM>(&TbReplaceBitmap)))
  108. {
  109. m_hBitmap = hNewBitmap;
  110. bResult = true;
  111. //
  112. // Ensure that we don't free this bitmap
  113. //
  114. hNewBitmap = NULL;
  115. }
  116. else
  117. {
  118. WIA_TRACE((TEXT("TB_REPLACEBITMAP failed!")));
  119. }
  120. }
  121. else
  122. {
  123. WIA_TRACE((TEXT("Unable to load bitmap!")));
  124. }
  125. //
  126. // Prevent GDI leak
  127. //
  128. if (hNewBitmap)
  129. {
  130. DeleteObject( hNewBitmap );
  131. }
  132. }
  133. else
  134. {
  135. WIA_TRACE((TEXT("Validation error: m_hWndToolbar: 0x%p, m_hBitmap: 0x%p, m_hToolbarInstance: 0x%p, m_nBitmapResId: %d"), m_hWndToolbar, m_hBitmap, m_hToolbarInstance, m_nBitmapResId ));
  136. }
  137. return bResult;
  138. }
  139. };
  140. struct CButtonDescriptor
  141. {
  142. int iBitmap;
  143. int idCommand;
  144. BYTE fsState;
  145. BYTE fsStyle;
  146. bool bFollowingSeparator;
  147. bool *pbControllingVariable;
  148. int nStringResId;
  149. };
  150. enum
  151. {
  152. AlignLeft = 0x00000000,
  153. AlignHCenter = 0x00000001,
  154. AlignRight = 0x00000002,
  155. AlignTop = 0x00000000,
  156. AlignVCenter = 0x00000004,
  157. AlignBottom = 0x00000008
  158. };
  159. HWND CreateToolbar(
  160. HWND hWndParent,
  161. HWND hWndPrevious,
  162. HWND hWndAlign,
  163. int Alignment,
  164. UINT nToolbarId,
  165. CToolbarBitmapInfo &ToolbarBitmapInfo,
  166. CButtonDescriptor *pButtonDescriptors,
  167. UINT nDescriptorCount );
  168. void SetToolbarButtonState( HWND hWndToolbar, int nButtonId, int nState );
  169. void EnableToolbarButton( HWND hWndToolbar, int nButtonId, bool bEnable );
  170. void CheckToolbarButton( HWND hWndToolbar, int nButtonId, bool bChecked );
  171. UINT GetButtonBarAccelerators( HWND hWndToolbar, ACCEL *pAccelerators, UINT nMaxCount );
  172. }
  173. #endif // __CREATETB_H_INCLUDED