Strona Główna   Lista Obszarów Nazw   Lista Alfabetyczna   Lista Klas   Lista Plików   Składowe Klas   Składowe Plików  

BtnST.h

Idź do dokumentacji tego pliku.
00001 //
00002 //      Class:          CButtonST
00003 //
00004 //      Compiler:       Visual C++
00005 //      Tested on:      Visual C++ 5.0
00006 //                              Visual C++ 6.0
00007 //
00008 //      Version:        See GetVersionC() or GetVersionI()
00009 //
00010 //      Created:        xx/xxxx/1998
00011 //      Updated:        25/November/2002
00012 //
00013 //      Author:         Davide Calabro'         davide_calabro@yahoo.com
00014 //                                                                      http://www.softechsoftware.it
00015 //
00016 //      Note:           Code for the PreSubclassWindow and OnSetStyle functions
00017 //                              has been taken from the COddButton class
00018 //                              published by Paolo Messina and Jerzy Kaczorowski
00019 //
00020 //      Disclaimer
00021 //      ----------
00022 //      THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT
00023 //      ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE
00024 //      DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE
00025 //      RISK OF USING THIS SOFTWARE.
00026 //
00027 //      Terms of use
00028 //      ------------
00029 //      THIS SOFTWARE IS FREE FOR PERSONAL USE OR FREEWARE APPLICATIONS.
00030 //      IF YOU USE THIS SOFTWARE IN COMMERCIAL OR SHAREWARE APPLICATIONS YOU
00031 //      ARE GENTLY ASKED TO DONATE 5$ (FIVE U.S. DOLLARS) TO THE AUTHOR:
00032 //
00033 //              Davide Calabro'
00034 //              P.O. Box 65
00035 //              21019 Somma Lombardo (VA)
00036 //              Italy
00037 //
00038 #ifndef _BTNST_H
00039 #define _BTNST_H
00040 
00041 // Uncomment the following 2 lines to enable support for BCMenu class
00042 //#define       BTNST_USE_BCMENU
00043 //#include "BCMenu.h"
00044 
00045 // Uncomment the following line to enable support for sound effects
00046 #define BTNST_USE_SOUND
00047 
00048 #if _MSC_VER >= 1000
00049 #pragma once
00050 #endif // _MSC_VER >= 1000
00051 
00052 // Return values
00053 #ifndef BTNST_OK
00054 #define BTNST_OK                                                0
00055 #endif
00056 #ifndef BTNST_INVALIDRESOURCE
00057 #define BTNST_INVALIDRESOURCE                   1
00058 #endif
00059 #ifndef BTNST_FAILEDMASK
00060 #define BTNST_FAILEDMASK                                2
00061 #endif
00062 #ifndef BTNST_INVALIDINDEX
00063 #define BTNST_INVALIDINDEX                              3
00064 #endif
00065 #ifndef BTNST_INVALIDALIGN
00066 #define BTNST_INVALIDALIGN                              4
00067 #endif
00068 #ifndef BTNST_BADPARAM
00069 #define BTNST_BADPARAM                                  5
00070 #endif
00071 #ifndef BTNST_INVALIDPRESSEDSTYLE
00072 #define BTNST_INVALIDPRESSEDSTYLE               6
00073 #endif
00074 
00075 // Dummy identifier for grayscale icon
00076 #ifndef BTNST_AUTO_GRAY
00077 #define BTNST_AUTO_GRAY                                 (HICON)(0xffffffff - 1L)
00078 #endif
00079 
00080 class CButtonST : public CButton
00081 {
00082 public:
00083     CButtonST();
00084         ~CButtonST();
00085 
00086     enum        {       ST_ALIGN_HORIZ  = 0,                    // Icon/bitmap on the left, text on the right
00087                                 ST_ALIGN_VERT,                                  // Icon/bitmap on the top, text on the bottom
00088                                 ST_ALIGN_HORIZ_RIGHT,                   // Icon/bitmap on the right, text on the left
00089                                 ST_ALIGN_OVERLAP                                // Icon/bitmap on the same space as text
00090                         };
00091 
00092         enum    {       BTNST_COLOR_BK_IN       = 0,            // Background color when mouse is INside
00093                                 BTNST_COLOR_FG_IN,                              // Text color when mouse is INside
00094                                 BTNST_COLOR_BK_OUT,                             // Background color when mouse is OUTside
00095                                 BTNST_COLOR_FG_OUT,                             // Text color when mouse is OUTside
00096                                 BTNST_COLOR_BK_FOCUS,                   // Background color when the button is focused
00097                                 BTNST_COLOR_FG_FOCUS,                   // Text color when the button is focused
00098 
00099                                 BTNST_MAX_COLORS
00100                         };
00101 
00102     enum        {       BTNST_PRESSED_LEFTRIGHT = 0,    // Pressed style from left to right (as usual)
00103                                 BTNST_PRESSED_TOPBOTTOM                 // Pressed style from top to bottom
00104                         };
00105 
00106         // ClassWizard generated virtual function overrides
00107     //{{AFX_VIRTUAL(CButtonST)
00108         public:
00109         virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
00110         virtual BOOL PreTranslateMessage(MSG* pMsg);
00111         protected:
00112         virtual void PreSubclassWindow();
00113         //}}AFX_VIRTUAL
00114 
00115 public:
00116         DWORD SetDefaultColors(BOOL bRepaint = TRUE);
00117         DWORD SetColor(BYTE byColorIndex, COLORREF crColor, BOOL bRepaint = TRUE);
00118         DWORD GetColor(BYTE byColorIndex, COLORREF* crpColor);
00119         DWORD OffsetColor(BYTE byColorIndex, short shOffset, BOOL bRepaint = TRUE);
00120 
00121         DWORD SetCheck(int nCheck, BOOL bRepaint = TRUE);
00122         int GetCheck();
00123 
00124         DWORD SetURL(LPCTSTR lpszURL = NULL);
00125         void DrawTransparent(BOOL bRepaint = FALSE);
00126         DWORD SetBk(CDC* pDC);
00127 
00128         BOOL GetDefault();
00129         DWORD SetAlwaysTrack(BOOL bAlwaysTrack = TRUE);
00130 
00131         void SetTooltipText(int nText, BOOL bActivate = TRUE);
00132         void SetTooltipText(LPCTSTR lpszText, BOOL bActivate = TRUE);
00133         void ActivateTooltip(BOOL bEnable = TRUE);
00134         DWORD EnableBalloonTooltip();
00135 
00136         DWORD SetBtnCursor(int nCursorId = NULL, BOOL bRepaint = TRUE);
00137 
00138         DWORD SetFlat(BOOL bFlat = TRUE, BOOL bRepaint = TRUE);
00139         DWORD SetAlign(BYTE byAlign, BOOL bRepaint = TRUE);
00140         DWORD SetPressedStyle(BYTE byStyle, BOOL bRepaint = TRUE);
00141 
00142         DWORD DrawBorder(BOOL bDrawBorder = TRUE, BOOL bRepaint = TRUE);
00143         DWORD DrawFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint = TRUE);
00144 
00145         DWORD SetIcon(int nIconIn, int nIconOut = NULL);
00146         DWORD SetIcon(HICON hIconIn, HICON hIconOut = NULL);
00147 
00148         DWORD SetBitmaps(int nBitmapIn, COLORREF crTransColorIn, int nBitmapOut = NULL, COLORREF crTransColorOut = 0);
00149         DWORD SetBitmaps(HBITMAP hBitmapIn, COLORREF crTransColorIn, HBITMAP hBitmapOut = NULL, COLORREF crTransColorOut = 0);
00150 
00151         void SizeToContent();
00152 
00153 #ifdef  BTNST_USE_BCMENU
00154         DWORD SetMenu(UINT nMenu, HWND hParentWnd, BOOL bWinXPStyle = TRUE, UINT nToolbarID = NULL, CSize sizeToolbarIcon = CSize(16, 16), COLORREF crToolbarBk = RGB(255, 0, 255), BOOL bRepaint = TRUE);
00155 #else
00156         DWORD SetMenu(UINT nMenu, HWND hParentWnd, BOOL bRepaint = TRUE);
00157 #endif
00158         DWORD SetMenuCallback(HWND hWnd, UINT nMessage, LPARAM lParam = 0);
00159 
00160 #ifdef  BTNST_USE_SOUND
00161         DWORD SetSound(LPCTSTR lpszSound, HMODULE hMod = NULL, BOOL bPlayOnClick = FALSE, BOOL bPlayAsync = TRUE);
00162 #endif
00163 
00164         static short GetVersionI()              {return 38;}
00165         static LPCTSTR GetVersionC()    {return (LPCTSTR)_T("3.8");}
00166 
00167         BOOL    m_bShowDisabledBitmap;
00168         POINT   m_ptImageOrg;
00169         POINT   m_ptPressedOffset;
00170 
00171 protected:
00172     //{{AFX_MSG(CButtonST)
00173         afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
00174         afx_msg void OnKillFocus(CWnd* pNewWnd);
00175         afx_msg void OnMouseMove(UINT nFlags, CPoint point);
00176         afx_msg void OnSysColorChange();
00177         afx_msg BOOL OnClicked();
00178         afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
00179         afx_msg void OnEnable(BOOL bEnable);
00180         afx_msg void OnCancelMode();
00181         afx_msg UINT OnGetDlgCode();
00182         //}}AFX_MSG
00183 
00184 #ifdef  BTNST_USE_BCMENU
00185         afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);
00186         afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
00187 #endif
00188 
00189         afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
00190         HICON CreateGrayscaleIcon(HICON hIcon);
00191         virtual DWORD OnDrawBackground(CDC* pDC, CRect* pRect);
00192         virtual DWORD OnDrawBorder(CDC* pDC, CRect* pRect);
00193 
00194         BOOL            m_bIsFlat;                      // Is a flat button?
00195         BOOL            m_bMouseOnButton;       // Is mouse over the button?
00196         BOOL            m_bDrawTransparent;     // Draw transparent?
00197         BOOL            m_bIsPressed;           // Is button pressed?
00198         BOOL            m_bIsFocused;           // Is button focused?
00199         BOOL            m_bIsDisabled;          // Is button disabled?
00200         BOOL            m_bIsDefault;           // Is default button?
00201         BOOL            m_bIsCheckBox;          // Is the button a checkbox?
00202         BYTE            m_byAlign;                      // Align mode
00203         BOOL            m_bDrawBorder;          // Draw border?
00204         BOOL            m_bDrawFlatFocus;       // Draw focus rectangle for flat button?
00205         COLORREF        m_crColors[BTNST_MAX_COLORS];   // Colors to be used
00206         HWND            m_hParentWndMenu;       // Handle to window for menu selection
00207         BOOL            m_bMenuDisplayed;       // Is menu displayed ?
00208 
00209 #ifdef  BTNST_USE_BCMENU
00210         BCMenu          m_menuPopup;            // BCMenu class instance
00211 #else
00212         HMENU           m_hMenu;                        // Handle to associated menu
00213 #endif
00214 
00215 private:
00216         LRESULT OnSetCheck(WPARAM wParam, LPARAM lParam);
00217         LRESULT OnGetCheck(WPARAM wParam, LPARAM lParam);
00218         LRESULT OnSetStyle(WPARAM wParam, LPARAM lParam);
00219         LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);
00220 
00221         void CancelHover();
00222         void FreeResources(BOOL bCheckForNULL = TRUE);
00223         void PrepareImageRect(BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, DWORD dwWidth, DWORD dwHeight, CRect* rpImage);
00224         HBITMAP CreateBitmapMask(HBITMAP hSourceBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTransColor);
00225         virtual void DrawTheIcon(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled);
00226         virtual void DrawTheBitmap(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled);
00227         virtual void DrawTheText(CDC* pDC, LPCTSTR lpszText, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled);
00228         void PaintBk(CDC* pDC);
00229 
00230         void InitToolTip();
00231 
00232         HCURSOR         m_hCursor;                      // Handle to cursor
00233         CToolTipCtrl m_ToolTip;                 // Tooltip
00234 
00235         CDC                     m_dcBk;
00236         CBitmap         m_bmpBk;
00237         CBitmap*        m_pbmpOldBk;
00238 
00239         BOOL            m_bAlwaysTrack;         // Always hilight button?
00240         int                     m_nCheck;                       // Current value for checkbox
00241         UINT            m_nTypeStyle;           // Button style
00242         DWORD           m_dwToolTipStyle;       // Style of tooltip control
00243 
00244         TCHAR           m_szURL[_MAX_PATH];     // URL to open when clicked
00245 
00246 #pragma pack(1)
00247         typedef struct _STRUCT_ICONS
00248         {
00249                 HICON           hIcon;                  // Handle to icon
00250                 DWORD           dwWidth;                // Width of icon
00251                 DWORD           dwHeight;               // Height of icon
00252         } STRUCT_ICONS;
00253 #pragma pack()
00254 
00255 #pragma pack(1)
00256         typedef struct _STRUCT_BITMAPS
00257         {
00258                 HBITMAP         hBitmap;                // Handle to bitmap
00259                 DWORD           dwWidth;                // Width of bitmap
00260                 DWORD           dwHeight;               // Height of bitmap
00261                 HBITMAP         hMask;                  // Handle to mask bitmap
00262                 COLORREF        crTransparent;  // Transparent color
00263         } STRUCT_BITMAPS;
00264 #pragma pack()
00265 
00266 #pragma pack(1)
00267         typedef struct _STRUCT_CALLBACK
00268         {
00269                 HWND            hWnd;                   // Handle to window
00270                 UINT            nMessage;               // Message identifier
00271                 WPARAM          wParam;
00272                 LPARAM          lParam;
00273         } STRUCT_CALLBACK;
00274 #pragma pack()
00275 
00276         STRUCT_ICONS    m_csIcons[2];
00277         STRUCT_BITMAPS  m_csBitmaps[2];
00278 
00279         STRUCT_CALLBACK m_csCallbacks;
00280 
00281 #ifdef  BTNST_USE_SOUND
00282 #pragma pack(1)
00283         typedef struct _STRUCT_SOUND
00284         {
00285                 TCHAR           szSound[_MAX_PATH];
00286                 LPCTSTR         lpszSound;
00287                 HMODULE         hMod;
00288                 DWORD           dwFlags;
00289         } STRUCT_SOUND;
00290 #pragma pack()
00291 
00292         STRUCT_SOUND    m_csSounds[2];  // Index 0 = Over       1 = Clicked
00293 #endif
00294 
00295         DECLARE_MESSAGE_MAP()
00296 };
00297 
00298 //{{AFX_INSERT_LOCATION}}
00299 // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
00300 
00301 #endif

Wygenerowano Mon Feb 17 16:20:02 2003 dla FormCreator programem doxygen1.2.16