EasySizeDemoDlg.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // EasySizeDemoDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "EasySizeDemo.h"
  5. #include "EasySizeDemoDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CAboutDlg dialog used for App About
  13. class CAboutDlg : public CDialog
  14. {
  15. public:
  16. CAboutDlg();
  17. // Dialog Data
  18. //{{AFX_DATA(CAboutDlg)
  19. enum { IDD = IDD_ABOUTBOX };
  20. //}}AFX_DATA
  21. // ClassWizard generated virtual function overrides
  22. //{{AFX_VIRTUAL(CAboutDlg)
  23. protected:
  24. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  25. //}}AFX_VIRTUAL
  26. // Implementation
  27. protected:
  28. //{{AFX_MSG(CAboutDlg)
  29. //}}AFX_MSG
  30. DECLARE_MESSAGE_MAP()
  31. };
  32. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  33. {
  34. //{{AFX_DATA_INIT(CAboutDlg)
  35. //}}AFX_DATA_INIT
  36. }
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CAboutDlg)
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  44. //{{AFX_MSG_MAP(CAboutDlg)
  45. // No message handlers
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CEasySizeDemoDlg dialog
  50. CEasySizeDemoDlg::CEasySizeDemoDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CEasySizeDemoDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CEasySizeDemoDlg)
  54. // NOTE: the ClassWizard will add member initialization here
  55. //}}AFX_DATA_INIT
  56. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  57. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  58. }
  59. void CEasySizeDemoDlg::DoDataExchange(CDataExchange* pDX)
  60. {
  61. CDialog::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CEasySizeDemoDlg)
  63. // NOTE: the ClassWizard will add DDX and DDV calls here
  64. //}}AFX_DATA_MAP
  65. }
  66. BEGIN_MESSAGE_MAP(CEasySizeDemoDlg, CDialog)
  67. //{{AFX_MSG_MAP(CEasySizeDemoDlg)
  68. ON_WM_SYSCOMMAND()
  69. ON_WM_PAINT()
  70. ON_WM_QUERYDRAGICON()
  71. ON_WM_SIZE()
  72. ON_WM_SIZING()
  73. //}}AFX_MSG_MAP
  74. END_MESSAGE_MAP()
  75. BEGIN_EASYSIZE_MAP(CEasySizeDemoDlg)
  76. EASYSIZE(IDC_TITLE,ES_BORDER,ES_BORDER,ES_BORDER,ES_KEEPSIZE,ES_HCENTER)
  77. EASYSIZE(IDC_RADIO1,ES_BORDER,ES_BORDER,ES_KEEPSIZE,ES_KEEPSIZE,0)
  78. EASYSIZE(IDC_RADIO2,ES_BORDER,ES_BORDER,ES_KEEPSIZE,ES_KEEPSIZE,0)
  79. EASYSIZE(IDC_STATUSFRAME,ES_BORDER,ES_KEEPSIZE,ES_BORDER,ES_BORDER,0)
  80. EASYSIZE(IDC_STATUS,ES_BORDER,ES_KEEPSIZE,ES_BORDER,ES_BORDER,0)
  81. EASYSIZE(IDOK,ES_KEEPSIZE,ES_KEEPSIZE,ES_BORDER,ES_BORDER,0)
  82. EASYSIZE(IDCANCEL,ES_KEEPSIZE,ES_KEEPSIZE,ES_BORDER,ES_BORDER,0)
  83. EASYSIZE(IDC_MYICON2,ES_BORDER,ES_BORDER,IDC_TITLE,ES_KEEPSIZE,ES_HCENTER)
  84. EASYSIZE(IDC_CONTENT,IDC_TITLE,ES_BORDER,ES_BORDER,ES_BORDER,0)
  85. EASYSIZE(IDC_MIDFRAME,ES_BORDER,ES_BORDER,IDC_CONTENT,ES_BORDER,0)
  86. EASYSIZE(IDC_MIDRECT,ES_BORDER,ES_BORDER,IDC_CONTENT,ES_BORDER,0)
  87. EASYSIZE(IDC_MYICON1,IDC_MIDRECT,IDC_MIDRECT,IDC_MIDRECT,IDC_MIDRECT,ES_HCENTER|ES_VCENTER)
  88. END_EASYSIZE_MAP
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CEasySizeDemoDlg message handlers
  91. BOOL CEasySizeDemoDlg::OnInitDialog()
  92. {
  93. CDialog::OnInitDialog();
  94. // Add "About..." menu item to system menu.
  95. // IDM_ABOUTBOX must be in the system command range.
  96. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  97. ASSERT(IDM_ABOUTBOX < 0xF000);
  98. CMenu* pSysMenu = GetSystemMenu(FALSE);
  99. if (pSysMenu != NULL)
  100. {
  101. CString strAboutMenu;
  102. strAboutMenu.LoadString(IDS_ABOUTBOX);
  103. if (!strAboutMenu.IsEmpty())
  104. {
  105. pSysMenu->AppendMenu(MF_SEPARATOR);
  106. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  107. }
  108. }
  109. // Set the icon for this dialog. The framework does this automatically
  110. // when the application's main window is not a dialog
  111. SetIcon(m_hIcon, TRUE); // Set big icon
  112. SetIcon(m_hIcon, FALSE); // Set small icon
  113. INIT_EASYSIZE;
  114. return TRUE; // return TRUE unless you set the focus to a control
  115. }
  116. void CEasySizeDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
  117. {
  118. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  119. {
  120. CAboutDlg dlgAbout;
  121. dlgAbout.DoModal();
  122. }
  123. else
  124. {
  125. CDialog::OnSysCommand(nID, lParam);
  126. }
  127. }
  128. // If you add a minimize button to your dialog, you will need the code below
  129. // to draw the icon. For MFC applications using the document/view model,
  130. // this is automatically done for you by the framework.
  131. void CEasySizeDemoDlg::OnPaint()
  132. {
  133. if (IsIconic())
  134. {
  135. CPaintDC dc(this); // device context for painting
  136. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  137. // Center icon in client rectangle
  138. int cxIcon = GetSystemMetrics(SM_CXICON);
  139. int cyIcon = GetSystemMetrics(SM_CYICON);
  140. CRect rect;
  141. GetClientRect(&rect);
  142. int x = (rect.Width() - cxIcon + 1) / 2;
  143. int y = (rect.Height() - cyIcon + 1) / 2;
  144. // Draw the icon
  145. dc.DrawIcon(x, y, m_hIcon);
  146. }
  147. else
  148. {
  149. CDialog::OnPaint();
  150. }
  151. }
  152. // The system calls this to obtain the cursor to display while the user drags
  153. // the minimized window.
  154. HCURSOR CEasySizeDemoDlg::OnQueryDragIcon()
  155. {
  156. return (HCURSOR) m_hIcon;
  157. }
  158. void CEasySizeDemoDlg::OnSize(UINT nType, int cx, int cy)
  159. {
  160. CDialog::OnSize(nType, cx, cy);
  161. UPDATE_EASYSIZE;
  162. }
  163. void CEasySizeDemoDlg::OnSizing(UINT fwSide, LPRECT pRect)
  164. {
  165. CDialog::OnSizing(fwSide, pRect);
  166. EASYSIZE_MINSIZE(280,250,fwSide,pRect);
  167. }