標籤:false code none temp data control cat filter sage
We have learn open a file by using an open button, here is code below:
1 void CFileCrcDlg::OnOpen() 2 { 3 // TODO: Add your control notification handler code here 4 WORD n; 5 WORD i; 6 BYTE szchar[201]; 7 BYTE crc_hex[4],bt; 8 CString strtemp=""; 9 CFileDialog fileDlg(TRUE);10 fileDlg.m_ofn.lpstrFilter="All files (*.*)";11 if(fileDlg.DoModal()==IDOK)12 {13 CFile file(fileDlg.m_ofn.lpstrFile,CFile::modeRead);14 UpdateData(TRUE);15 m_path += file.GetFilePath();16 m_path += "\r\n";17 //clear the Edit Dlg18 i=0xffff;19 memset(szchar,0,201);20 while(file.Read(szchar,200))21 {22 n=0;23 while(szchar[n])24 {25 i=crc_16(i,szchar[n]);26 n++;27 }28 memset(szchar,0,201);29 }30 strtemp.Format("%d",i);31 m_crc_dec+=strtemp;32 m_crc_dec+="\r\n";33 34 swap_word_byte(i,crc_hex);35 for(i=0;i<4;i++)36 {37 bt =*(char*)(crc_hex+i);38 strtemp.Format("%c",bt);39 m_crc_hex+=strtemp;40 }41 m_crc_hex += "\r\n";42 file.Close();43 UpdateData(FALSE);44 }45 }
void CFileCrcDlg::OnOpen()
Now, we are going to using another way to open a file and get the crc check sum.
here is the code:
1 void CFileCrcDlg::OnDropFiles(HDROP hDropInfo) 2 { 3 // TODO: Add your message handler code here and/or call default 4 UINT j,iFileCount; 5 char file_name[MAX_PATH]; 6 //variable for crc 7 WORD n; 8 WORD i; 9 BYTE szchar[201];10 BYTE crc_hex[4],bt;11 CString strtemp="";12 13 iFileCount=::DragQueryFile(hDropInfo,0xffffffff,NULL,0);14 15 for(j=0;j<iFileCount;j++)16 {17 ::DragQueryFile(hDropInfo,j,file_name,MAX_PATH);18 CFile file(file_name,CFile::modeRead);19 UpdateData(TRUE);20 m_path += file.GetFilePath();21 m_path += "\r\n";22 //clear the Edit Dlg23 i=0xffff;24 memset(szchar,0,201);25 while(file.Read(szchar,200))26 {27 n=0;28 while(szchar[n])29 {30 i=crc_16(i,szchar[n]);31 n++;32 }33 memset(szchar,0,201);34 }35 strtemp.Format("%d",i);36 m_crc_dec+=strtemp;37 m_crc_dec+="\r\n";38 39 swap_word_byte(i,crc_hex);40 for(i=0;i<4;i++)41 {42 bt =*(char*)(crc_hex+i);43 strtemp.Format("%c",bt);44 m_crc_hex+=strtemp;45 }46 m_crc_hex += "\r\n";47 file.Close();48 UpdateData(FALSE);49 }50 ::DragFinish(hDropInfo);51 CDialog::OnDropFiles(hDropInfo);52 }
void CFileCrcDlg::OnDropFiles(HDROP hDropInfo)
OK, Enjoy. Thank you!
B.R.
通過開啟按鈕開啟檔案和通過左鍵移動開啟檔案並計算crc