zoukankan      html  css  js  c++  java
  • Dialog和FormView如何派生通用类

    派生通用类涉及到派生类的构造函数需要传递窗口ID和CWnd,所以要在派生类中事先定义好

    在Dialog中构造函数是这样定义的

    public:
        CDialogEx();
        CDialogEx(UINT nIDTemplate, CWnd *pParent = NULL);
        CDialogEx(LPCTSTR lpszTemplateName, CWnd *pParentWnd = NULL);

    所以在派生

    Dialog类时要这样构造
    class CThemeDialogForFixShootSearch : public CDialogEx
    {
        DECLARE_DYNAMIC(CThemeDialogForFixShootSearch)
    
    public:
        CThemeDialogForFixShootSearch(UINT nIDTemplate, CWnd* pParent = NULL);   // standard constructor
        virtual ~CThemeDialogForFixShootSearch();
    }
    #include "stdafx.h"
    #include "ThemeDialogForFixShootSearch.h"
    
    
    
    // CThemeDialogForFixShootSearch dialog
    
    IMPLEMENT_DYNAMIC(CThemeDialogForFixShootSearch, CDialogEx)
    
    CThemeDialogForFixShootSearch::CThemeDialogForFixShootSearch(UINT nIDTemplate, CWnd* pParent /*=NULL*/)
        : CDialogEx(nIDTemplate, pParent)
    {
       
    }
    
    CThemeDialogForFixShootSearch::~CThemeDialogForFixShootSearch()
    {
    }
    
    void CThemeDialogForFixShootSearch::DoDataExchange(CDataExchange* pDX)
    {
        CDialogEx::DoDataExchange(pDX);
    }
    
    
    BEGIN_MESSAGE_MAP(CThemeDialogForFixShootSearch, CDialogEx)
    END_MESSAGE_MAP()
    同样FormView的构造函数为
    protected:      // must derive your own class
        CFormView(LPCTSTR lpszTemplateName);
        CFormView(UINT nIDTemplate);

    因为FormView没有默认构造,所以必须带参数

    #pragma once
    #include "afxext.h"
    
    class CBackgroundColor :public CFormView
    {
        DECLARE_DYNAMIC(CBackgroundColor)
    public:
        CBackgroundColor(UINT nIDTemplate);
        virtual ~CBackgroundColor();
        DECLARE_MESSAGE_MAP()
        afx_msg void OnPaint();
    };
    #include "stdafx.h"
    #include "BackgroundColor.h"
    #include <afxtempl.h>
    IMPLEMENT_DYNAMIC(CBackgroundColor, CFormView)
    CBackgroundColor::CBackgroundColor (UINT nIDTemplate)
    : CFormView(nIDTemplate)
    {
    }
    
    
    CBackgroundColor::~CBackgroundColor()
    {
    }
    BEGIN_MESSAGE_MAP(CBackgroundColor, CFormView)
        ON_WM_PAINT()
    END_MESSAGE_MAP()
     
  • 相关阅读:
    欢迎参加MVP主讲的Windows 10开发线上课程
    SharePoint 2013 重复的管理账户错误:已添加项。字典中的关键字 所添加的关键字
    SharePoint 2013 开发——SharePoint Designer 2013工作流
    SharePoint 2013 开发——构建工作流开发环境
    SharePoint 2013 开发——工作流架构
    SharePoint 2013 开发——APP安全模型
    SharePoint 2013 开发——SharePoint APP介绍
    SharePoint 2013 开发——概述
    win32
    hdu2100 26进制加法
  • 原文地址:https://www.cnblogs.com/ye-ming/p/8880089.html
Copyright © 2011-2022 走看看