ConfigDlg.cpp
上传用户:kelijie
上传日期:2007-01-01
资源大小:123k
文件大小:6k
源码类别:

图形图象

开发平台:

Visual C++

  1. // ConfigDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include <stdio.h>
  5. #include <io.h>
  6. #include <time.h>
  7. #include "Config.h"
  8. #include "ConfigDlg.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAboutDlg dialog used for App About
  16. class CAboutDlg : public CDialog
  17. {
  18. public:
  19. CAboutDlg();
  20. // Dialog Data
  21. //{{AFX_DATA(CAboutDlg)
  22. enum { IDD = IDD_ABOUTBOX };
  23. //}}AFX_DATA
  24. // ClassWizard generated virtual function overrides
  25. //{{AFX_VIRTUAL(CAboutDlg)
  26. protected:
  27. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  28. //}}AFX_VIRTUAL
  29. // Implementation
  30. protected:
  31. //{{AFX_MSG(CAboutDlg)
  32. //}}AFX_MSG
  33. DECLARE_MESSAGE_MAP()
  34. };
  35. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  36. {
  37. //{{AFX_DATA_INIT(CAboutDlg)
  38. //}}AFX_DATA_INIT
  39. }
  40. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CDialog::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(CAboutDlg)
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  47. //{{AFX_MSG_MAP(CAboutDlg)
  48. // No message handlers
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CConfigDlg dialog
  53. CConfigDlg::CConfigDlg(CWnd* pParent /*=NULL*/)
  54. : CDialog(CConfigDlg::IDD, pParent)
  55. {
  56. //{{AFX_DATA_INIT(CConfigDlg)
  57. // NOTE: the ClassWizard will add member initialization here
  58. //}}AFX_DATA_INIT
  59. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  60. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  61. }
  62. void CConfigDlg::DoDataExchange(CDataExchange* pDX)
  63. {
  64. CDialog::DoDataExchange(pDX);
  65. //{{AFX_DATA_MAP(CConfigDlg)
  66. DDX_Control(pDX, IDC_PLUGINLIST, m_PluginList);
  67. DDX_Control(pDX, IDC_EXISTLIST, m_ExistList);
  68. //}}AFX_DATA_MAP
  69. }
  70. BEGIN_MESSAGE_MAP(CConfigDlg, CDialog)
  71. //{{AFX_MSG_MAP(CConfigDlg)
  72. ON_WM_SYSCOMMAND()
  73. ON_WM_PAINT()
  74. ON_WM_QUERYDRAGICON()
  75. ON_BN_CLICKED(IDC_ADD, OnAdd)
  76. ON_BN_CLICKED(IDC_ROMOVE, OnRomove)
  77. ON_LBN_DBLCLK(IDC_EXISTLIST, OnDblclkExistlist)
  78. ON_LBN_DBLCLK(IDC_PLUGINLIST, OnDblclkPluginlist)
  79. //}}AFX_MSG_MAP
  80. END_MESSAGE_MAP()
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CConfigDlg message handlers
  83. BOOL CConfigDlg::OnInitDialog()
  84. {
  85. CDialog::OnInitDialog();
  86. // Add "About..." menu item to system menu.
  87. // IDM_ABOUTBOX must be in the system command range.
  88. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  89. ASSERT(IDM_ABOUTBOX < 0xF000);
  90. CMenu* pSysMenu = GetSystemMenu(FALSE);
  91. if (pSysMenu != NULL)
  92. {
  93. CString strAboutMenu;
  94. strAboutMenu.LoadString(IDS_ABOUTBOX);
  95. if (!strAboutMenu.IsEmpty())
  96. {
  97. pSysMenu->AppendMenu(MF_SEPARATOR);
  98. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  99. }
  100. }
  101. // Set the icon for this dialog.  The framework does this automatically
  102. //  when the application's main window is not a dialog
  103. SetIcon(m_hIcon, TRUE); // Set big icon
  104. SetIcon(m_hIcon, FALSE); // Set small icon
  105. // TODO: Add extra initialization here
  106. //Add existing module to list view
  107.     struct _finddata_t dll_file;    
  108. long hFile;
  109.     if((hFile = _findfirst( "e*.dll", &dll_file )) != -1L)
  110.     {
  111.         if(m_ExistList.AddString(dll_file.name) != LB_ERRSPACE)
  112. {
  113.             while( _findnext( hFile, &dll_file ) == 0 )            
  114. {
  115. m_ExistList.AddString(dll_file.name);
  116. }       
  117.         _findclose( hFile );   
  118. }
  119. }
  120. //Add plug-in module to list view
  121.     CFile  file;
  122. char   f_name[20];
  123.     int    inum;
  124.     if(file.Open("plugin.sys", CFile::modeRead))
  125.     {
  126.         file.Read(&inum, sizeof(int));
  127. for(int i = 0; i < inum; i++)
  128. {
  129. file.Read(&f_name, 20*sizeof(char));
  130. m_PluginList.AddString(f_name);
  131. }
  132.     file.Close();
  133. }
  134. return TRUE;  // return TRUE  unless you set the focus to a control
  135. }
  136. void CConfigDlg::OnSysCommand(UINT nID, LPARAM lParam)
  137. {
  138. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  139. {
  140. CAboutDlg dlgAbout;
  141. dlgAbout.DoModal();
  142. }
  143. else
  144. {
  145. CDialog::OnSysCommand(nID, lParam);
  146. }
  147. }
  148. // If you add a minimize button to your dialog, you will need the code below
  149. //  to draw the icon.  For MFC applications using the document/view model,
  150. //  this is automatically done for you by the framework.
  151. void CConfigDlg::OnPaint() 
  152. {
  153. if (IsIconic())
  154. {
  155. CPaintDC dc(this); // device context for painting
  156. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  157. // Center icon in client rectangle
  158. int cxIcon = GetSystemMetrics(SM_CXICON);
  159. int cyIcon = GetSystemMetrics(SM_CYICON);
  160. CRect rect;
  161. GetClientRect(&rect);
  162. int x = (rect.Width() - cxIcon + 1) / 2;
  163. int y = (rect.Height() - cyIcon + 1) / 2;
  164. // Draw the icon
  165. dc.DrawIcon(x, y, m_hIcon);
  166. }
  167. else
  168. {
  169. CDialog::OnPaint();
  170. }
  171. }
  172. // The system calls this to obtain the cursor to display while the user drags
  173. //  the minimized window.
  174. HCURSOR CConfigDlg::OnQueryDragIcon()
  175. {
  176. return (HCURSOR) m_hIcon;
  177. }
  178. void CConfigDlg::OnAdd() 
  179. {
  180. // TODO: Add your control notification handler code here
  181.     int lsel = m_ExistList.GetCurSel( ); 
  182.     if(lsel != LB_ERR)
  183. {
  184.     char f_name[20];
  185.         m_ExistList.GetText(lsel, f_name);
  186. if(m_PluginList.FindString(0, f_name) == LB_ERR)
  187. {
  188. m_PluginList.AddString(f_name);
  189. }
  190. }
  191. }
  192. void CConfigDlg::OnRomove() 
  193. {
  194. // TODO: Add your control notification handler code here
  195.     int lsel = m_PluginList.GetCurSel(); 
  196.     if(lsel != LB_ERR)
  197. {
  198.     m_PluginList.DeleteString(lsel);
  199. }
  200. }
  201. void CConfigDlg::OnOK() 
  202. {
  203. // TODO: Add extra validation here
  204. int count = m_PluginList.GetCount(); 
  205. if(count != LB_ERR)
  206. {
  207.         CFile  file;
  208.     char   f_name[20];
  209.         if(file.Open("plugin.sys", CFile::modeCreate|CFile::modeWrite))
  210. {
  211.             file.Write(&count, sizeof(int));
  212.     for(int i = 0; i < count; i++)
  213. {
  214.                m_PluginList.GetText(i, f_name);
  215.    file.Write(&f_name, 20*sizeof(char));
  216. }
  217.         file.Close();
  218. }
  219. }
  220. CDialog::OnOK();
  221. }
  222. void CConfigDlg::OnDblclkExistlist() 
  223. {
  224. // TODO: Add your control notification handler code here
  225.     OnAdd();
  226. }
  227. void CConfigDlg::OnDblclkPluginlist() 
  228. {
  229. // TODO: Add your control notification handler code here
  230.     OnRomove();
  231. }