⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vc常用源码.htm

📁 Hex转换成CString
💻 HTM
📖 第 1 页 / 共 5 页
字号:
      * psl ;<BR>IPersistFile* ppf ;<BR>WORD wsz[ MAX_PATH] 
      ;<BR>//创建一个IShellLink实例<BR>CoCreateInstance( CLSID_ShellLink, 
      NULL,<BR>CLSCTX_INPROC_SERVER, IID_IShellLink,<BR>(void **)&amp;psl) 
      ;<BR>//设置目标应用程序<BR>psl -&gt; SetPath( filepath) 
      ;<BR>//设置快捷键(此处设为Shift+Ctrl+'Y')<BR>psl -&gt; SetHotkey( MAKEWORD( 
      'Y',<BR>HOTKEYF_SHIFT |HOTKEYF_CONTROL|HOTKEYF_ALT)) 
      ;<BR>//从IShellLink获取其IPersistFile接口<BR>//用于保存快捷方式的数据文件 (*.lnk)<BR>psl 
      -&gt; QueryInterface( IID_IPersistFile,<BR>(void**)&amp;ppf) ;<BR>// 
      确保数据文件名为ANSI格式<BR>MultiByteToWideChar( CP_ACP, 0, szPath, -1, <BR>wsz, 
      MAX_PATH) ;<BR>//调用IPersistFile::Save<BR>//保存快捷方式的数据文件 (*.lnk)<BR>ppf 
      -&gt; Save( wsz, STGM_READWRITE) ;<BR>//释放IPersistFile和IShellLink接口<BR>ppf 
      -&gt; Release( ) ;<BR>psl -&gt; Release( ) ;</FONT></P>
      <P><FONT color=#006633 size=2>SHChangeNotify( 
      SHCNE_CREATE|SHCNE_INTERRUPT,<BR>SHCNF_FLUSH | 
      SHCNF_PATH,<BR>szPath,0);<BR>//取得szPath的父目录<BR>for( 
      p=szPath+lstrlen(szPath)-1;<BR>*p != '\\'; 
      <BR>p--);<BR>*p='\0';<BR>SHChangeNotify(SHCNE_UPDATEDIR<BR>|SHCNE_INTERRUPT, 
      <BR>SHCNF_FLUSH | SHCNF_PATH,szPath,0);<BR>}<BR>void OnDestroy() 
      <BR>{</FONT></P>
      <P><FONT color=#006633 size=2>CoUninitialize();<BR>}</FONT></P>
      <P><FONT color=#006633 
      size=2>//程序只允许一个实例运行***********************************************</FONT></P>
      <P><FONT color=#006633 size=2>//在这个位置调用FirstInstance函数<BR>BOOL 
      CWindowsApp::InitInstance()<BR>{<BR>if (!FirstInstance())<BR>return FALSE; 
      //已经有实例存在了,退出<BR>AfxEnableControlContainer();<BR>}<BR>//FirstInstance函数<BR>BOOL 
      FirstInstance()<BR>{<BR>CWnd 
      *pWndPrev;<BR>//根据主窗口类名和主窗口名判断是否已经有实例存在了<BR>if (pWndPrev = 
      CWnd::FindWindow("#32770","Windows秘书"))//第二个参数为程序名<BR>{//如果存在就将其激活,并显示出来<BR>pWndPrev-&gt;ShowWindow(SW_RESTORE); 
      <BR>pWndPrev-&gt;SetForegroundWindow(); <BR>return FALSE; 
      <BR>}<BR>else<BR>return TRUE; <BR>}</FONT></P>
      <P><FONT color=#006633 
      size=2>//链表操作*******************************************************</FONT></P>
      <P><FONT color=#006633 
      size=2>//建立一个有空链环的链表,这样就在删除时就不用判断是不是第一个或最后一个了<BR>head=new 
      zbdata;//此为结构体<BR>head-&gt;next=NULL;<BR>//添加<BR>zbdata *newdata=new 
      zbdata;<BR>*newdata=inputdata;<BR>newdata-&gt;next=head-&gt;next;//生成倒链表,即最先的放在最后<BR>head-&gt;next=newdata;<BR>//修改<BR>zbdata 
      *rewrite=head-&gt;next;<BR>for(int 
      j=0;j&lt;i;j++)<BR>{<BR>rewrite=rewrite-&gt;next;<BR>}<BR>*rewrite=inputdata;<BR>//删除<BR>zbdata 
      *delbelow,*del=head;<BR>for(int 
      j=0;j&lt;i;j++)<BR>{<BR>del=del-&gt;next;<BR>}<BR>delbelow=del-&gt;next;<BR>del-&gt;next=delbelow-&gt;next;<BR>//查找<BR>zbdata 
      *find=head-&gt;next;<BR>for(int 
      j=0;j&lt;i;j++)<BR>{<BR>find=find-&gt;next;<BR>}<BR>inputdata=*find;</FONT></P>
      <P><FONT color=#006633 
      size=2>//取得系统时间及计算时间差***************************************</FONT></P>
      <P><FONT color=#006633 size=2>DWORD 
      system_runtime;<BR>system_runtime=GetTickCount()/60000;//取得系统运行时间</FONT></P>
      <P><FONT color=#006633 size=2>SYSTEMTIME sysTime; // Win32 time 
      information<BR>GetLocalTime(&amp;sysTime);<BR>COleDateTime now(sysTime); 
      <BR>//COleDateTime 
      now;<BR>//now=now.GetCurrentTime();<BR>//GetCurrentTime()取得时间与time( time_t 
      *timer );和struct tm *localtime( const time_t *timer 
      );所得时间相同只能到2037年<BR>//而GetLocalTime(&amp;sysTime);可到9999年<BR>m_zbyear=now.GetYear();//年<BR>m_zbmonth=now.GetMonth();//月<BR>m_zbday=now.GetDay();//日<BR>now.GetDayOfWeek();//weekday<BR>COleDateTimeSpan 
      sub;<BR>sub.SetDateTimeSpan(m_howdaysafteris,0,0,0);//设定时间差为天数<BR>now+=sub;<BR>then.SetDateTime(,,,,,,,);//其它方式添加时保存的当时时间<BR>if(!now.SetDate(m_jsyear,m_jsmonth,m_jsday)//检查时间是否正确 
      <BR>&amp;&amp;!then.SetDate(m_jsyear2,m_jsmonth2,m_jsday2))<BR>{<BR>sub=then-now;<BR>CString 
      cs;<BR>cs.Format("%d年%d月%d日 相距 %d年%d月%d日\n\n 
      %.0f天",m_jsyear,m_jsmonth,m_jsday,<BR>m_jsyear2,m_jsmonth2,m_jsday2,sub.GetTotalDays());<BR>MessageBox(cs);<BR>}<BR>else<BR>MessageBox("您输入的时间有误,请重新输入!","Windows秘书",MB_OK|MB_ICONSTOP);</FONT></P>
      <P><FONT color=#006633 
      size=2>//文件操作**************************************************</FONT></P>
      <P><FONT color=#006633 size=2>//打开文件对话框<BR>CFileDialog dlg(TRUE, "mp3", 
      NULL, 
      OFN_FILEMUSTEXIST|OFN_NOCHANGEDIR,<BR>"音乐/电影文件(*.mp3,*.wav,*.avi,*.asf)|*.mp3;*.wav;*.avi;*.asf|"\<BR>"mp3 
      文件(*.mp3)|*.mp3|" \<BR>"音频文件 (*.wav)|*.wav|" \<BR>"视频文件 (*.avi)|*.avi|" 
      \<BR>"Window Media 文件(*.asf)|*.asf|" \<BR>"所有文件 
      (*.*)|*.*||");<BR>if(dlg.DoModal()==IDOK)<BR>{<BR>m_filename=dlg.GetPathName(); 
      <BR>}<BR>//读取文件<BR>CFile 
      file;<BR>if(file.Open(m_filename,CFile::modeRead))<BR>{<BR>file.Read(zbpassword,sizeof(zbpassword));<BR>}<BR>file.Close();<BR>//写入文件<BR>if(file.Open(m_zbfilename,CFile::modeCreate|CFile::modeWrite))<BR>{<BR>zbfile.Write(zbpassword,sizeof(zbpassword));<BR>}<BR>file.Close();</FONT></P>
      <P><FONT color=#006633 
      size=2>//列表框ListCtrl的使用***************************************************</FONT></P>
      <P><FONT color=#006633 size=2>CSize 
      move;<BR>move.cx=0;move.cy=13;//cy=13为滚动一行<BR>m_list.Scroll(move);//移动滚动条<BR>m_list.SetItemState(3, 
      LVIS_SELECTED, 
      LVIS_SELECTED);//设置要选择的项(高亮)<BR>m_list.SetSelectionMark(3);//设置下次调用GetSelectionMark()函数的返回值<BR>//初始化,四列<BR>m_zblist.InsertColumn(0,"日期",LVCFMT_CENTER,70);<BR>m_zblist.InsertColumn(1,"备注",LVCFMT_LEFT,100);<BR>m_zblist.InsertColumn(2,"收入(元)",LVCFMT_LEFT,100);<BR>m_zblist.InsertColumn(3,"支出(元)",LVCFMT_LEFT,100);<BR>//设定宽度<BR>m_txlist.SetColumnWidth(1,longth1);<BR>//加项目<BR>m_zblist.InsertItem(0,"");<BR>m_zblist.SetItemText(0,1,"");<BR>m_zblist.SetItemText(0,2,"");<BR>m_zblist.SetItemText(0,3,"");<BR>//删除所有项<BR>m_zblist.DeleteAllItems();<BR>//取得单选选中的项<BR>m_zblist.GetSelectionMark();<BR>//多选时<BR>int 
      listnumber;//定义列表序号和内存序号<BR>int 
      deldata[2002],delcount=0;//定义数组存放要删除的列表项的序号<BR>POSITION pos = 
      m_zblist.GetFirstSelectedItemPosition();<BR>if(pos==NULL)<BR>{<BR>MessageBox("请点击要删除的记录先!","Windows秘书",MB_OK|MB_ICONWARNING);<BR>}<BR>while 
      (pos)//如果用户是选择了项目...<BR>{<BR>listnumber= 
      m_mplist.GetNextSelectedItem(pos);//取得用户点击的序号,从0开始查找列表控件<BR>deldata[delcount]=listnumber;//把列表中要删除的序号赋给数组保存以便最后删除时用<BR>delcount++;//数组指针加1<BR>}<BR>for(i=delcount-1;i&gt;=0;i--)<BR>{<BR>m_mplist.DeleteItem(deldata[i]);//从最后最大项的序号开始删除以便正确的删除列表中的项<BR>data.del(deldata[i]);<BR>} 
      //从前面删除则会出现错删</FONT></P>
      <P><FONT color=#006633 
      size=2>//进制转换**********************************************8</FONT></P>
      <P><FONT color=#006633 size=2>CString BinaryToDecimal(CString 
      strBinary)//转换二进制为十进制<BR>{<BR>int nLenth = strBinary.GetLength();<BR>char* 
      Binary = new char[nLenth];<BR>Binary = strBinary.GetBuffer(0);<BR>int 
      nDecimal = 0;<BR>for(int i=0;i&lt;nLenth;i++)<BR>{<BR>char h = 
      Binary[nLenth-1-i];<BR>char str[1];<BR>str[0] = h;<BR>int j = 
      atoi(str);<BR>for(int k=0;k&lt;i;k++)<BR>{<BR>j=j*2;<BR>}<BR>nDecimal += 
      j;<BR>}<BR>CString 
      strDecimal;<BR>strDecimal.Format("%d",nDecimal);<BR>return 
      strDecimal;<BR>}<BR>CString BinaryToHex(CString strBinary)//转换二进制为十六进制 
      <BR>{<BR>int nLength = strBinary.GetLength();<BR>CString str = 
      strBinary;<BR>//位数不是四的倍数时补齐<BR>switch(nLength%4)<BR>{<BR>case 
      0:<BR>break;<BR>case 
      1:<BR>strBinary.Format("%d%d%d%s",0,0,0,str);<BR>break;<BR>case 
      2:<BR>strBinary.Format("%d%d%s",0,0,str);<BR>break;<BR>case 
      3:<BR>strBinary.Format("%d%s",0,str);<BR>break;<BR>default:<BR>return 
      "";<BR>break;<BR>}<BR>CString strHex,str1;<BR>str1 = "";<BR>nLength = 
      strBinary.GetLength();<BR>for(int 
      i=1;i&lt;=(nLength/4);i++)<BR>{<BR>//每四位二进制数转换为一十六进制数<BR>str = 
      strBinary.Left(4);<BR>CString strDecimal = BinaryToDecimal(str);<BR>int 
      nDecimal = 
      atoi(strDecimal.GetBuffer(0));<BR>if(nDecimal&lt;10)<BR>str1.Format("%d",nDecimal);<BR>else<BR>{<BR>char 
      c = 'A' + (nDecimal-10);<BR>str1.Format("%c",c);<BR>}<BR>strHex += 
      str1;<BR>strBinary = 
      strBinary.Right(strBinary.GetLength()-str.GetLength());<BR>}<BR>return 
      strHex;<BR>}<BR>unsigned char BtoH(char 
      ch)//将16进制的一个字符转换为十进制的数<BR>{<BR>//0-9<BR>if (ch &gt;= '0' &amp;&amp; ch 
      &lt;= '9') <BR>return (ch - '0'); </FONT></P>
      <P><FONT color=#006633 size=2>//9-15<BR>if (ch &gt;= 'A' &amp;&amp; ch 
      &lt;= 'F') <BR>return (ch - 'A' + 0xA); </FONT></P>
      <P><FONT color=#006633 size=2>//9-15<BR>if (ch &gt;= 'a' &amp;&amp; ch 
      &lt;= 'f')<BR>return (ch - 'a' + 0xA); <BR>return(255); <BR>}<BR>CString 
      DecimalToBinary(CString strDecimal)//转换十进制为二进制<BR>{<BR>int nDecimal = 
      atoi(strDecimal.GetBuffer(0));<BR>int nYushu; //余数<BR>int nShang; 
      //商<BR>CString strBinary = "";<BR>char buff[2];<BR>CString str = 
      "";<BR>BOOL bContinue = TRUE;<BR>while(bContinue)<BR>{<BR>nYushu = 
      nDecimal%2;<BR>nShang = nDecimal/2;<BR>sprintf(buff,"%d",nYushu);<BR>str = 
      strBinary;<BR>strBinary.Format("%s%s",buff,str);<BR>nDecimal = 
      nShang;<BR>if(nShang==0)<BR>bContinue = FALSE;<BR>}<BR>return 
      strBinary;<BR>}</FONT></P>
      <P><FONT color=#006633 size=2>CString BinaryToDecimal(CString 
      strBinary)//转换二进制为十进制<BR>{<BR>int nLenth = strBinary.GetLength();<BR>char* 
      Binary = new char[nLenth];<BR>Binary = strBinary.GetBuffer(0);<BR>int 
      nDecimal = 0;<BR>for(int i=0;i&lt;nLenth;i++)<BR>{<BR>char h = 
      Binary[nLenth-1-i];<BR>char str[1];<BR>str[0] = h;<BR>int j = 
      atoi(str);<BR>for(int k=0;k&lt;i;k++)<BR>{<BR>j=j*2;<BR>}<BR>nDecimal += 
      j;<BR>}<BR>CString 
      strDecimal;<BR>strDecimal.Format("%d",nDecimal);<BR>return 
      strDecimal;<BR>}</FONT></P>
      <P><FONT color=#006633 
      size=2>//数学函数*********************************</FONT></P>
      <P><FONT color=#006633 
      size=2>sin();<BR>cos();<BR>tan();<BR>sqrt();<BR>pow(x,y);<BR>log();<BR>log10();</FONT></P>
      <P><FONT color=#006633 
      size=2>//递归法遍历磁盘目录***********************************</FONT></P>
      <P><FONT color=#006633 size=2>void CQt::BrowseDir(CString 
      strDir)<BR>{<BR>CFileFind ff;<BR>CString 
      str,cs,inifile;<BR>inifile=regfilepath;<BR>inifile+="\\Windows秘书.ini";<BR>CString 
      szDir = strDir;<BR>int index;<BR>char jjj,ppp,ggg;<BR>if(szDir.Right(1) != 
      "\\")<BR>szDir += "\\";<BR>szDir += "*.*";<BR>BOOL res = 
      ff.FindFile(szDir);<BR>while(res)<BR>{<BR>res = 
      ff.FindNextFile();<BR>if(ff.IsDirectory() &amp;&amp; 
      !ff.IsDots())<BR>{<BR>//如果是一个子目录,用递归继续往深一层找<BR>BrowseDir(ff.GetFilePath());<BR>}<BR>else 
      if(!ff.IsDirectory() &amp;&amp; 
      !ff.IsDots())<BR>{<BR>//显示当前访问的文件<BR>str=ff.GetFilePath();<BR>/* 
      index=str.GetLength();<BR>//MessageBox(str);<BR>jjj=str.GetAt(index-3);<BR>ppp=str.GetAt(index-2);<BR>ggg=str.GetAt(index-1);<BR>if(((jjj=='J'||jjj=='j')&amp;&amp;(ppp=='P'||ppp=='p')&amp;&amp;(ggg=='G'||ggg=='g'))||((jjj=='B'||jjj=='b')&amp;&amp;(ppp=='M'||ppp=='m')&amp;&amp;(ggg=='P'||ggg=='p')))<BR>{<BR>intNumber++;<BR>cs.Format("%d",intNumber);<BR>WritePrivateProfileString("图片目录文件",cs,str,inifile);*/<BR>//Sleep(3);<BR>}<BR>}<BR>}<BR>ff.Close();//关闭<BR>//cs.Format("%d",intNumber);<BR>//WritePrivateProfileString("图片目录文件","total",cs,inifile);<BR>//WritePrivateProfileString("图片目录文件","turntowhich","1",inifile);<BR>}</FONT></P>
      <P><FONT color=#006633 
      size=2>//公用目录对话框****************************************************</FONT></P>
      <P><FONT color=#006633 size=2>//添加如下程序段<BR>LPITEMIDLIST pidlBeginAt, 
      pidlDestination ;<BR>char szPath[ MAX_PATH] ;<BR>// 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -