Dlg.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Dlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "PropertySheet.h"
  5. #include "Dlg.h"
  6. #include "MyPropertySheet.h"
  7. #include "about.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CDlg dialog
  15. BEGIN_MESSAGE_MAP(CDlg, CDialog)
  16. //{{AFX_MSG_MAP(CDlg)
  17. ON_WM_SYSCOMMAND()
  18. ON_WM_PAINT()
  19. ON_WM_QUERYDRAGICON()
  20. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  21. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  22. //}}AFX_MSG_MAP
  23. END_MESSAGE_MAP()
  24. CDlg::CDlg(CWnd* pParent /*=NULL*/)
  25. : CDialog(CDlg::IDD, pParent)
  26. {
  27. //{{AFX_DATA_INIT(CDlg)
  28. //}}AFX_DATA_INIT
  29. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  30. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  31. }
  32. void CDlg::DoDataExchange(CDataExchange* pDX)
  33. {
  34. CDialog::DoDataExchange(pDX);
  35. //{{AFX_DATA_MAP(CDlg)
  36. //}}AFX_DATA_MAP
  37. }
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CDlg message handlers
  40. BOOL CDlg::OnInitDialog()
  41. {
  42. CDialog::OnInitDialog();
  43. // Add "About..." menu item to system menu.
  44. // IDM_ABOUTBOX must be in the system command range.
  45. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  46. ASSERT(IDM_ABOUTBOX < 0xF000);
  47. CMenu* pSysMenu = GetSystemMenu(FALSE);
  48. if (pSysMenu != NULL)
  49. {
  50. CString strAboutMenu;
  51. strAboutMenu.LoadString(IDS_ABOUTBOX);
  52. if (!strAboutMenu.IsEmpty())
  53. {
  54. pSysMenu->AppendMenu(MF_SEPARATOR);
  55. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  56. }
  57. }
  58. // Set the icon for this dialog. The framework does this automatically
  59. // when the application's main window is not a dialog
  60. SetIcon(m_hIcon, TRUE); // Set big icon
  61. SetIcon(m_hIcon, FALSE); // Set small icon
  62. return TRUE; // return TRUE unless you set the focus to a control
  63. }
  64. void CDlg::OnSysCommand(UINT nID, LPARAM lParam)
  65. {
  66. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  67. {
  68. CAboutDlg dlgAbout;
  69. dlgAbout.DoModal();
  70. }
  71. else
  72. {
  73. CDialog::OnSysCommand(nID, lParam);
  74. }
  75. }
  76. // If you add a minimize button to your dialog, you will need the code below
  77. // to draw the icon. For MFC applications using the document/view model,
  78. // this is automatically done for you by the framework.
  79. void CDlg::OnPaint()
  80. {
  81. if (IsIconic())
  82. {
  83. CPaintDC dc(this); // device context for painting
  84. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  85. // Center icon in client rectangle
  86. int cxIcon = GetSystemMetrics(SM_CXICON);
  87. int cyIcon = GetSystemMetrics(SM_CYICON);
  88. CRect rect;
  89. GetClientRect(&rect);
  90. int x = (rect.Width() - cxIcon + 1) / 2;
  91. int y = (rect.Height() - cyIcon + 1) / 2;
  92. // Draw the icon
  93. dc.DrawIcon(x, y, m_hIcon);
  94. }
  95. else
  96. {
  97. CDialog::OnPaint();
  98. }
  99. }
  100. // The system calls this to obtain the cursor to display while the user drags
  101. // the minimized window.
  102. HCURSOR CDlg::OnQueryDragIcon()
  103. {
  104. return (HCURSOR) m_hIcon;
  105. }
  106. void CDlg::OnButton1()
  107. {
  108. // property sheet (without help)
  109. CMyPropertySheet propSheet;
  110. // propSheet.EnableStackedTabs(FALSE);
  111. propSheet.DoModal();
  112. }
  113. void CDlg::OnButton2()
  114. {
  115. // wizard mode (with help)
  116. CMyPropertySheet propSheet;
  117. propSheet.SetWizardMode();
  118. propSheet.m_psh.dwFlags |= PSH_HASHELP;
  119. propSheet.DoModal();
  120. }