通過開啟按鈕開啟檔案和通過左鍵移動開啟檔案並計算crc

來源:互聯網
上載者:User

標籤: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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.