• 通过打开按钮打开文件和通过左键移动打开文件并计算crc


    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 += "
    ";
    17         //clear the Edit Dlg
    18         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+="
    ";
    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 += "
    ";
    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 += "
    ";
    22         //clear the Edit Dlg
    23         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+="
    ";
    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 += "
    ";
    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.

  • 相关阅读:
    .net core EF 入门笔记Code First
    Windows环境下安装MongodDB
    Ueditor1.4.3.3 富文本编辑器在图片不显示问题
    .net IIS网站部署Host文件简单应用
    .Net初学Less的安装与部署
    EF+MVC动态Lamda表达式拼接(学习笔记二)
    EF+MVC动态Lamda表达式拼接(学习笔记)
    区块链从入门到放弃
    Unity3D的update和FixedUpdate
    忽雷太极拳十三式
  • 原文地址:https://www.cnblogs.com/lumao1122-Milolu/p/7775051.html
Copyright © 2020-2023  润新知