TA的每日心情 | 难过 2017-6-29 01:10 |
---|
签到天数: 376 天 [LV.9]以坛为家II
管理员
- 积分
- 13551
|
- void CMFCApplication2Dlg::OnBnClickedButtonDtohex()
- {
- UpdateData(TRUE);
- int num = atoi(m_sInput);
- m_sInput.Format("0x%x",num);
- UpdateData(FALSE);
- }
- void CMFCApplication2Dlg::OnBnClickedButtonHextod()
- {
- UpdateData(TRUE);
- m_sInput.MakeLower();
- char sz[50]={0};
- strcpy(sz,(LPCSTR)m_sInput);
- char* p = sz;
- int nlen = strlen(p);
- WORD dw = * (WORD*)p;
- char* p1="0x";
- WORD dw1 = *(WORD*)p1;
- if (dw==dw1)
- {
- p+=2;
- nlen-=2;
- }
- int data=0;
- int base=1;
- char *pend = p+nlen-1;
- while (pend>=p)
- {
- if (*pend>='a')
- {
- data+= ( (*pend-'a'+10) *base);
- }
- else
- {
- data+= ( (*pend-'0') *base);
- }
- base*=16;
- pend--;
- }
- m_sInput.Format("%d",data);
- UpdateData(FALSE);
- }
- void CMFCApplication2Dlg::OnBnClickedButtonDtob()
- {
- UpdateData(TRUE);
- int num = atoi(m_sInput);
- char sz[100]={0};
- char sz2[100]={0};
- int i=0;
- while (num>0)
- {
- int n = num%2;
- //TRACE("%d",n);
- if (n==1)
- {
- sz='1';
- }
- else
- {
- sz='0';
- }
- i++;
- num/=2;
- }
- i--;
- for (int j=0;j<=i;j++)
- {
- sz2[j]=sz[i-j];
- }
- m_sInput = sz2;
- UpdateData(FALSE);
- }
- void CMFCApplication2Dlg::OnBnClickedButtonBtod()
- {
- UpdateData(TRUE);
- m_sInput.MakeLower();
- char sz[100]={0};
- strcpy(sz,(LPCSTR)m_sInput);
- char* p = sz;
- int nlen = strlen(p);
- WORD dw = * (WORD*)p;
- int data=0;
- int base=1;
- char *pend = p+nlen-1;
- while (pend>=p)
- {
- data+= ( (*pend-'0') *base);
- base*=2;
- pend--;
- }
- m_sInput.Format("%d",data);
- UpdateData(FALSE);
- }
- void CMFCApplication2Dlg::OnBnClickedButtonRgbtoh()
- {
- UpdateData(TRUE);
- m_sInput.MakeLower();
- char rgb[3]={0};
- char sz[50]={0};
- strcpy(sz,(LPCSTR)m_sInput);
- char* p = sz;
- int nlen = strlen(p);
- int i = 0;
- char *tokenPtr=strtok(sz,",");
- while(tokenPtr!=NULL)
- {
- //cout<<tokenPtr<<'\n';
- rgb = atoi(tokenPtr);
- i++;
- tokenPtr=strtok(NULL,",");
- }
- if (i!=3)
- {
- AfxMessageBox("请输入如:12,255,241");
- return;
- }
- //int aa = RGB(1,2,3);
-
- m_sInput.Format("0x%06x",RGB(rgb[0],rgb[1],rgb[2]));
- UpdateData(FALSE);
- }
- void CMFCApplication2Dlg::OnBnClickedButtonHtorgb()
- {
- // TODO: 在此添加控件通知处理程序代码
- UpdateData(TRUE);
- m_sInput.MakeLower();
- char sz[50]={0};
- strcpy(sz,(LPCSTR)m_sInput);
- char* p = sz;
- int nlen = strlen(p);
- WORD dw = * (WORD*)p;
- char* p1="0x";
- WORD dw1 = *(WORD*)p1;
- if (dw==dw1)
- {
- p+=2;
- nlen-=2;
- }
- int data=0;
- int base=1;
- char *pend = p+nlen-1;
- while (pend>=p)
- {
- if (*pend>='a')
- {
- data+= ( (*pend-'a'+10) *base);
- }
- else
- {
- data+= ( (*pend-'0') *base);
- }
- base*=16;
- pend--;
- }
- //m_sInput.Format("%d",data);
- byte*pRgb =(byte*)&data;
-
- m_sInput.Format("%d,%d,%d",pRgb[0],pRgb[1],pRgb[2]);
- UpdateData(FALSE);
- }
- void CMFCApplication2Dlg::OnBnClickedButtonAsciitod()
- {
- UpdateData(TRUE);
- LPCSTR p=(LPCSTR)m_sInput;
- m_sInput.Format("%d",*p);
- UpdateData(FALSE);
- }
- void CMFCApplication2Dlg::OnBnClickedButtonDtoasciit()
- {
- UpdateData(TRUE);
- int num = atoi(m_sInput);
- m_sInput.Format("%c",num);
- UpdateData(FALSE);
- }
- void CMFCApplication2Dlg::OnBnClickedButtonDwtoip()
- {
- UpdateData(TRUE);
- DWORD dw = atol(m_sInput);
- byte ary_by[4]={0};
- memcpy(ary_by,&dw,sizeof(byte)*4);
- m_sInput.Format("%d.%d.%d.%d",ary_by[0],ary_by[1],ary_by[2],ary_by[3]);
- UpdateData(FALSE);
- }
- void CMFCApplication2Dlg::OnBnClickedButtonIptodw()
- {
- UpdateData(TRUE);
- char sz[50]={0};
- strcpy(sz,(LPCSTR)m_sInput);
- char* p = sz;
- int i = 0;
- char *tokenPtr=strtok(p,".");
- byte ary_by[4]={0};
- while(tokenPtr!=NULL)
- {
- ary_by = atoi(tokenPtr);
- i++;
- tokenPtr=strtok(NULL,".");
- }
- if (i!=4)
- {
- AfxMessageBox("请输入如:192.168.0.68");
- return;
- }
- DWORD dw;
- memcpy(&dw,ary_by,sizeof(ary_by)*4);
- m_sInput.Format("%d",dw);
- UpdateData(FALSE);
- }
复制代码
|
|