|
#include "stdafx.h"
#include "NGXPStyleButton.h"
#include <Windows.h>
#include <Winuser.h>
//#if(WINVER >= 0x0501)
#ifdef THEMEAPI
#include <tmschema.h>
#else
#define NO_THEMEAPI_FOUND
#define BP_PUSHBUTTON 0x00000001
#define PBS_NORMAL 0x00000001
#define PBS_HOT 0x00000002
#define PBS_PRESSED 0x00000003
#define PBS_DISABLED 0x00000004
#define PBS_DEFAULTED 0x00000005
#endif
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CNGXPStyleButton::CNGXPStyleButton()
{
// No theme helper
m_pTheme = NULL;
}
CNGXPStyleButton::~CNGXPStyleButton()
{
}
// This function is called every time the button border needs to be painted.
// If the button is in standard (not flat) mode this function will NOT be called.
// This is a virtual function that can be rewritten in CButtonST-derived classes
// to produce a whole range of buttons not available by default.
//
// Parameters:
// [IN] pDC
// Pointer to a CDC object that indicates the device context.
// [IN] pRect
// Pointer to a CRect object that indicates the bounds of the
// area to be painted.
//
// Return value:
// BTNST_OK
// Function executed successfully.
//
DWORD CNGXPStyleButton::OnDrawBorder(CDC* pDC, LPCRECT pRect)
{
if (m_pTheme == NULL || m_pTheme->IsAppThemed() == FALSE)
{
return CNGButton::OnDrawBorder(pDC, pRect);
} // if
return BTNST_OK;
} // End of OnDrawBorder
// This function is called every time the button background needs to be painted.
// If the button is in transparent mode this function will NOT be called.
// This is a virtual function that can be rewritten in CButtonST-derived classes
// to produce a whole range of buttons not available by default.
//
// Parameters:
// [IN] pDC
// Pointer to a CDC object that indicates the device context.
// [IN] pRect
// Pointer to a CRect object that indicates the bounds of the
// area to be painted.
//
// Return value:
// BTNST_OK
// Function executed successfully.
//
DWORD CNGXPStyleButton::OnDrawBackground(CDC* pDC, LPCRECT pRect)
{
BOOL bDefaultDraw = FALSE;
// No theme helper passed
if (m_pTheme == NULL || m_pTheme->IsAppThemed() == FALSE)
{
bDefaultDraw = TRUE;
} // if
else
{
HTHEME hTheme = NULL;
int iStateId = 0;
if (m_bDrawBorder)
{
hTheme = m_pTheme->OpenThemeData(GetSafeHwnd(), L"BUTTON");
}
else
{
// AJM 29.11.2002 this allows us to create toolbar like buttons
// on dialog bars (the default ones just don't look right)
hTheme = m_pTheme->OpenThemeData(GetSafeHwnd(), L"TOOLBAR");
}
if (hTheme)
{
m_bIsFlat = TRUE; // Needed otherwise the button won't paint correctly
iStateId = PBS_NORMAL; // Normal
if (m_bIsDefault) iStateId = PBS_DEFAULTED; // Default button
if (m_bMouseOnButton) iStateId = PBS_HOT; // Hot
if (m_bIsPressed) iStateId = PBS_PRESSED; // Pressed
if (m_bIsDisabled) iStateId = PBS_DISABLED; // Disabled
m_pTheme->DrawThemeBackground(hTheme, m_hWnd, pDC->GetSafeHdc(), BP_PUSHBUTTON, iStateId, pRect, NULL);
m_pTheme->CloseThemeData(hTheme);
} // if
else
{
bDefaultDraw = TRUE;
} // else
} // else
if (bDefaultDraw)
{
return CNGButton::OnDrawBackground(pDC, pRect);
} // if
return BTNST_OK;
} // End of OnDrawBackground
// This function assigns a CThemeHelperST instance to the button.
//
// Parameters:
// [IN] pTheme
// Pointer to a CThemeHelperST instance.
// Pass NULL to remove any previous instance.
//
void CNGXPStyleButton::SetThemeHelper(CNGThemeHelper* pTheme)
{
m_pTheme = pTheme;
} // End of SetThemeHelper
#ifdef NO_THEMEAPI_FOUND
#undef NO_THEMEAPI_FOUND
#undef BP_PUSHBUTTON
#undef PBS_NORMAL
#undef PBS_HOT
#undef PBS_PRESSED
#undef PBS_DISABLED
#undef PBS_DEFAULTED
#endif
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I haven't always written software for a living. When I graduated from Surrey University in 1989, it was with an Electronic Engineering degree, but unfortunately that never really gave me the opportunity to do anything particularly interesting (with the possible exception of designing
Darth Vader's Codpiece * for the UK Army in 1990).
* Also known as the Standard Army Bootswitch. But that's another story...
Since the opportunity arose to lead a software team developing C++ software for
Avionic Test Systems in 1996, I've not looked back. More recently I've been involved in the development of subsea acoustic navigation systems, digital TV broadcast systems, port security/tracking systems, and most recently software development tools with my own company,
Riverblade Ltd.
One of my personal specialities is IDE plug-in development.
ResOrg was my first attempt at a plug-in, but my day to day work is with
Visual Lint, an interactive code analysis tool environment with works within the Visual Studio and Eclipse IDEs or on build servers.
I love lots of things, but particularly music, photography and anything connected with history or engineering. I
despise ignorant, intolerant and obstructive people - and it shows...I can be a bolshy cow if you wind me up the wrong way...
I'm currently based 15 minutes walk from the beach in Bournemouth on the south coast of England. Since I moved here I've grown to love the place - even if it is full of grockles in Summer!