ReportDialogExDlg.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:6k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // ReportDialogExDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ReportDialogEx.h"
  5. #include "ReportDialogExDlg.h"
  6. #include "MessageRecord.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. UINT AFX_CDECL AddRecordsThreadFunc(LPVOID pvParms);
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CReportDialogExDlg dialog
  15. CReportDialogExDlg::CReportDialogExDlg(CWnd* pParent /*=NULL*/)
  16. : CXTResizeDialog(CReportDialogExDlg::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CReportDialogExDlg)
  19. // NOTE: the ClassWizard will add member initialization here
  20. //}}AFX_DATA_INIT
  21. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  22. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  23. }
  24. void CReportDialogExDlg::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CXTResizeDialog::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(CReportDialogExDlg)
  28. //}}AFX_DATA_MAP
  29. }
  30. BEGIN_MESSAGE_MAP(CReportDialogExDlg, CXTResizeDialog)
  31. //{{AFX_MSG_MAP(CReportDialogExDlg)
  32. ON_WM_SYSCOMMAND()
  33. ON_WM_PAINT()
  34. ON_WM_QUERYDRAGICON()
  35. ON_WM_DESTROY()
  36. ON_BN_CLICKED(IDC_ADD_RECORDS_BUTTON, OnAddRecordsButton)
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CReportDialogExDlg message handlers
  41. BOOL CReportDialogExDlg::OnInitDialog()
  42. {
  43. CXTResizeDialog::OnInitDialog();
  44. // Add "About..." menu item to system menu.
  45. // IDM_ABOUTBOX must be in the system command range.
  46. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  47. ASSERT(IDM_ABOUTBOX < 0xF000);
  48. CMenu* pSysMenu = GetSystemMenu(FALSE);
  49. if (pSysMenu != NULL)
  50. {
  51. CString strAboutMenu;
  52. strAboutMenu.LoadString(IDS_ABOUTBOX);
  53. if (!strAboutMenu.IsEmpty())
  54. {
  55. pSysMenu->AppendMenu(MF_SEPARATOR);
  56. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  57. }
  58. }
  59. // Set the icon for this dialog.  The framework does this automatically
  60. //  when the application's main window is not a dialog
  61. SetIcon(m_hIcon, TRUE); // Set big icon
  62. SetIcon(m_hIcon, FALSE); // Set small icon
  63. // subclass the report control
  64. m_wndReportCtrl.SubclassDlgItem(IDC_REPORTCTRL, this);
  65. //  add sample columns
  66. for(int i = 0; i < 4; i++)
  67. {
  68. CString strName;
  69. strName.Format(_T("Column %d"), i + 1);
  70. m_wndReportCtrl.AddColumn(new CXTPReportColumn(i, strName, 280));
  71. }
  72. // set the first column as a group column
  73. m_wndReportCtrl.ShowGroupBy();
  74. m_wndReportCtrl.GetColumns()->GetGroupsOrder()->Add(m_wndReportCtrl.GetColumns()->GetAt(0));
  75. // add empty header row
  76. m_wndReportCtrl.GetHeaderRecords()->Add(new CMessageRecord());
  77. m_wndReportCtrl.ShowHeaderRows();
  78. m_wndReportCtrl.HeaderRowsAllowEdit(TRUE);
  79. m_wndReportCtrl.PopulateHeaderRows();
  80. m_wndReportCtrl.GetPaintManager()->SetHeaderRowsDividerStyle(xtpReportFixedRowsDividerOutlook);
  81. // define style attributes for the report control
  82. m_wndReportCtrl.FocusSubItems(TRUE);
  83. m_wndReportCtrl.AllowEdit(TRUE);
  84. // Set control resizing.
  85. SetResize(IDC_REPORTCTRL, SZ_TOP_LEFT, SZ_BOTTOM_RIGHT);
  86. SetResize(IDOK, SZ_BOTTOM_RIGHT, SZ_BOTTOM_RIGHT);
  87. SetResize(IDC_ADD_RECORDS_BUTTON, SZ_BOTTOM_RIGHT, SZ_BOTTOM_RIGHT);
  88. // Load window placement
  89. LoadPlacement(_T("CReportDialogExDlg"));
  90. return TRUE;  // return TRUE  unless you set the focus to a control
  91. }
  92. void CReportDialogExDlg::OnSysCommand(UINT nID, LPARAM lParam)
  93. {
  94. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  95. {
  96. CAboutDlg dlgAbout;
  97. dlgAbout.DoModal();
  98. }
  99. else
  100. {
  101. CXTResizeDialog::OnSysCommand(nID, lParam);
  102. }
  103. }
  104. // If you add a minimize button to your dialog, you will need the code below
  105. //  to draw the icon.  For MFC applications using the document/view model,
  106. //  this is automatically done for you by the framework.
  107. void CReportDialogExDlg::OnPaint() 
  108. {
  109. if (IsIconic())
  110. {
  111. CPaintDC dc(this); // device context for painting
  112. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  113. // Center icon in client rectangle
  114. int cxIcon = GetSystemMetrics(SM_CXICON);
  115. int cyIcon = GetSystemMetrics(SM_CYICON);
  116. CRect rect;
  117. GetClientRect(&rect);
  118. int x = (rect.Width() - cxIcon + 1) / 2;
  119. int y = (rect.Height() - cyIcon + 1) / 2;
  120. // Draw the icon
  121. dc.DrawIcon(x, y, m_hIcon);
  122. }
  123. else
  124. {
  125. CXTResizeDialog::OnPaint();
  126. }
  127. }
  128. // The system calls this to obtain the cursor to display while the user drags
  129. //  the minimized window.
  130. HCURSOR CReportDialogExDlg::OnQueryDragIcon()
  131. {
  132. return (HCURSOR) m_hIcon;
  133. }
  134. void CReportDialogExDlg::OnDestroy() 
  135. {
  136. CXTResizeDialog::OnDestroy();
  137. // Save window placement
  138. SavePlacement(_T("CReportDialogExDlg"));
  139. }
  140. void CReportDialogExDlg::OnAddRecordsButton() 
  141. {
  142. GetDlgItem(IDC_ADD_RECORDS_BUTTON)->EnableWindow(FALSE);
  143. AfxBeginThread(AddRecordsThreadFunc, (LPVOID)&m_wndReportCtrl, THREAD_PRIORITY_IDLE);
  144. //GetDlgItem(IDC_ADD_RECORDS_BUTTON)->EnableWindow();
  145. }
  146. BOOL CReportDialogExDlg::PreTranslateMessage(MSG* pMsg) 
  147. {
  148. if(pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN || pMsg->wParam == VK_TAB))
  149. return FALSE;
  150. return CXTResizeDialog::PreTranslateMessage(pMsg);
  151. }
  152. UINT AFX_CDECL AddRecordsThreadFunc(LPVOID pvParms)
  153. {
  154. CReportControl* pReportCtrl = (CReportControl*)pvParms;
  155. if(!pReportCtrl)
  156. return 0;
  157. int nAddCount = 100;
  158. for(int i = 0; i < nAddCount; i++)
  159. {
  160. CString strItem[4];
  161. for(int j = 0; j < 4; j++)
  162. {
  163. strItem[j].Format(_T("Row - %d, Col - %d"), i + 1, j + 1);
  164. }
  165. CMessageRecord* pMsg = new CMessageRecord(strItem[0], strItem[1], strItem[2], strItem[3]);
  166. // WPARAM = pointer to a report record
  167. // LPARAM:
  168. //    LOWORD = record number
  169. //    HIWORD = records count to add
  170. if(pMsg)
  171. pReportCtrl->SendMessage(WM_ADD_RECORD_EX, (WPARAM)pMsg, MAKELPARAM(i, nAddCount));
  172. if (pReportCtrl->GetParent())
  173. {
  174. CString strCaption(_T("Report Sample for AddRecordEx"));
  175. if (i + 1 < nAddCount)
  176. strCaption.Format(_T("Report Sample for AddRecordEx [%d of %d]"), i+1, nAddCount);
  177. pReportCtrl->GetParent()->SetWindowText(strCaption);
  178. }
  179. Sleep(50);
  180. }
  181. pReportCtrl->GetParent()->GetDlgItem(IDC_ADD_RECORDS_BUTTON)->EnableWindow();
  182. return 0;
  183. }