MFC对话框实现梯形分页
本文实例为大家分享了MFC对话框实现梯形分页的具体代码,供大家参考,具体内容如下
//MFCDlg.h:头文件 // #pragmaonce #include"CMemoCtrl.h" //CMFCDlg对话框 classCMFCDlg:publicCDialogEx { //构造 CMemoCtrlm_Memo; public: CMFCDlg(CWnd*pParent=nullptr);//标准构造函数 //对话框数据 #ifdefAFX_DESIGN_TIME enum{IDD=IDD_MFC_DIALOG}; #endif protected: virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDV支持 //实现 protected: HICONm_hIcon; //生成的消息映射函数 virtualBOOLOnInitDialog(); afx_msgvoidOnPaint(); afx_msgHCURSOROnQueryDragIcon(); DECLARE_MESSAGE_MAP() };
//MFCDlg.cpp:实现文件 // #include"pch.h" #include"framework.h" #include"MFC.h" #include"MFCDlg.h" #include"afxdialogex.h" #ifdef_DEBUG #definenewDEBUG_NEW #endif //CMFCDlg对话框 CMFCDlg::CMFCDlg(CWnd*pParent/*=nullptr*/) :CDialogEx(IDD_MFC_DIALOG,pParent) { m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME); } voidCMFCDlg::DoDataExchange(CDataExchange*pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CMFCDlg,CDialogEx) ON_WM_PAINT() ON_WM_QUERYDRAGICON() END_MESSAGE_MAP() //CMFCDlg消息处理程序 BOOLCMFCDlg::OnInitDialog() { CDialogEx::OnInitDialog(); CRectrect; GetClientRect(rect); rect.top=rect.bottom-18; m_Memo.Create(5,rect,this,8088); m_Memo.SetFont(GetFont()); m_Memo.InsertItem(0,_T("断点")); m_Memo.InsertItem(1,_T("异常设置")); m_Memo.InsertItem(2,_T("输出")); m_Memo.InsertItem(3,_T("查找")); //设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 //执行此操作 SetIcon(m_hIcon,TRUE);//设置大图标 SetIcon(m_hIcon,FALSE);//设置小图标 returnTRUE;//除非将焦点设置到控件,否则返回TRUE } voidCMFCDlg::OnPaint() { CPaintDCdc(this); CDialogEx::OnPaint(); } //当用户拖动最小化窗口时系统调用此函数取得光标 //显示。 HCURSORCMFCDlg::OnQueryDragIcon() { returnstatic_cast(m_hIcon); }
//CMemoCtrl.h #pragmaonce #includeclassCMemoCtrl: publicCWnd { intm_nLeft; intm_nIndex; HCURSORm_hCursor; CArray m_aItems; CArray m_rc; CFontm_font; public: CMemoCtrl(); BOOLCreate(intnIndex,constRECT&rect,CWnd*pParentWnd,UINTnID); DECLARE_MESSAGE_MAP() afx_msgvoidOnPaint(); afx_msgvoidOnLButtonDown(UINTnFlags,CPointpoint); public: voidInsertItem(intnIndex,CStringszItemName); voidSetFont(CFont*pFont); afx_msgvoidOnMouseMove(UINTnFlags,CPointpoint); };
//CMemoCtrl.cpp #include"pch.h" #include"CMemoCtrl.h" CMemoCtrl::CMemoCtrl() { m_nLeft=0; m_nIndex=0; m_hCursor=::LoadCursor(NULL,IDC_HAND); } BOOLCMemoCtrl::Create(intnCount,constRECT&rect,CWnd*pParentWnd,UINTnID) { returnCWnd::Create(NULL,NULL,WS_CHILD|WS_VISIBLE,rect,pParentWnd,nID); } BEGIN_MESSAGE_MAP(CMemoCtrl,CWnd) ON_WM_PAINT() ON_WM_LBUTTONDOWN() ON_WM_MOUSEMOVE() END_MESSAGE_MAP() voidCMemoCtrl::OnPaint() { CPaintDCdc(this); CRectrect,rt,rc; GetClientRect(rect); rt=rect; inti=0; CSizesize; CPointp[5]; m_nLeft=8; m_rc.SetSize(m_aItems.GetSize()); CBrushbr(GetSysColor(COLOR_3DFACE)); dc.FillRect(rect,&br); CFont*pOldFont=dc.SelectObject(&m_font); while(iGetLogFont(&lf); if(m_font.GetSafeHandle()) m_font.DeleteObject(); m_font.CreateFontIndirect(&lf); } voidCMemoCtrl::OnMouseMove(UINTnFlags,CPointpoint) { for(inti=0;i 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。