/***************************************************************************** * * Copyright (c) 1999, KL GROUP INC. All Rights Reserved. * http://www.klgroup.com * * This file is provided for demonstration and educational uses only. * Permission to use, copy, modify and distribute this file for * any purpose and without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all * copies, and that the name of KL Group not be used in advertising * or publicity pertaining to this material without the specific, * prior written permission of an authorized representative of * KL Group. * * KL GROUP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. KL GROUP SHALL NOT BE LIABLE FOR ANY * DAMAGES SUFFERED BY USERS AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ // StaticEx.cpp : implementation file // #include "stdafx.h" #include "chlabels.h" #include "StaticEx.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CStaticEx CStaticEx::CStaticEx() { m_colorUnselected = RGB(0,0,0); // black m_colorSelected = RGB(255,0,0); // red m_bSelected = false; // not selected yet } CStaticEx::~CStaticEx() { } BEGIN_MESSAGE_MAP(CStaticEx, CStatic) //{{AFX_MSG_MAP(CStaticEx) ON_WM_CTLCOLOR_REFLECT() // ON_CONTROL_REFLECT(STN_CLICKED, OnClicked) //}}AFX_MSG_MAP END_MESSAGE_MAP() ////////////////// // Handle reflected WM_CTLCOLOR to set custom control color. // For a text control, use selected/unselected colors. // For non-text controls, do nothing. Also ensures SS_NOTIFY is on. // HBRUSH CStaticEx::CtlColor(CDC* pDC, UINT nCtlColor) { char FontName[32] = "Times New Roman"; ASSERT(nCtlColor == CTLCOLOR_STATIC); DWORD dwStyle = GetStyle(); if (!(dwStyle & SS_NOTIFY)) { // Turn on notify flag to get mouse messages and STN_CLICKED. // Otherwise, I'll never get any mouse clicks! ::SetWindowLong(m_hWnd, GWL_STYLE, dwStyle | SS_NOTIFY); } HBRUSH hbr = NULL; if ((dwStyle & 0xFF) <= SS_RIGHT) { // this is a text control: set up font and colors if (!(HFONT)m_font) { // first time init: create font LOGFONT lf; GetFont()->GetObject(sizeof(lf), &lf); // We'd Like Times New Roman for the label strcpy(lf.lfFaceName, FontName); // Change the font size lf.lfHeight = -21; lf.lfWidth = -9; // Make it BOLD lf.lfWeight = FW_BOLD; m_font.CreateFontIndirect(&lf); } // use selected/unselected colors pDC->SelectObject(&m_font); pDC->SetTextColor(m_bSelected ? m_colorSelected : m_colorUnselected); pDC->SetBkMode(TRANSPARENT); // return hollow brush to preserve parent background color hbr = (HBRUSH)::GetStockObject(HOLLOW_BRUSH); } return hbr; } void CStaticEx::SetHilight(bool bHilight /* = TRUE */ ) { // set this flag to change the font color m_bSelected = bHilight; InvalidateRect(NULL); }