xlRWDlg.cpp
上传用户:xaqykg
上传日期:2015-10-26
资源大小:25k
文件大小:7k
源码类别:

其他小程序

开发平台:

Visual C++

  1. // xlRWDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "xlRW.h"
  5. #include "xlRWDlg.h"
  6. #include "biff.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAboutDlg dialog used for App About
  14. class CAboutDlg : public CDialog
  15. {
  16. public:
  17. CAboutDlg();
  18. // Dialog Data
  19. //{{AFX_DATA(CAboutDlg)
  20. enum { IDD = IDD_ABOUTBOX };
  21. //}}AFX_DATA
  22. // ClassWizard generated virtual function overrides
  23. //{{AFX_VIRTUAL(CAboutDlg)
  24. protected:
  25. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  26. //}}AFX_VIRTUAL
  27. // Implementation
  28. protected:
  29. //{{AFX_MSG(CAboutDlg)
  30. //}}AFX_MSG
  31. DECLARE_MESSAGE_MAP()
  32. };
  33. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  34. {
  35. //{{AFX_DATA_INIT(CAboutDlg)
  36. //}}AFX_DATA_INIT
  37. }
  38. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CAboutDlg)
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  45. //{{AFX_MSG_MAP(CAboutDlg)
  46. // No message handlers
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CXlRWDlg dialog
  51. CXlRWDlg::CXlRWDlg(CWnd* pParent /*=NULL*/)
  52. : CDialog(CXlRWDlg::IDD, pParent)
  53. {
  54. //{{AFX_DATA_INIT(CXlRWDlg)
  55. // NOTE: the ClassWizard will add member initialization here
  56. //}}AFX_DATA_INIT
  57. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  58. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  59. }
  60. void CXlRWDlg::DoDataExchange(CDataExchange* pDX)
  61. {
  62. CDialog::DoDataExchange(pDX);
  63. //{{AFX_DATA_MAP(CXlRWDlg)
  64. // NOTE: the ClassWizard will add DDX and DDV calls here
  65. //}}AFX_DATA_MAP
  66. }
  67. BEGIN_MESSAGE_MAP(CXlRWDlg, CDialog)
  68. //{{AFX_MSG_MAP(CXlRWDlg)
  69. ON_WM_SYSCOMMAND()
  70. ON_WM_PAINT()
  71. ON_WM_QUERYDRAGICON()
  72. //}}AFX_MSG_MAP
  73. END_MESSAGE_MAP()
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CXlRWDlg message handlers
  76. BOOL CXlRWDlg::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. return TRUE;  // return TRUE  unless you set the focus to a control
  100. }
  101. void CXlRWDlg::OnSysCommand(UINT nID, LPARAM lParam)
  102. {
  103. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  104. {
  105. CAboutDlg dlgAbout;
  106. dlgAbout.DoModal();
  107. }
  108. else
  109. {
  110. CDialog::OnSysCommand(nID, lParam);
  111. }
  112. }
  113. // If you add a minimize button to your dialog, you will need the code below
  114. //  to draw the icon.  For MFC applications using the document/view model,
  115. //  this is automatically done for you by the framework.
  116. void CXlRWDlg::OnPaint() 
  117. {
  118. if (IsIconic())
  119. {
  120. CPaintDC dc(this); // device context for painting
  121. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  122. // Center icon in client rectangle
  123. int cxIcon = GetSystemMetrics(SM_CXICON);
  124. int cyIcon = GetSystemMetrics(SM_CYICON);
  125. CRect rect;
  126. GetClientRect(&rect);
  127. int x = (rect.Width() - cxIcon + 1) / 2;
  128. int y = (rect.Height() - cyIcon + 1) / 2;
  129. // Draw the icon
  130. dc.DrawIcon(x, y, m_hIcon);
  131. }
  132. else
  133. {
  134. CDialog::OnPaint();
  135. }
  136. }
  137. // The system calls this to obtain the cursor to display while the user drags
  138. //  the minimized window.
  139. HCURSOR CXlRWDlg::OnQueryDragIcon()
  140. {
  141. return (HCURSOR) m_hIcon;
  142. }
  143. void CXlRWDlg::OnOK() 
  144. {
  145. CFile f;
  146. CFileException e;
  147. // 打开文件
  148. if (!f.Open("D:\Book1.xls", CFile::modeRead, &e))
  149. {
  150. TCHAR szError[1024];
  151. e.GetErrorMessage(szError, 1024);
  152. AfxMessageBox(szError);
  153. return;
  154. }
  155. DWORD dwLen = f.GetLength();
  156. DWORD dwPos = f.GetPosition();
  157. WORD RecNo, RecLen, StrLen;
  158. UINT nRead;
  159. // 读取版本
  160. while (dwPos < dwLen)
  161. {
  162. nRead = f.Read((void*)&RecNo, 2);
  163. if (RecNo == XL_BOF)
  164. {
  165. WORD Ver, Type;
  166. f.Read((void*)&RecLen, 2);
  167. f.Read((void*)&Ver, 2);
  168. f.Read((void*)&Type, 2);
  169. f.Seek(RecLen, CFile::current);
  170. int ver = 0;
  171. switch (Ver)
  172. {
  173. case BIFF7:
  174. ver = 7;
  175. break;
  176. case BIFF8:
  177. ver = 8;
  178. AfxMessageBox("Biff8");
  179. break;
  180. }
  181. int type = 0;
  182. switch (Type)
  183. {
  184. case WORKBOOK:
  185. type = 5;
  186. AfxMessageBox("Workbook");
  187. break;
  188. case WORKSHEET:
  189. type = 16;
  190. AfxMessageBox("Worksheet");
  191. break;
  192. case CHART:
  193. type = 32;
  194. AfxMessageBox("Chart");
  195. break;
  196. }
  197. break;
  198. }
  199. dwPos = f.GetPosition();
  200. }
  201. f.SeekToBegin();
  202. dwPos = f.GetPosition();
  203. // 读表格数据
  204. while (dwPos < dwLen)
  205. {
  206. nRead = f.Read((void*)&RecNo, 2);
  207. switch (RecNo)
  208. {
  209. case XL_BOF:
  210. {
  211. f.Read((void*)&RecLen, 2);
  212. AfxMessageBox("Bof");
  213. }
  214. break;
  215. case XL_BOUNDSHEET:
  216. {
  217. DWORD temp;
  218. BYTE visi;
  219. BYTE type;
  220. TCHAR name;
  221. f.Read((void*)&RecLen, 2);
  222. f.Read((void*)&temp, 4);
  223. f.Read((void*)&visi, 1);
  224. f.Read((void*)&type, 1);
  225. f.Read((void*)&StrLen, 2);
  226. f.Read((void*)&name, StrLen);
  227. char buf[128];
  228. memset(buf, 0x0, 128);
  229. strncpy(buf, &name, StrLen);
  230. AfxMessageBox(buf);
  231. }
  232. break;
  233. case XL_DIMENSION:
  234. f.Read((void*)&RecLen, 2);
  235. f.Seek(RecLen, CFile::current);
  236. AfxMessageBox("Dimension");
  237. break;
  238. case 0xE2: // INTERFACED
  239. f.Read((void*)&RecLen, 2);
  240. AfxMessageBox("e2");
  241. break;
  242. case XL_SST:
  243. f.Read((void*)&RecLen, 2);
  244. f.Seek(RecLen, CFile::current);
  245. AfxMessageBox("SST");
  246. break;
  247. case XL_NUMBER:
  248. f.Read((void*)&RecLen, 2);
  249. AfxMessageBox("Number");
  250. break;
  251. case XL_STRING:
  252. f.Read((void*)&RecLen, 2);
  253. AfxMessageBox("String");
  254. break;
  255. case XL_RK:
  256. f.Read((void*)&RecLen, 2);
  257. AfxMessageBox("RK");
  258. break;
  259. case XL_LABEL:
  260. {
  261. f.Read((void*)&RecLen, 2);
  262. AfxMessageBox("Label");
  263. }
  264. break;
  265. case 0xD6:
  266. f.Read((void*)&RecLen, 2);
  267. AfxMessageBox("RString");
  268. break;
  269. case XL_EOF:
  270. dwPos = dwLen;
  271. AfxMessageBox("Eof");
  272. break;
  273. default:
  274. nRead = f.Read((void*)&RecLen, 2);
  275. if (nRead == 0)
  276. dwPos = dwLen;
  277. break;
  278. }
  279. }
  280. // 关闭文件
  281. f.Close();
  282. }