#include "stdafx.h"
#include "CeBtnST.h"
#include <Windows.h>
#include <initguid.h>
#include <imgguids.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Mask for control's type
#ifndef WM_MOUSELEAVE
#define WM_MOUSELEAVE 0x02A3
#endif
#ifndef DestroyCursor
#define DestroyCursor DestroyIcon
#endif
#define BS_TYPEMASK 0x0000000FL
HBRUSH GetBkBrush( HWND hWnd, UINT nID, HBITMAP hBmBk );
CCeButtonST::CCeButtonST()
{
HGDIOBJ h=::GetStockObject(NULL_BRUSH);
hNullBrush=(HBRUSH)h;
m_PenGrey.CreatePen(PS_SOLID,1,RGB(100,100,100));
m_PenWhite.CreatePen(PS_SOLID,1,RGB(255,255,255));
m_bIsPressed = FALSE;
m_bIsFocused = FALSE;
m_bIsDisabled = FALSE;
m_bMouseOnButton = FALSE;
FreeResources(FALSE);
// Default type is "flat" button
m_bIsFlat = TRUE;
// Button will be tracked also if when the window is inactive (like Internet Explorer)
m_bAlwaysTrack = TRUE;
// By default draw border in "flat" button
m_bDrawBorder = TRUE;
// By default icon is aligned horizontally
m_byAlign = ST_ALIGN_HORIZ;
// By default, for "flat" button, don't draw the focus rect
m_bDrawFlatFocus = FALSE;
// By default the button is not the default button
m_bIsDefault = FALSE;
// Invalid value, since type still unknown
m_nTypeStyle = BS_TYPEMASK;
// By default the button is not a checkbox
m_bIsCheckBox = FALSE;
m_nCheck = 0;
// Set default colors
SetDefaultColors(FALSE);
// No URL defined
SetURL(NULL);
// No cursor defined
m_hCursor = NULL;
m_hOldCursor = NULL;
// No timer defined
m_nTimerId = 0;
// No associated menu
m_hMenu = NULL;
m_hParentWndMenu = NULL;
m_bMenuDisplayed = FALSE;
// transp CRef
m_transpCREF = RGB(255,255,255);
//IImagingFactory *pIImgFactory;
pIImgFactory = NULL;
}
CCeButtonST::~CCeButtonST()
{
if (m_dcBk.m_hDC && m_pbmpOldBk)
{
m_dcBk.SelectObject(m_pbmpOldBk);
} // if
FreeResources();
// Restore old cursor (if any)
if (m_hOldCursor) ::SetCursor(m_hOldCursor);
// Destroy the cursor (if any)
if (m_hCursor) ::DestroyCursor(m_hCursor);
// Destroy the menu (if any)
if (m_hMenu) ::DestroyMenu(m_hMenu);
//free(pIImgFactory);
}
BEGIN_MESSAGE_MAP(CCeButtonST, CButton)
//{{AFX_MSG_MAP(CCeButtonST)
ON_WM_MOUSEMOVE()
ON_CONTROL_REFLECT_EX(BN_CLICKED, OnClicked)
ON_WM_SYSCOLORCHANGE()
ON_WM_ENABLE()
ON_WM_GETDLGCODE()
ON_WM_CTLCOLOR()
ON_WM_DESTROY()
ON_WM_KILLFOCUS()
ON_WM_ACTIVATE()
ON_WM_CANCELMODE()
ON_WM_DRAWITEM()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
//ON_WM_CAPTURECHANGED()
ON_WM_SETCURSOR()
ON_MESSAGE(BM_SETSTYLE, OnSetStyle)
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
END_MESSAGE_MAP()
void CCeButtonST::OnSysColorChange()
{
CButton::OnSysColorChange();
m_dcBk.DeleteDC();
m_bmpBk.DeleteObject();
} // End of OnSysColorChange
void CCeButtonST::DeleteBk()
{
m_dcBk.DeleteDC();
m_bmpBk.DeleteObject();
}
void CCeButtonST::FreeResources(BOOL bCheckForNULL)
{
//if (bCheckForNULL)
//{
// // Destroy icons
// // Note: the following lines MUST be here! even if
// // BoundChecker says they are unnecessary!
// if (m_csIcons[0].hIcon) ::DestroyIcon(m_csIcons[0].hIcon);
// if (m_csIcons[1].hIcon) ::DestroyIcon(m_csIcons[1].hIcon);
// if (m_csIcons[2].hIcon) ::DestroyIcon(m_csIcons[2].hIcon);
//} // if
// memset(&m_csIcons, 0, sizeof(m_csIcons));
// memset(&m_csBitmaps, 0, sizeof(m_csBitmaps));
memset(&m_csImages, 0, sizeof(m_csImages));
} // End of FreeResources
void CCeButtonST::PreSubclassWindow()
{
UINT nBS;
nBS = GetButtonStyle();
// Set initial control type
m_nTypeStyle = nBS & BS_TYPEMASK;
// Check if this is a checkbox
if (nBS & BS_CHECKBOX) m_bIsCheckBox = TRUE;
// Set initial default state flag
if (m_nTypeStyle == BS_DEFPUSHBUTTON)
{
// Set default state for a default button
m_bIsDefault = TRUE;
// Adjust style for default button
m_nTypeStyle = BS_PUSHBUTTON;
} // If
// You should not set the Owner Draw before this call
// (don't use the resource editor "Owner Draw" or
// ModifyStyle(0, BS_OWNERDRAW) before calling PreSubclassWindow() )
ASSERT(m_nTypeStyle != BS_OWNERDRAW);
// Switch to owner-draw
ModifyStyle(BS_TYPEMASK, BS_OWNERDRAW, SWP_FRAMECHANGED);
CButton::PreSubclassWindow();
} // End of PreSubclassWindow
void CCeButtonST::OnDestroy()
{
// Kill timer
if (m_nTimerId) KillTimer(m_nTimerId);
m_nTimerId = 0;
CButton::OnDestroy();
} // End of OnDestroy
UINT CCeButtonST::OnGetDlgCode()
{
UINT nCode = CButton::OnGetDlgCode();
// tell the system if we want default state handling
// (losing default state always allowed)
nCode |= (m_bIsDefault ? DLGC_DEFPUSHBUTTON : DLGC_UNDEFPUSHBUTTON);
return nCode;
} // End of OnGetDlgCode
LRESULT CCeButtonST::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_LBUTTONDBLCLK)
{
message = WM_LBUTTONDOWN;
} // if
return CButton::DefWindowProc(message, wParam, lParam);
} // End of DefWindowProc
HBRUSH CCeButtonST::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
return hNullBrush;//(HBRUSH)::GetStockObject(NULL_BRUSH);
} // End of CtlColor
LRESULT CCeButtonST::OnSetStyle(WPARAM wParam, LPARAM lParam)
{
UINT nNewType = (wParam & BS_TYPEMASK);
// Update default state flag
if (nNewType == BS_DEFPUSHBUTTON)
{
m_bIsDefault = TRUE;
} // if
else if (nNewType == BS_PUSHBUTTON)
{
// Losing default state always allowed
m_bIsDefault = FALSE;
} // if
// Can't change control type after owner-draw is set.
// Let the system process changes to other style bits
// and redrawing, while keeping owner-draw style
return DefWindowProc(BM_SETSTYLE,
(wParam & ~BS_TYPEMASK) | BS_OWNERDRAW, lParam);
} // End of OnSetStyle
void CCeButtonST::OnEnable(BOOL bEnable)
{
CButton::OnEnable(bEnable);
if (bEnable == FALSE)
{
CWnd* pWnd = GetParent()->GetNextDlgTabItem(this);
if (pWnd)
pWnd->SetFocus();
else
GetParent()->SetFocus();
CancelHover();
} // if
} // End of OnEnable
void CCeButtonST::OnKillFocus(CWnd* pNewWnd)
{
CButton::OnKillFocus(pNewWnd);
CancelHover();
} // End of OnKillFocus
void CCeButtonST::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CButton::OnActivate(nState, pWndOther, bMinimized);
if (nState == WA_INACTIVE) CancelHover();
} // End of OnActivate
void CCeButtonST::OnCancelMode()
{
CButton::OnCancelMode();
CancelHover();
} // End of OnCancelMode
void CCeButtonST::OnLButtonDown(UINT nFlags, CPoint point)
{
SetState(TRUE);
#if defined(_WIN32_WCE_PSPC) && (_WIN32_WCE >= 300)
SHRecognizeGesture(point);
#endif // _WIN32_WCE_PSPC
Default();
//CButton::OnLButtonDown(nFlags, point);
} // End of OnLButtonDown
void CCeButtonST::CancelHover()
{
// Only for flat buttons
if (m_bIsFlat)
{
// Kill timer (if active)
if (m_nTimerId) KillTimer(m_nTimerId);
m_nTimerId = 0;
if (m_bMouseOnButton)
{
// Restore old cursor (if any)
if (m_hOldCursor)
{
::SetCursor(m_hOldCursor);
m_hOldCursor = NULL;
} // if
m_bMouseOnButton = FALSE;
Invalidate();
} // if
} // if
} // End of CancelHover
void CCeButtonST::OnMouseMove(UINT nFlags, CPoint point)
{
CWnd* wndUnderMouse = NULL;
CWnd* wndActive = this;
CButton::OnMouseMove(nFlags, point);
ClientToScreen(&point);
wndUnderMouse = WindowFromPoint(point);
// If the mouse enter the button with the left button pressed then do nothing
if (nFlags & MK_LBUTTON && m_bMouseOnButton == FALSE) return;
// If our button is not flat then do nothing
if (m_bIsFlat == FALSE) return;
if (m_bAlwaysTrack == FALSE) wndActive = GetActiveWindow();
if (wndUnderMouse && wndUnderMouse->m_hWnd == m_hWnd && wndActive)
- 1
- 2
- 3
- 4
- 5
前往页