ActiveXDlg.cpp
上传用户:z_mail1980
上传日期:2007-06-01
资源大小:647k
文件大小:7k
源码类别:

SNMP编程

开发平台:

Visual C++

  1. // ActiveXDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ActiveX.h"
  5. #include "ActiveXDlg.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. // CActiveXDlg dialog
  50. CActiveXDlg::CActiveXDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CActiveXDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CActiveXDlg)
  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 CActiveXDlg::DoDataExchange(CDataExchange* pDX)
  60. {
  61. CDialog::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CActiveXDlg)
  63. DDX_Control(pDX, IDC_MSFGRID, m_ctlFGrid);
  64. //}}AFX_DATA_MAP
  65. }
  66. BEGIN_MESSAGE_MAP(CActiveXDlg, CDialog)
  67. //{{AFX_MSG_MAP(CActiveXDlg)
  68. ON_WM_SYSCOMMAND()
  69. ON_WM_PAINT()
  70. ON_WM_QUERYDRAGICON()
  71. ON_BN_CLICKED(IDC_EXIT, OnExit)
  72. //}}AFX_MSG_MAP
  73. END_MESSAGE_MAP()
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CActiveXDlg message handlers
  76. BOOL CActiveXDlg::OnInitDialog()
  77. {
  78. CDialog::OnInitDialog();
  79. // Add "About..." menu item to system menu.
  80. // IDM_ABOUTBOX must be in the system command range.
  81. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  82. ASSERT(IDM_ABOUTBOX < 0xF000);
  83. CMenu* pSysMenu = GetSystemMenu(FALSE);
  84. if (pSysMenu != NULL)
  85. {
  86. CString strAboutMenu;
  87. strAboutMenu.LoadString(IDS_ABOUTBOX);
  88. if (!strAboutMenu.IsEmpty())
  89. {
  90. pSysMenu->AppendMenu(MF_SEPARATOR);
  91. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  92. }
  93. }
  94. // Set the icon for this dialog.  The framework does this automatically
  95. //  when the application's main window is not a dialog
  96. SetIcon(m_hIcon, TRUE); // Set big icon
  97. SetIcon(m_hIcon, FALSE); // Set small icon
  98. // TODO: Add extra initialization here
  99. LoadData();
  100. return TRUE;  // return TRUE  unless you set the focus to a control
  101. }
  102. void CActiveXDlg::OnSysCommand(UINT nID, LPARAM lParam)
  103. {
  104. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  105. {
  106. CAboutDlg dlgAbout;
  107. dlgAbout.DoModal();
  108. }
  109. else
  110. {
  111. CDialog::OnSysCommand(nID, lParam);
  112. }
  113. }
  114. // If you add a minimize button to your dialog, you will need the code below
  115. //  to draw the icon.  For MFC applications using the document/view model,
  116. //  this is automatically done for you by the framework.
  117. void CActiveXDlg::OnPaint() 
  118. {
  119. if (IsIconic())
  120. {
  121. CPaintDC dc(this); // device context for painting
  122. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  123. // Center icon in client rectangle
  124. int cxIcon = GetSystemMetrics(SM_CXICON);
  125. int cyIcon = GetSystemMetrics(SM_CYICON);
  126. CRect rect;
  127. GetClientRect(&rect);
  128. int x = (rect.Width() - cxIcon + 1) / 2;
  129. int y = (rect.Height() - cyIcon + 1) / 2;
  130. // Draw the icon
  131. dc.DrawIcon(x, y, m_hIcon);
  132. }
  133. else
  134. {
  135. CDialog::OnPaint();
  136. }
  137. }
  138. // The system calls this to obtain the cursor to display while the user drags
  139. //  the minimized window.
  140. HCURSOR CActiveXDlg::OnQueryDragIcon()
  141. {
  142. return (HCURSOR) m_hIcon;
  143. }
  144. void CActiveXDlg::OnExit() 
  145. {
  146. // TODO: Add your control notification handler code here
  147. OnOK();
  148. }
  149. void CActiveXDlg::LoadData()
  150. {
  151.    int liCount;
  152.    CString lsAmount;
  153.    srand((unsigned)time(NULL));
  154.    for(liCount=m_ctlFGrid.GetFixedRows();liCount<m_ctlFGrid.GetRows();liCount++)
  155.    {
  156.    m_ctlFGrid.SetTextArray(GenID(liCount,0),RandomStringValue(0));
  157.    m_ctlFGrid.SetTextArray(GenID(liCount,1),RandomStringValue(1));
  158.    m_ctlFGrid.SetTextArray(GenID(liCount,2),RandomStringValue(2));
  159.    lsAmount.Format("%5d.00",rand());
  160.    m_ctlFGrid.SetTextArray(GenID(liCount,3),lsAmount);
  161.    }
  162.    m_ctlFGrid.SetMergeCol(0,TRUE);
  163.    m_ctlFGrid.SetMergeCol(1,TRUE);
  164.    m_ctlFGrid.SetMergeCol(2,TRUE);
  165.    DoSort();
  166. }
  167. int CActiveXDlg::GenID(int m_iRow, int m_iCol)
  168. {
  169. int liCols=m_ctlFGrid.GetCols();
  170. return(m_iRow*liCols+m_iCol);
  171. }
  172. CString CActiveXDlg::RandomStringValue(int m_iColumn)
  173. {
  174. CString lsStr;
  175. int liCase;
  176. switch(m_iColumn)
  177. {
  178. case 0:
  179. liCase=(rand()%5);
  180. switch(liCase)
  181. {
  182. case 0:
  183. lsStr="Northwest";
  184. break;
  185. case 1:
  186. lsStr="Southwest";
  187. break;
  188. case 2:
  189. lsStr="Midwest";
  190. break;
  191. case 3:
  192. lsStr="Northeast";
  193. break;
  194. default:
  195. lsStr="Southeast";
  196. break;
  197. }
  198. break;
  199. case 1:
  200. liCase=(rand()%5);
  201. switch(liCase)
  202. {
  203. case 0:
  204. lsStr="Apple";
  205. break;
  206. case 1:
  207. lsStr="Orange";
  208. break;
  209. case 2:
  210. lsStr="Peach";
  211. break;
  212. case 3:
  213. lsStr="Branana";
  214. break;
  215. default:
  216. lsStr="Fruit";
  217. break;
  218. }
  219. break;
  220. case 2:
  221. liCase=(rand()%4);
  222. switch(liCase)
  223. {
  224. case 0:
  225. lsStr="Kongqingfeng";
  226. break;
  227. case 1:
  228. lsStr="Liuyikang";
  229. break;
  230. case 2:
  231. lsStr="Yumenglei";
  232. break;
  233. default:
  234. lsStr="Wangyiming";
  235. break;
  236. }
  237. break;
  238. }
  239. return lsStr;
  240. }
  241. void CActiveXDlg::DoSort()
  242. {
  243. m_ctlFGrid.SetCol(0);
  244. m_ctlFGrid.SetColSel(m_ctlFGrid.GetCols()-1);
  245. m_ctlFGrid.SetSort(1);
  246. }
  247. BEGIN_EVENTSINK_MAP(CActiveXDlg, CDialog)
  248.     //{{AFX_EVENTSINK_MAP(CActiveXDlg)
  249. ON_EVENT(CActiveXDlg, IDC_MSFGRID, -605 /* MouseDown */, OnMouseDownMsfgrid, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
  250. ON_EVENT(CActiveXDlg, IDC_MSFGRID, -607 /* MouseUp */, OnMouseUpMsfgrid, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
  251. //}}AFX_EVENTSINK_MAP
  252. END_EVENTSINK_MAP()
  253. void CActiveXDlg::OnMouseDownMsfgrid(short Button, short Shift, long x, long y) 
  254. {
  255. // TODO: Add your control notification handler code here
  256. if(m_ctlFGrid.GetMouseRow()!=0)
  257. {
  258. m_iMouseCol=0;
  259. return;
  260. }
  261. m_iMouseCol=m_ctlFGrid.GetMouseCol();
  262. }
  263. void CActiveXDlg::OnMouseUpMsfgrid(short Button, short Shift, long x, long y) 
  264. {
  265. // TODO: Add your control notification handler code here
  266. if(m_iMouseCol==0)
  267. return;
  268. m_ctlFGrid.SetRedraw(FALSE);
  269. m_ctlFGrid.SetColPosition(m_iMouseCol,m_ctlFGrid.GetMouseCol());
  270. DoSort();
  271. m_ctlFGrid.SetRedraw(TRUE);
  272. }