Chinaunix首页 | 论坛 | 博客
  • 博客访问: 90521
  • 博文数量: 50
  • 博客积分: 1086
  • 博客等级: 少尉
  • 技术积分: 420
  • 用 户 组: 普通用户
  • 注册时间: 2011-10-25 16:16
文章分类
文章存档

2011年(50)

我的朋友

分类: C/C++

2011-11-15 18:55:07

  1. #pragma once
  2. #define IDC_BUTTON 1001
  3. class CDialog_ControlView : public CView
  4. {
  5. protected: // 仅从序列化创建
  6.  CDialog_ControlView();
  7.  DECLARE_DYNCREATE(CDialog_ControlView)
  8. // 属性
  9. public:
  10.  CDialog_ControlDoc* GetDocument() const;
  11. // 操作
  12. public:
  13.  CButton m_button;
  14. // 重写
  15. public:
  16.  virtual void OnDraw(CDC* pDC); // 重写以绘制该视图
  17.  virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  18. protected:
  19.  virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
  20.  virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
  21.  virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
  22. // 实现
  23. public:
  24.  virtual ~CDialog_ControlView();
  25. #ifdef _DEBUG
  26.  virtual void AssertValid() const;
  27.  virtual void Dump(CDumpContext& dc) const;
  28. #endif
  29. protected:
  30. // 生成的消息映射函数
  31. protected:
  32.  //{{AFX_MSG(CDialog_ControlView)
  33.  afx_msg void OnButton();
  34.  //}}AFX_MSG
  35.  DECLARE_MESSAGE_MAP()
  36. };
  37. #ifndef _DEBUG // Dialog_ControlView.cpp 中的调试版本
  38. inline CDialog_ControlDoc* CDialog_ControlView::GetDocument() const
  39.    { return reinterpret_cast<CDialog_ControlDoc*>(m_pDocument); }
  40. #endif

  41. ————————————————————————————————————————————————————————————————————

  42. // Dialog_ControlView.cpp : CDialog_ControlView 类的实现
  43. //
  44. #include "stdafx.h"
  45. #include "Dialog_Control.h"
  46. #include "Dialog_ControlDoc.h"
  47. #include "Dialog_ControlView.h"
  48. #ifdef _DEBUG
  49. #define new DEBUG_NEW
  50. #endif

  51. // CDialog_ControlView
  52. IMPLEMENT_DYNCREATE(CDialog_ControlView, CView)
  53. BEGIN_MESSAGE_MAP(CDialog_ControlView, CView)
  54.  //{{AFX_MSG_MAP(CDialog_ControlView)
  55.  ON_BN_CLICKED(IDC_BUTTON, OnButton)
  56.  //}}AFX_MSG_MAP
  57.  // 标准打印命令
  58.  ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
  59.  ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
  60.  ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
  61.  ON_WM_SIZE()
  62. END_MESSAGE_MAP()
  63. // CDialog_ControlView 构造/析构
  64. CDialog_ControlView::CDialog_ControlView()
  65. {
  66.  // TODO: 在此处添加构造代码
  67. }
  68. CDialog_ControlView::~CDialog_ControlView()
  69. {
  70. }
  71. BOOL CDialog_ControlView::PreCreateWindow(CREATESTRUCT& cs)
  72. {
  73.  // TODO: 在此处通过修改
  74.  // CREATESTRUCT cs 来修改窗口类或样式
  75.  return CView::PreCreateWindow(cs);
  76. }
  77. // CDialog_ControlView 绘制
  78. void CDialog_ControlView::OnDraw(CDC* /*pDC*/)
  79. {
  80.  CDialog_ControlDoc* pDoc = GetDocument();
  81.  ASSERT_VALID(pDoc);
  82.  if (!pDoc)
  83.   return;
  84.  // TODO: 在此处为本机数据添加绘制代码
  85.   //创建按钮
  86.   m_button.Create(
  87.   //按钮标题
  88.   "i am a dynimic button",
  89.   //按钮风格
  90.   WS_CHILD|WS_VISIBLE|WS_BORDER,
  91.   //按钮大小
  92.   CRect(300,40,500,80),
  93.   //按钮父指针
  94.   this,
  95.   //该按钮对应的ID号
  96.   IDC_BUTTON);
  97. }

  98. // CDialog_ControlView 打印
  99. BOOL CDialog_ControlView::OnPreparePrinting(CPrintInfo* pInfo)
  100. {
  101.  // 默认准备
  102.  return DoPreparePrinting(pInfo);
  103. }
  104. void CDialog_ControlView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  105. {
  106.  // TODO: 添加额外的打印前进行的初始化过程
  107. }
  108. void CDialog_ControlView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  109. {
  110.  // TODO: 添加打印后进行的清理过程
  111. }

  112. // CDialog_ControlView 诊断
  113. #ifdef _DEBUG
  114. void CDialog_ControlView::AssertValid() const
  115. {
  116.  CView::AssertValid();
  117. }
  118. void CDialog_ControlView::Dump(CDumpContext& dc) const
  119. {
  120.  CView::Dump(dc);
  121. }
  122. CDialog_ControlDoc* CDialog_ControlView::GetDocument() const // 非调试版本是内联的
  123. {
  124.  ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDialog_ControlDoc)));
  125.  return (CDialog_ControlDoc*)m_pDocument;
  126. }
  127. #endif //_DEBUG

  128. // CDialog_ControlView 消息处理程序
  129. void CDialog_ControlView::OnButton()
  130. {
  131.  MessageBox("okk");
  132. }
阅读(545) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~