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

SNMP编程

开发平台:

Visual C++

  1. // LISTCONTROLDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "LISTCONTROL.h"
  5. #include "LISTCONTROLDlg.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. SPS Sps[]={
  14. {"红梅",0,"1000","30","30000"},
  15. {"黄梅",0,"1000","29","29000"},
  16. {"绿梅",0,"1000","28","28000"},
  17. {"青梅",0,"1000","27","27000"},
  18. {"白梅",0,"1000","31","31000"},
  19. {"红梅",1,"1000","30","30000"},
  20. {"黄梅",1,"1000","29","29000"},
  21. {"绿梅",1,"1000","28","28000"},
  22. {"青梅",1,"1000","27","27000"},
  23. {"白梅",1,"1000","31","31000"}
  24. };
  25. CImageList Cil1,Cil2;
  26. class CAboutDlg : public CDialog
  27. {
  28. public:
  29. CAboutDlg();
  30. // Dialog Data
  31. //{{AFX_DATA(CAboutDlg)
  32. enum { IDD = IDD_ABOUTBOX };
  33. //}}AFX_DATA
  34. // ClassWizard generated virtual function overrides
  35. //{{AFX_VIRTUAL(CAboutDlg)
  36. protected:
  37. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  38. //}}AFX_VIRTUAL
  39. // Implementation
  40. protected:
  41. //{{AFX_MSG(CAboutDlg)
  42. //}}AFX_MSG
  43. DECLARE_MESSAGE_MAP()
  44. };
  45. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  46. {
  47. //{{AFX_DATA_INIT(CAboutDlg)
  48. //}}AFX_DATA_INIT
  49. }
  50. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  51. {
  52. CDialog::DoDataExchange(pDX);
  53. //{{AFX_DATA_MAP(CAboutDlg)
  54. //}}AFX_DATA_MAP
  55. }
  56. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  57. //{{AFX_MSG_MAP(CAboutDlg)
  58. // No message handlers
  59. //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CLISTCONTROLDlg dialog
  63. CLISTCONTROLDlg::CLISTCONTROLDlg(CWnd* pParent /*=NULL*/)
  64. : CDialog(CLISTCONTROLDlg::IDD, pParent)
  65. {
  66. //{{AFX_DATA_INIT(CLISTCONTROLDlg)
  67. // NOTE: the ClassWizard will add member initialization here
  68. //}}AFX_DATA_INIT
  69. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  70. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  71. }
  72. void CLISTCONTROLDlg::DoDataExchange(CDataExchange* pDX)
  73. {
  74. CDialog::DoDataExchange(pDX);
  75. //{{AFX_DATA_MAP(CLISTCONTROLDlg)
  76. DDX_Control(pDX, IDC_LISTCTRL, m_ListCtrl);
  77. //}}AFX_DATA_MAP
  78. }
  79. BEGIN_MESSAGE_MAP(CLISTCONTROLDlg, CDialog)
  80. //{{AFX_MSG_MAP(CLISTCONTROLDlg)
  81. ON_WM_SYSCOMMAND()
  82. ON_WM_PAINT()
  83. ON_WM_QUERYDRAGICON()
  84. ON_BN_CLICKED(IDC_STDICON, OnStdicon)
  85. ON_BN_CLICKED(IDC_SMLICON, OnSmlicon)
  86. ON_BN_CLICKED(IDC_LIST, OnList)
  87. ON_BN_CLICKED(IDC_REPORT, OnReport)
  88. //}}AFX_MSG_MAP
  89. END_MESSAGE_MAP()
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CLISTCONTROLDlg message handlers
  92. BOOL CLISTCONTROLDlg::OnInitDialog()
  93. {
  94. CDialog::OnInitDialog();
  95. // Add "About..." menu item to system menu.
  96. // IDM_ABOUTBOX must be in the system command range.
  97. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  98. ASSERT(IDM_ABOUTBOX < 0xF000);
  99. CMenu* pSysMenu = GetSystemMenu(FALSE);
  100. if (pSysMenu != NULL)
  101. {
  102. CString strAboutMenu;
  103. strAboutMenu.LoadString(IDS_ABOUTBOX);
  104. if (!strAboutMenu.IsEmpty())
  105. {
  106. pSysMenu->AppendMenu(MF_SEPARATOR);
  107. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  108. }
  109. }
  110. // Set the icon for this dialog.  The framework does this automatically
  111. //  when the application's main window is not a dialog
  112. SetIcon(m_hIcon, TRUE); // Set big icon
  113. SetIcon(m_hIcon, FALSE); // Set small icon
  114. // TODO: Add extra initialization here
  115. LV_ITEM  lvitem;
  116. LV_COLUMN lvcol;
  117. int i,iPos,iItemNum;
  118. CLISTCONTROLApp *pApp=(CLISTCONTROLApp *)AfxGetApp();
  119. Cil1.Create(32,32,TRUE,2,2);
  120. Cil1.Add(pApp->LoadIcon(IDI_GJ));
  121. Cil1.Add(pApp->LoadIcon(IDI_XS));
  122. Cil2.Create(16,16,TRUE,2,2);
  123. Cil2.Add(pApp->LoadIcon(IDI_GJ));
  124. Cil2.Add(pApp->LoadIcon(IDI_XS));
  125. m_ListCtrl.SetImageList(&Cil1,LVSIL_NORMAL);
  126. m_ListCtrl.SetImageList(&Cil2,LVSIL_SMALL);
  127. lvcol.mask=LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
  128. lvcol.fmt=LVCFMT_CENTER;
  129. i=0;
  130. lvcol.pszText="品名";
  131. lvcol.iSubItem=i;
  132. lvcol.cx=70;
  133. m_ListCtrl.InsertColumn(i++,&lvcol);
  134. lvcol.pszText="数量";
  135. lvcol.iSubItem=i;
  136. lvcol.cx=70;
  137. m_ListCtrl.InsertColumn(i++,&lvcol);
  138. lvcol.pszText="单价";
  139. lvcol.iSubItem=i;
  140. lvcol.cx=70;
  141. m_ListCtrl.InsertColumn(i++,&lvcol);
  142. lvcol.pszText="金额";
  143. lvcol.iSubItem=i;
  144. lvcol.cx=70;
  145. m_ListCtrl.InsertColumn(i++,&lvcol);
  146. iItemNum=sizeof(Sps)/sizeof(SPS);
  147. for(i=0;i<iItemNum;i++)
  148. {
  149. lvitem.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
  150. lvitem.iItem=i;
  151. lvitem.iSubItem=0;
  152. lvitem.pszText=Sps[i].szPm;
  153. lvitem.iImage=Sps[i].Lx;
  154. iPos=m_ListCtrl.InsertItem(&lvitem);
  155. lvitem.mask=LVIF_TEXT;
  156. lvitem.iItem=iPos;
  157. lvitem.iSubItem=1;
  158. lvitem.pszText=Sps[i].szSl;
  159. m_ListCtrl.SetItem(&lvitem);
  160. lvitem.iSubItem=2;
  161. lvitem.pszText=Sps[i].szDj;
  162. m_ListCtrl.SetItem(&lvitem);
  163. lvitem.iSubItem=3;
  164. lvitem.pszText=Sps[i].szJe;
  165. m_ListCtrl.SetItem(&lvitem);
  166. }
  167. CheckRadioButton(IDC_STDICON,IDC_REPORT,IDC_STDICON);
  168. return TRUE;  // return TRUE  unless you set the focus to a control
  169. }
  170. void CLISTCONTROLDlg::OnSysCommand(UINT nID, LPARAM lParam)
  171. {
  172. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  173. {
  174. CAboutDlg dlgAbout;
  175. dlgAbout.DoModal();
  176. }
  177. else
  178. {
  179. CDialog::OnSysCommand(nID, lParam);
  180. }
  181. }
  182. // If you add a minimize button to your dialog, you will need the code below
  183. //  to draw the icon.  For MFC applications using the document/view model,
  184. //  this is automatically done for you by the framework.
  185. void CLISTCONTROLDlg::OnPaint() 
  186. {
  187. if (IsIconic())
  188. {
  189. CPaintDC dc(this); // device context for painting
  190. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  191. // Center icon in client rectangle
  192. int cxIcon = GetSystemMetrics(SM_CXICON);
  193. int cyIcon = GetSystemMetrics(SM_CYICON);
  194. CRect rect;
  195. GetClientRect(&rect);
  196. int x = (rect.Width() - cxIcon + 1) / 2;
  197. int y = (rect.Height() - cyIcon + 1) / 2;
  198. // Draw the icon
  199. dc.DrawIcon(x, y, m_hIcon);
  200. }
  201. else
  202. {
  203. CDialog::OnPaint();
  204. }
  205. }
  206. // The system calls this to obtain the cursor to display while the user drags
  207. //  the minimized window.
  208. HCURSOR CLISTCONTROLDlg::OnQueryDragIcon()
  209. {
  210. return (HCURSOR) m_hIcon;
  211. }
  212. void CLISTCONTROLDlg::OnStdicon() 
  213. {
  214. // TODO: Add your control notification handler code here
  215. LONG lStyle;
  216. lStyle=GetWindowLong(m_ListCtrl.m_hWnd,GWL_STYLE);
  217. lStyle &=~LVS_TYPEMASK;
  218. lStyle |=LVS_ICON;
  219. SetWindowLong(m_ListCtrl.m_hWnd,GWL_STYLE,lStyle);
  220. }
  221. void CLISTCONTROLDlg::OnSmlicon() 
  222. {
  223. // TODO: Add your control notification handler code here
  224. LONG lStyle;
  225. lStyle=GetWindowLong(m_ListCtrl.m_hWnd,GWL_STYLE);
  226. lStyle &=~LVS_TYPEMASK;
  227. lStyle |=LVS_SMALLICON;
  228. SetWindowLong(m_ListCtrl.m_hWnd,GWL_STYLE,lStyle);
  229. }
  230. void CLISTCONTROLDlg::OnList() 
  231. {
  232. // TODO: Add your control notification handler code here
  233. LONG lStyle;
  234. lStyle=GetWindowLong(m_ListCtrl.m_hWnd,GWL_STYLE);
  235. lStyle &=~LVS_TYPEMASK;
  236. lStyle |=LVS_LIST;
  237. SetWindowLong(m_ListCtrl.m_hWnd,GWL_STYLE,lStyle);
  238. }
  239. void CLISTCONTROLDlg::OnReport() 
  240. {
  241. // TODO: Add your control notification handler code here
  242. LONG lStyle;
  243. lStyle=GetWindowLong(m_ListCtrl.m_hWnd,GWL_STYLE);
  244. lStyle &=~LVS_TYPEMASK;
  245. lStyle |=LVS_REPORT;
  246. SetWindowLong(m_ListCtrl.m_hWnd,GWL_STYLE,lStyle);
  247. }