概要:
CTurnPageCtrl
|---CTurnPageStatic
|---CTurnPageCombo
代码:
TurnPageCtr.h
// TurnPageCtrl.h: interface for the CTurnPageCtrl class. // // #if !defined(AFX_TURNPAGECTRL_H__7092386C_B27F_4050_A11C_864E2BE02E8D__INCLUDED_) #define AFX_TURNPAGECTRL_H__7092386C_B27F_4050_A11C_864E2BE02E8D__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "TurnPageStatic.h" #include "TurnPageCombo.h" class CTurnPageCtrl { public: CTurnPageCtrl(); virtual ~CTurnPageCtrl(); public: CTurnPageStatic m_staticBegin; CTurnPageStatic m_staticUp; CTurnPageStatic m_staticDown; CTurnPageStatic m_staticEnd; CTurnPageCombo m_combPage; CWnd *m_pParentWnd; int m_iIndex; // 本控件与父窗口的通信约定:用于同一父窗口中使用了多个本控件的时候 // 比如某对话框用了两组分页按钮,第一组的m_iIndex为0,第二组的m_iIndex // 为1,那么当给对话框发消息的时候,携带此m_iIndex,则父窗口就可以分辨出 // 是哪组分页按钮发来的消息 BOOL m_bCreated;// 本控件已创建, 防止重复创建 void CreateChildCtrl(CWnd *pParentWnd, int iIndex = 0); void ShowChildCtrl(BOOL bShow); }; #endif // !defined(AFX_TURNPAGECTRL_H__7092386C_B27F_4050_A11C_864E2BE02E8D__INCLUDED_)
TurnPageCtrl.cpp// TurnPageCtrl.cpp: implementation of the CTurnPageCtrl class. // // #include "stdafx.h" #include "hrinetnsm_con.h" #include "TurnPageCtrl.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif // // Construction/Destruction // CTurnPageCtrl::CTurnPageCtrl() { m_bCreated = FALSE; } CTurnPageCtrl::~CTurnPageCtrl() { } /** * 函数名称: CreateChildCtrl * * 函数功能: 提供给外界,创建本控件 * * 函数参数: pParentWnd 父窗口 * iIndex 本控件为父窗口的第几组分页按钮 */ void CTurnPageCtrl::CreateChildCtrl(CWnd *pParentWnd, int iIndex) { if (m_bCreated) return; m_pParentWnd = pParentWnd; m_iIndex = iIndex; m_staticBegin.m_pParentWnd = m_staticUp.m_pParentWnd = m_staticDown.m_pParentWnd = m_staticEnd.m_pParentWnd = m_combPage.m_pParentWnd = m_pParentWnd; m_staticBegin.m_iIndex = m_staticUp.m_iIndex = m_staticDown.m_iIndex = m_staticEnd.m_iIndex = iIndex; m_staticBegin.m_pageType = PageBegin; m_staticUp.m_pageType = PageUp; m_staticDown.m_pageType = PageDown; m_staticEnd.m_pageType = PageEnd; m_staticBegin.Create(_T("首页"), WS_CHILD|WS_VISIBLE|SS_NOTIFY, CRect(0, 0, 30, 20), m_pParentWnd); m_staticUp.Create(_T("上一页"), WS_CHILD|WS_VISIBLE|SS_NOTIFY, CRect(40, 0, 90, 20), m_pParentWnd); m_staticDown.Create(_T("下一页"), WS_CHILD|WS_VISIBLE|SS_NOTIFY, CRect(100, 0, 150, 20), m_pParentWnd); m_staticEnd.Create(_T("末页"), WS_CHILD|WS_VISIBLE|SS_NOTIFY, CRect(160, 0, 190, 20), m_pParentWnd); m_combPage.Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|CBS_DROPDOWN|CBS_AUTOHSCROLL, CRect(200, 0, 240, 100), m_pParentWnd, IDC_COMBO_PAGE); m_combPage.m_iIndex = iIndex; m_bCreated = TRUE; } /** * 函数名称: ShowChildCtrl * * 函数功能: 显示或隐藏详细信息的控件 * * 函数参数: bShow * TRUE 显示 * FALSE 隐藏 */ void CTurnPageCtrl::ShowChildCtrl(BOOL bShow) { if (m_bCreated) { m_staticBegin.ShowWindow(bShow); m_staticUp.ShowWindow(bShow); m_staticDown.ShowWindow(bShow); m_staticEnd.ShowWindow(bShow); m_combPage.ShowWindow(bShow); } }
TurnPageStatic.h
#if !defined(AFX_TURNPAGESTATIC_H__4A0C0EBB_8E31_490B_81DE_D235B6446520__INCLUDED_) #define AFX_TURNPAGESTATIC_H__4A0C0EBB_8E31_490B_81DE_D235B6446520__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 // TurnPageStatic.h : header file // #include "Static/HandStatic.h" typedef enum _EM_PAGE { PageBegin = 0, PageUp = 1, PageDown = 2, PageEnd = 3 }EM_PAGE; #define WM_TURNPAGE_CLICK WM_USER + 101 / // CTurnPageStatic window class CTurnPageStatic : public CStatic { // Construction public: CTurnPageStatic(); // Attributes public: // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CTurnPageStatic) //}}AFX_VIRTUAL // Implementation public: virtual ~CTurnPageStatic(); // Generated message map functions protected: //{{AFX_MSG(CTurnPageStatic) afx_msg void OnClicked(); afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor); //}}AFX_MSG DECLARE_MESSAGE_MAP() public: EM_PAGE m_pageType; CWnd *m_pParentWnd; int m_iIndex; // 本控件与父窗口的通信约定:用于同一父窗口中使用了多个本控件的时候 // 比如某对话框用了两组分页按钮,第一组的m_iIndex为0,第二组的m_iIndex // 为1,那么当给对话框发消息的时候,携带此m_iIndex,则父窗口就可以分辨出 // 是哪组分页按钮发来的消息 private: CFont m_font; }; / //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_TURNPAGESTATIC_H__4A0C0EBB_8E31_490B_81DE_D235B6446520__INCLUDED_)
TurnPageStatic.cpp// TurnPageStatic.cpp : implementation file // #include "stdafx.h" #include "hrinetnsm_con.h" #include "TurnPageStatic.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif / // CTurnPageStatic CTurnPageStatic::CTurnPageStatic() { } CTurnPageStatic::~CTurnPageStatic() { } BEGIN_MESSAGE_MAP(CTurnPageStatic, CStatic) //{{AFX_MSG_MAP(CTurnPageStatic) ON_CONTROL_REFLECT(BN_CLICKED, OnClicked) ON_WM_SETCURSOR() ON_WM_CTLCOLOR_REFLECT() //}}AFX_MSG_MAP END_MESSAGE_MAP() / // CTurnPageStatic message handlers void CTurnPageStatic::OnClicked() { // TODO: Add your control notification handler code here if (m_pParentWnd->GetSafeHwnd() != NULL) { m_pParentWnd->SendMessage(WM_TURNPAGE_CLICK, (WPARAM)m_pageType, m_iIndex); } } BOOL CTurnPageStatic::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { // TODO: Add your message handler code here and/or call default POINT point; GetCursorPos(&point); if (GetSafeHwnd() != NULL) { CRect rect; GetWindowRect(&rect); if (rect.PtInRect(point)) { ::SetCursor(::LoadCursor(NULL, IDC_HAND)); return true; } } return CStatic::OnSetCursor(pWnd, nHitTest, message); } HBRUSH CTurnPageStatic::CtlColor(CDC* pDC, UINT nCtlColor) { // TODO: Change any attributes of the DC here if (!(HFONT)m_font) { // first time init: create font LOGFONT lf; ::GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT),sizeof(lf),&lf); lf.lfUnderline = TRUE;//具有下划线的文字 m_font.CreateFontIndirect(&lf); } // use underline font and visited/unvisited colors pDC->SelectObject(&m_font); pDC->SetBkMode(TRANSPARENT); // return hollow brush to preserve parent background color // TODO: Return a non-NULL brush if the parent's handler should not be called return NULL; }
TurnPageCombo.h#if !defined(AFX_TURNPAGECOMBO_H__0D622184_382A_4A32_AB4A_DC50C878ACAB__INCLUDED_) #define AFX_TURNPAGECOMBO_H__0D622184_382A_4A32_AB4A_DC50C878ACAB__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 // TurnPageCombo.h : header file // #define WM_TURNPAGE_COMBO WM_USER + 102 / // CTurnPageCombo window class CTurnPageCombo : public CComboBox { // Construction public: CTurnPageCombo(); // Attributes public: // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CTurnPageCombo) //}}AFX_VIRTUAL // Implementation public: virtual ~CTurnPageCombo(); // Generated message map functions protected: //{{AFX_MSG(CTurnPageCombo) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnSelchange(); //}}AFX_MSG DECLARE_MESSAGE_MAP() private: CFont m_font; public: CWnd *m_pParentWnd; int m_iIndex; // 本控件与父窗口的通信约定:用于同一父窗口中使用了多个本控件的时候 // 比如某对话框用了两组分页按钮,第一组的m_iIndex为0,第二组的m_iIndex // 为1,那么当给对话框发消息的时候,携带此m_iIndex,则父窗口就可以分辨出 // 是哪组分页按钮发来的消息 }; / //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_TURNPAGECOMBO_H__0D622184_382A_4A32_AB4A_DC50C878ACAB__INCLUDED_)
TurnPageCombo.cpp// TurnPageCombo.cpp : implementation file // #include "stdafx.h" #include "hrinetnsm_con.h" #include "TurnPageCombo.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif / // CTurnPageCombo CTurnPageCombo::CTurnPageCombo() { } CTurnPageCombo::~CTurnPageCombo() { } BEGIN_MESSAGE_MAP(CTurnPageCombo, CComboBox) //{{AFX_MSG_MAP(CTurnPageCombo) ON_WM_CREATE() ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange) //}}AFX_MSG_MAP END_MESSAGE_MAP() / // CTurnPageCombo message handlers int CTurnPageCombo::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CComboBox::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here LOGFONT lf; ::GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT),sizeof(lf),&lf); m_font.CreateFontIndirect(&lf); SetFont(&m_font); return 0; } void CTurnPageCombo::OnSelchange() { // TODO: Add your control notification handler code here int iIndex = GetCurSel(); if (iIndex != CB_ERR) { if (m_pParentWnd->GetSafeHwnd() != NULL) { m_pParentWnd->SendMessage(WM_TURNPAGE_COMBO, iIndex + 1, m_iIndex);// +1 页码从1开始 } } }