mrDarker
2025-08-11 bd9942d185fb25b35b0c6e089e5763d45e5c83ce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
// SISButton.cpp : implementation file
//
 
#include "stdafx.h"
#include "SISButton.h"
 
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
 
/////////////////////////////////////////////////////////////////////////////
// CSISButton
 
CSISButton::CSISButton()
{
    m_bSIS = FALSE;
    m_bTracking = FALSE;
 
    ::GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT),sizeof(m_lf),&m_lf);
    m_Font.CreateFontIndirect(&m_lf);
 
    m_RGBTextNormal = RGB(10, 10, 10);
    m_RGBTextDisable = RGB(80, 80, 80);
}
 
CSISButton::~CSISButton()
{
    m_Font.DeleteObject();
}
IMPLEMENT_DYNAMIC(CSISButton, CBitmapButton)
 
BEGIN_MESSAGE_MAP(CSISButton, CBitmapButton)
    //{{AFX_MSG_MAP(CSISButton)
    ON_WM_MOUSEMOVE()
    ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
    ON_MESSAGE(WM_MOUSEHOVER, OnMouseHOver)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()
 
/////////////////////////////////////////////////////////////////////////
//    CSISButton message handlers
 
void CSISButton::OnMouseMove(UINT nFlags, CPoint point) 
{
    //    TODO: Add your message handler code here and/or call default
 
    if (!m_bTracking)
    {
        TRACKMOUSEEVENT tme;
        tme.cbSize = sizeof(tme);
        tme.hwndTrack = m_hWnd;
        tme.dwFlags = TME_LEAVE|TME_HOVER;
        tme.dwHoverTime = 1;
        m_bTracking = _TrackMouseEvent(&tme);
    }
    CBitmapButton::OnMouseMove(nFlags, point);
}
 
BOOL CSISButton::PreTranslateMessage(MSG* pMsg) 
{
    // TODO: Add your specialized code here and/or call the base class
    InitToolTip();
    m_ToolTip.RelayEvent(pMsg);        
    return CButton::PreTranslateMessage(pMsg);
}
 
// Set the tooltip with a string resource
void CSISButton::SetToolTipText(int nId, BOOL bActivate)
{
    CString sText;
 
    // load string resource
    sText.LoadString(nId);
    // If string resource is not empty
    if (sText.IsEmpty() == FALSE) SetToolTipText(&sText, bActivate);
 
}
 
// Set the tooltip with a CString
void CSISButton::SetToolTipText(CString *spText, BOOL bActivate)
{
    // We cannot accept NULL pointer
    if (spText == NULL) return;
 
    // Initialize ToolTip
    InitToolTip();
 
    // If there is no tooltip defined then add it
    if (m_ToolTip.GetToolCount() == 0)
    {
        CRect rectBtn; 
        GetClientRect(rectBtn);
        m_ToolTip.AddTool(this, (LPCTSTR)*spText, rectBtn, 1);
    }
 
    // Set text for tooltip
    m_ToolTip.UpdateTipText((LPCTSTR)*spText, this, 1);
    m_ToolTip.Activate(bActivate);
}
 
void CSISButton::InitToolTip()
{
    if (m_ToolTip.m_hWnd == NULL)
    {
        // Create ToolTip control
        m_ToolTip.Create(this);
        // Create inactive
        m_ToolTip.Activate(FALSE);
    }
} // End of InitToolTip
 
// Activate the tooltip
void CSISButton::ActivateTooltip(BOOL bActivate)
{
    // If there is no tooltip then do nothing
    if (m_ToolTip.GetToolCount() == 0) return;
 
    // Activate tooltip
    m_ToolTip.Activate(bActivate);
} // End of EnableTooltip
 
void CSISButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
    // TODO: Add your code to draw the specified item
 
    CDC *mydc=CDC::FromHandle(lpDrawItemStruct->hDC);
 
    CDC * pMemDC = new CDC;
    pMemDC -> CreateCompatibleDC(mydc);
 
    CBitmap * pOldBitmap;
    pOldBitmap = pMemDC -> SelectObject(&m_Bitmap);
    
    CPoint point(0,0);    
        
    if(lpDrawItemStruct->itemState & ODS_SELECTED)    // Click
    {
        m_bIsDisable = FALSE;
        mydc->BitBlt(0,0,m_ButtonSize.cx,m_ButtonSize.cy,pMemDC,0,m_ButtonSize.cy * 2,SRCCOPY);
    }
    else if (lpDrawItemStruct->itemState & ODS_DISABLED && m_uiImageCount > 3)    // À̹ÌÁö°¡ ³× °³ ÀÌ»óÀ̸頳נ¹øÂ°°¡ Disable
    {
        m_bIsDisable = TRUE;
        mydc->BitBlt(0,0,m_ButtonSize.cx,m_ButtonSize.cy,pMemDC,0,m_ButtonSize.cy * 3,SRCCOPY);
    }
    else
    {
        m_bIsDisable = FALSE;
        if(m_bSIS)    // OverMouse
        {
            mydc->BitBlt(0,0,m_ButtonSize.cx,m_ButtonSize.cy,pMemDC,0,m_ButtonSize.cy,SRCCOPY);
        }
        else    // ÀϹÝ
        {
            mydc->BitBlt(0,0,m_ButtonSize.cx,m_ButtonSize.cy,pMemDC,0,0,SRCCOPY);
        }    
    }
    fPaint(mydc);
 
    // clean up
    pMemDC -> SelectObject(pOldBitmap);
    delete pMemDC;
    pMemDC = NULL;
}
 
// Load a bitmap from the resources in the button, the bitmap has to have 3 buttonsstates next to each other: Up/Down/SIS
BOOL CSISButton::LoadBitmap(UINT bitmapid, UINT uiImageCount)
{
    m_uiImageCount = uiImageCount;
 
    m_Bitmap.Detach();
    m_Bitmap.Attach(::LoadImage(AfxGetResourceHandle(),MAKEINTRESOURCE(bitmapid), IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS));
    BITMAP    bitmapbits;
    m_Bitmap.GetBitmap(&bitmapbits);
    m_ButtonSize.cy = bitmapbits.bmHeight / uiImageCount;
    m_ButtonSize.cx = bitmapbits.bmWidth;
 
    SetWindowPos(NULL, 0, 0, m_ButtonSize.cx, m_ButtonSize.cy, SWP_NOMOVE | SWP_NOOWNERZORDER);
 
    return TRUE;
}
 
LRESULT CSISButton::OnMouseHOver(WPARAM wparam, LPARAM lparam) 
{
    // TODO: Add your message handler code here and/or call default
    m_bSIS=TRUE;
    Invalidate();
    return 0;
}
 
LRESULT CSISButton::OnMouseLeave(WPARAM wparam, LPARAM lparam)
{
    m_bTracking = FALSE;
    m_bSIS=FALSE;
    Invalidate();
    return 0;
}
 
void CSISButton::SetWindowText(CString strText) 
{
    m_strText = strText;
    Invalidate();
}
 
void CSISButton::fPaint(CDC* pDC)
{
    if(m_strText.GetLength())
    {
        if (!m_bIsDisable)
            pDC->SetTextColor(m_RGBTextNormal);
        else
            pDC->SetTextColor(m_RGBTextDisable);
 
        RECT Rect;
        GetClientRect(&Rect);
        pDC->SetBkMode(TRANSPARENT);
        pDC->SelectObject(m_Font);
        pDC->DrawText(m_strText,&Rect,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
    }
}
 
void CSISButton::SetFontSize(int nSize)
{
    m_lf.lfHeight = nSize;
    
    m_Font.DeleteObject();
    
    BOOL bCreated = m_Font.CreateFontIndirect(&m_lf);
 
    Invalidate();
}
 
void CSISButton::SetTextColor(COLORREF rgbNormal, COLORREF rgbDisable)
{
    m_RGBTextNormal = rgbNormal;
    m_RGBTextDisable = rgbDisable;
}
 
void CSISButton::SetSISButtonStyle(UINT uID, int nImgCount)
{
    LoadBitmap(uID, 4);
    Invalidate();
}
 
void CSISButton::SetSISButtonStyle(UINT uID, int nImgCount, CString spTipText)
{
    LoadBitmap(uID, 4);
 
    if (!spTipText.IsEmpty())
        SetToolTipText(&spTipText);
    Invalidate();
}
 
void CSISButton::SetSISButtonStyle(UINT uID, int nImgCount, CString spTipText, CString spBtnText, int nFontSize)
{
    LoadBitmap(uID, 4);
 
    if (!spTipText.IsEmpty())
        SetToolTipText(&spTipText);
    if (nFontSize > 0 && !spBtnText.IsEmpty())
    {
        SetFontSize(nFontSize);
        SetWindowText(spBtnText);
    }
    Invalidate();
}