nbutton.cpp
来自「EVC环境下用SDK开发WINCE的应用程序」· C++ 代码 · 共 107 行
CPP
107 行
// NButton.cpp: implementation of the CNButton class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "navgps.h"
#include "NButton.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CNButton::CNButton()
{
// do not erase bkgnd in default.
// m_bTransparent = TRUE;
// m_crBkgndColor = KEY_COLOR;
}
CNButton::~CNButton()
{
}
BOOL CNButton::Create(LPCTSTR lpszCaption, DWORD dwStyle,
const RECT& rect, CNWnd* pParentWnd, UINT nID)
{
CNWnd* pWnd = this;
return pWnd->Create(_T("BUTTON"), lpszCaption, dwStyle, rect, pParentWnd, nID);
}
void CNButton::OnDrawItem(int /*nIDCtl*/, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// it must be overrided by derived class.
ASSERT(FALSE);
}
/*
BOOL CNButton::OnEraseBkgnd(HDC hdc)
{
// it's unneccessary to erase background in default,
// if want, do it in derived class.
//
return TRUE;
}
*/
void CNButton::PreSubclassWindow()
{
CNWnd::PreSubclassWindow();
DWORD dwStyle = ::GetWindowLong(GetSafeHwnd(), GWL_STYLE);
dwStyle = dwStyle | BS_OWNERDRAW | BS_PUSHBUTTON;
SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle);
}
void CNButton::OnLButtonDblClk(UINT nFlags, POINT point)
{
SendMessage(WM_LBUTTONDOWN, nFlags, MAKELONG(point.x, point.y));
}
//
// we process the WM_PAINT message by ourselves, not by windows,
// for getting better performance, ignore some functions or characters
// not used in the application.
//
void CNButton::OnDraw(HDC hdc)
{
// PAINTSTRUCT ps;
DRAWITEMSTRUCT dis;
RECT rect;
GetClientRect(&rect);
// BeginPaint(GetSafeHwnd(), &ps);
// HFONT hOldFont = (HFONT)::SelectObject(g_hdcUI, GetFont());
// HRGN hOldRgn = (HRGN)::SelectObject(g_hdcUI, GetUpdateRgn());
// Here we assume all the buttons dervied by this class are
// OwnerDraw buttons(in this app, all buttons are ownerdrawed).
// generate drawitem message.
memset(&dis, 0, sizeof(dis));
dis.CtlType = ODT_BUTTON;
dis.itemState = IsWindowEnabled() ? 0 : ODS_DISABLED;
dis.itemState |= (BST_PUSHED & SendMessage(BM_GETSTATE,0,0)) ? ODS_SELECTED : 0;
dis.hwndItem = GetSafeHwnd();
dis.hDC = hdc;//g_hdcUI;
dis.rcItem = rect;
//::SendMessage(GetParent()->GetSafeHwnd(), WM_DRAWITEM,
// (WPARAM)GetDlgCtrlID(GetSafeHwnd()),(LPARAM)&dis);
// for getting best performance, we could call OnDrawItem here(just for our app),
// not following the windows philosophy to process this message.
// If want to do the same with windows, call the prceding commented code.
//
OnDrawItem(0, &dis);
// SelectObject(g_hdcUI, hOldFont);
// SelectObject(g_hdcUI, hOldRgn);
// EndPaint(GetSafeHwnd(), &ps);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?