这里列举对于函数的处理---读取文件个数,并逐个计算每个文件的crc值。
代码如下:
1 void CFile_DemoDlg::OnDropFiles(HDROP hDropInfo)
2 {
3 // TODO: 在此添加消息处理程序代码和/或调用默认值
4 UINT fileCount;
5 WORD crc,n;
6 BYTE szchar[201], crc_hex[4], bt;
7 CString strtmp;
8 TCHAR file_name[MAX_PATH] = { 0 };
9 //get number of drop files.
10 fileCount = DragQueryFile(hDropInfo,0xffffffff,NULL,0);
11 for (UINT i = 0; i < fileCount; i++)
12 {
13 DragQueryFile(hDropInfo,i,file_name,MAX_PATH-1);//get the file name of the i-th file
14 CFile file(file_name,CFile::modeRead);//open the file
15 UpdateData(true);
16 m_path += file.GetFilePath();
17 m_path += "\r\n";
18 crc = 0xffff;
19 memset(szchar, 0, 201);
20 while (file.Read(szchar, 200))
21 {
22 n = 0;
23 while (szchar[n])
24 {
25 crc = crc_16(crc, szchar[n]);
26 n++;
27 }
28 memset(szchar, 0, 201);
29 }
30 strtmp.Format(_T("%d"), crc);
31 m_dec += strtmp;
32 m_dec += "\r\n";
33 swap_word_byte(crc, crc_hex);
34 for (UINT i = 0; i < 4; i++)
35 {
36 bt = *(char*)(crc_hex + i);
37 strtmp.Format(_T("%c"), bt);
38 m_hex += strtmp;
39 }
40 m_hex += "\r\n";
41 UpdateData(false);
42 CEdit *pEdit = (CEdit*)this->GetDlgItem(IDC_EDIT1);
43 pEdit->LineScroll(pEdit->GetLineCount());
44 pEdit = (CEdit*)this->GetDlgItem(IDC_EDIT2);
45 pEdit->LineScroll(pEdit->GetLineCount());
46 pEdit = (CEdit*)this->GetDlgItem(IDC_EDIT3);
47 pEdit->LineScroll(pEdit->GetLineCount());
48 file.Close();
49 }
50 DragFinish(hDropInfo);
51
52
53 CDialogEx::OnDropFiles(hDropInfo);
54 }
注: fileCount = DragQueryFile(hDropInfo,0xffffffff,NULL,0); 返回拖拽文件个数。
谢谢.