文章标题

来源:互联网 发布:淘宝定价策略案例 编辑:程序博客网 时间:2024/05/18 22:45

AutoAddDlg.cpp
// AutoAddDlg.cpp : implementation file
//

include “stdafx.h”

include “AutoAdd.h”

include “AutoAddDlg.h”

ifdef _DEBUG

define new DEBUG_NEW

endif

define MAX_STRING_COUNT 400

unsigned char szText[MAX_STRING_COUNT];

CWinThread * pThread = NULL;
static UINT ThreadWorkFunction(LPVOID lPvoid);

// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
enum { IDD = IDD_ABOUTBOX };

protected:virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()

// CAutoAddDlg dialog

CAutoAddDlg::CAutoAddDlg(CWnd* pParent /=NULL/)
: CDialog(CAutoAddDlg::IDD, pParent)
, m_sTimeValue(_T(“”))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

m_strCurrentExePath=_T("");m_Second=0, m_Minute=0, m_Hour=0;m_strFilePath=_T("");

}

void CAutoAddDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_FILENAME, m_listBox);
DDX_Control(pDX, IDC_STATIC_TIMER, m_sTimeCtrl);
DDX_Control(pDX, IDC_STATIC_FILEPATH, m_sFilePathCtrl);
DDX_Text(pDX, IDC_STATIC_TIMER, m_sTimeValue);
DDX_Control(pDX, IDC_COMBO_LANGUAGE, m_ComboLanguage);
}

BEGIN_MESSAGE_MAP(CAutoAddDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BTN_START, &CAutoAddDlg::OnBnClickedBtnStart)
ON_LBN_DBLCLK(IDC_LIST_FILENAME, &CAutoAddDlg::OnLbnDblclkListFilename)
ON_WM_TIMER()
ON_WM_WINDOWPOSCHANGED()
ON_BN_CLICKED(IDC_BTNFILE, &CAutoAddDlg::OnBnClickedBtnfile)
ON_MESSAGE(WM_TASKBAR, OnTaskbar)
ON_WM_DESTROY()
ON_CBN_SELCHANGE(IDC_COMBO_LANGUAGE, &CAutoAddDlg::OnCbnSelchangeComboLanguage)
ON_LBN_SELCHANGE(IDC_LIST_FILENAME, &CAutoAddDlg::OnLbnSelchangeListFilename)
ON_BN_CLICKED(IDC_BTN_AUTOFILLING, &CAutoAddDlg::OnBnClickedBtnAutofilling)
ON_BN_CLICKED(IDC_BTNFILE2, &CAutoAddDlg::OnBnClickedBtnfile2)
END_MESSAGE_MAP()

// CAutoAddDlg message handlers

BOOL CAutoAddDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.// IDM_ABOUTBOX must be in the system command range.ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL){    CString strAboutMenu;    strAboutMenu.LoadString(IDS_ABOUTBOX);    if (!strAboutMenu.IsEmpty())    {        pSysMenu->AppendMenu(MF_SEPARATOR);        pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);    }}// Set the icon for this dialog.  The framework does this automatically//  when the application's main window is not a dialogSetIcon(m_hIcon, TRUE);         // Set big iconSetIcon(m_hIcon, FALSE);        // Set small icon// TODO: Add extra initialization hereCurrentExePath();m_ComboLanguage.AddString(_T("英语"));m_ComboLanguage.AddString(_T("中文"));m_ComboLanguage.AddString(_T("德语"));m_ComboLanguage.AddString(_T("法语"));m_ComboLanguage.AddString(_T("荷兰语"));m_ComboLanguage.AddString(_T("瑞典语"));m_ComboLanguage.AddString(_T("葡萄牙语"));m_ComboLanguage.AddString(_T("西班牙语"));m_ComboLanguage.AddString(_T("韩语"));m_ComboLanguage.AddString(_T("日语"));m_ComboLanguage.AddString(_T("俄语"));m_ComboLanguage.AddString(_T("意大利语"));m_ComboLanguage.AddString(_T("波兰"));m_ComboLanguage.AddString(_T("匈牙利语"));m_ComboLanguage.AddString(_T("泰语"));m_ComboLanguage.AddString(_T("中文繁体"));m_ComboLanguage.AddString(_T("希伯来语"));m_ComboLanguage.SetCurSel(0);ShowWindow(SW_HIDE);ModifyStyleEx(WS_EX_APPWINDOW, WS_EX_TOOLWINDOW, 0);AddIcon();return TRUE;  // return TRUE  unless you set the focus to a control

}

void CAutoAddDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CAutoAddDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

    SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);    // Center icon in client rectangle    int cxIcon = GetSystemMetrics(SM_CXICON);    int cyIcon = GetSystemMetrics(SM_CYICON);    CRect rect;    GetClientRect(&rect);    int x = (rect.Width() - cxIcon + 1) / 2;    int y = (rect.Height() - cyIcon + 1) / 2;    // Draw the icon    dc.DrawIcon(x, y, m_hIcon);}else{    CDialog::OnPaint();}

}

// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CAutoAddDlg::OnQueryDragIcon()
{
return static_cast(m_hIcon);
}

UINT ThreadWorkFunction(LPVOID lPvoid)
{
CAutoAddDlg * dlg = (CAutoAddDlg *)lPvoid;
vector vctFileProperty;
dlg->GetFileAllInformation(dlg->m_strDirPath, _T(“.txt”), vctFileProperty);

pThread = NULL;return 0;

}

// 获取exe所在文件夹路径,返回字符串长度
UINT GetAppPath( Out char* lpPath, In DWORD dwBufferSize)
{
ZeroMemory(lpPath, dwBufferSize);
TCHAR exePath[MAX_PATH];
DWORD dwFile;
// exe 全文件路径与GetCurrentDirectory不一样,后者是当前目录而不是exe的目录
dwFile = GetModuleFileName(NULL, exePath, MAX_PATH);
if ( ERROR_SUCCESS== dwFile)
{
TCHAR errBuffer[20];
wsprintf(errBuffer, TEXT(“%s%d”),TEXT(“获取exe文件路径出错,错误码:”), GetLastError() );
MessageBox(NULL,errBuffer,TEXT(“Error”),MB_OK);
}
else
{
//Returns a pointer to the last occurrence of c in string, or NULL if c is not found.
char ch[MAX_PATH];
Tchar2Char(exePath, ch);
char *pLastSlash = strrchr( ch, ‘\’);
strncpy(lpPath, ch, pLastSlash - ch );
}
return dwFile;
}

BOOL CAutoAddDlg::CurrentExePath()
{
char lpPath[MAX_PATH];
UINT uiLength=0;
int lpPathSize = sizeof(lpPath)/sizeof(TCHAR);
memset(lpPath, 0, MAX_PATH);
uiLength = GetAppPath(lpPath, MAX_PATH);
if (ERROR_SUCCESS == uiLength)
{
return FALSE;
}
else
{
m_strCurrentExePath.Format(_T(“%s”), lpPath);
}
return TRUE;
}

UINT CAutoAddDlg::GetFileAllInformation(In CString strFilePath, In CString strExt, Out vector& vctFileProperty)
{
CFileFind finder;
BOOL bWorking = FALSE;

bWorking=PathIsDirectory(strFilePath);//判断文件路径是否存在if (ERROR_SUCCESS == bWorking){    return -1;//输入的文件路径是不存在的}//if (strFilePath.GetLength())    bWorking = finder.FindFile(strFilePath+_T("\\*.*"));while (bWorking){    bWorking=finder.FindNextFile();    if (finder.IsDots())    {        if (finder.GetFileName() == _T("..") && FALSE == bWorking)            break;        else                continue;    }    if (finder.IsDirectory())    {        CString strPath = finder.GetFilePath();        GetFileAllInformation(strPath, strExt, vctFileProperty);    }    else    {        FileProperty fp;        fp.FileName=finder.GetFileName();//GetFileName获取找到文件的名字        CString strFileUp=fp.FileName;        strFileUp.MakeUpper();        strExt.MakeUpper();        if (strFileUp.Right(strExt.GetLength()) == strExt || strFileUp.Left(strExt.GetLength()) == strExt ||strFileUp == strExt)        {            fp.FileLength = finder.GetLength(); //GetLength获取找到文件的长度,以字节为单位            fp.FilePath     = finder.GetFilePath();     //GetFilePath找到文件的全路径            fp.FileTitle        = finder.GetFileTitle();        //GetFileTitle获取找到文件的标题,标题不包括扩展内容            fp.FileRoot = finder.GetRoot();     //GetRoot获取找到文件根目录            finder.GetCreationTime(fp.CreationTime);            //GetCreationTime获取文件创建时间            finder.GetLastAccessTime( fp.LastAccessTime);       //GetLastAccessTime获取文件最后一次打开的时间            finder.GetLastWriteTime( fp.LastWriteTime);     //GetLastWriteTime文件最后改变和存储的时间            fp.IsReadOnly   = finder.IsReadOnly();          //IsReadOnly文件是否是只读            fp.IsDirectory  = finder.IsDirectory();         //IsDirectory文件是否是目录            fp.IsCompressed = finder.IsCompressed();        //IsCompressed文件是否是压缩            fp.IsSystem = finder.IsSystem();                //IsSystem文件是否是系统文件            fp.IsHidden = finder.IsHidden();                //IsHidden文件是否是隐藏            fp.IsTemporary  =finder.IsTemporary();      //IsTemporary文件是否是临时的            fp.IsNormal = finder.IsNormal();                //IsNormal文件是否是常规的(无其它属性)            fp.IsArchived   =finder.IsArchived();           //IsArchived文件是否是档案            vctFileProperty.push_back(fp);             m_listBox.AddString(fp.FilePath);            return 0;        }               }}return -2;//没有找到

}

void CAutoAddDlg::OpenFile()
{
CFileDialog fileDlg(TRUE, _T(“dat Files (dat)”), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT | OFN_ENABLESIZING, _T(“Layer Files (.txt;.dat;.)|.txt;.dat;.*)||”), NULL);
fileDlg.m_ofn.lpstrTitle = _T(“请加载相关图层”);
//最多可以打开500个文件
fileDlg.m_ofn.nMaxFile = 500 * MAX_PATH;
fileDlg.m_ofn.lpstrFile = new TCHAR[fileDlg.m_ofn.nMaxFile];
ZeroMemory(fileDlg.m_ofn.lpstrFile, sizeof(TCHAR)* fileDlg.m_ofn.nMaxFile);
//设置默认打开路径
fileDlg.m_ofn.lpstrInitialDir = _T(“D:\work_demo”);

m_sFilePathCtrl.SetWindowText(fileDlg.m_ofn.lpstrInitialDir);//显示文件对话框,获得文件名集合int retval = fileDlg.DoModal();if (retval == IDCANCEL)    AfxMessageBox(_T("文件夹打开失败"));//获取实际打开文件夹 m_sFilePathCtrl.SetWindowText(fileDlg.GetPathName());POSITION pos_file;pos_file = fileDlg.GetStartPosition();while (pos_file != NULL){    m_listBox.AddString(fileDlg.GetNextPathName(pos_file));}delete fileDlg.m_ofn.lpstrFile;/*CFileDialog filedlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT,_T("MyType Files (*.txt)|*.txt|All Files (*.*)|*.*||"));int iStruct = 0;if(GetVersion() < 0x80000000)//WINAPI versioniStruct = 88;elseiStruct = 76;filedlg.m_ofn.lStructSize = iStruct;m_list.ResetContent();CString fileName;const int c_cMaxFiles =12500;const int c_cbBuffSize = (c_cMaxFiles * (11200 + 1)) + 1;filedlg.GetOFN().lpstrFile = fileName.GetBuffer(c_cbBuffSize);filedlg.GetOFN().nMaxFile = c_cMaxFiles;if(filedlg.DoModal() == IDOK){POSITION pos = filedlg.GetStartPosition();while (pos != NULL){CString m_strFileName = filedlg.GetNextPathName(pos);vecStrFileName.push_back(m_strFileName);m_list.AddString(m_strFileName);}}*/

}

void CAutoAddDlg::OnBnClickedBtnStart()
{
// TODO: Add your control notification handler code here
KillTimer(1);

m_Second=m_Minute=m_Hour=0;SetTimer(1, 1000, NULL);//first param:event ID; second param:Specifies the time-out value, in milliseconds.

}

BOOL CAutoAddDlg::AddIcon()
{
HICON hIcon=theApp.LoadIcon(IDI_ICON_Time);//图标句柄
CString lpszTip = _T(“little chock!”);

//给NOTIFYICONDATA结构赋值NOTIFYICONDATA tnid;tnid.cbSize = sizeof(NOTIFYICONDATA);tnid.hWnd = m_hWnd;tnid.uID = IDI_ICON_Time;tnid.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;tnid.uCallbackMessage = WM_TASKBAR;tnid.hIcon = hIcon;lstrcpyn(tnid.szTip, lpszTip, sizeof(tnid.szTip));return Shell_NotifyIcon(NIM_ADD, &tnid);

}

void CAutoAddDlg::OnLbnDblclkListFilename()
{
// TODO: Add your control notification handler code here
CString strFilePath=_T(“”);
int iItem = m_listBox.GetCurSel();//get cursel position
m_listBox.GetText(iItem, strFilePath);//get item text, for file path

SetDlgItemText(IDC_STATIC_FILEPATH, strFilePath);//双击用编辑器打开文件::ShellExecute(NULL, _T("open"), strFilePath, NULL, NULL, SW_SHOWNORMAL);//default//::ShellExecute(NULL, L"OPEN", strFilePath, NULL, L"C:\\Windows\\system32\\notepad.exe", SW_SHOWNORMAL);////MessageBox(strFilePath);

}

BOOL CAutoAddDlg::DeleteIcon()
{
//提供结构大小,窗口句柄和图标ID
NOTIFYICONDATA tnid;

tnid.cbSize = sizeof(NOTIFYICONDATA);tnid.hWnd = m_hWnd;tnid.uID = IDI_ICON_Time;//用NIM_DELETE删除图标return Shell_NotifyIcon(NIM_DELETE, &tnid);

}

LRESULT CAutoAddDlg::OnTaskbar(WPARAM wParam, LPARAM lParam)
{
UINT uMouseMsg = (UINT)lParam;
switch (uMouseMsg)
{
case WM_LBUTTONDOWN://鼠标左键消息
ShowWindow(SW_SHOWNORMAL);
break;
case WM_RBUTTONUP: // 鼠标右键消息
break;
//添加其他响应消息
default:
break;
}

return 0;

}

void CAutoAddDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
// Print out the day of the week using localized day name
UINT DayOfWeek[] = {
LOCALE_SDAYNAME7, // Sunday
LOCALE_SDAYNAME1,
LOCALE_SDAYNAME2,
LOCALE_SDAYNAME3,
LOCALE_SDAYNAME4,
LOCALE_SDAYNAME5,
LOCALE_SDAYNAME6 // Saturday
};

CTime timer=CTime::GetCurrentTime();TCHAR strWeek[255];::GetLocaleInfo(LOCALE_USER_DEFAULT, DayOfWeek[timer.GetDayOfWeek()-1], strWeek, sizeof(strWeek));m_sTimeValue.Format(_T("北京时间:%d年 %02d月 %02d日 %s\n %02d : %02d : %02d"),    timer.GetYear(),timer.GetMonth(),timer.GetDay(), strWeek,    timer.GetHour(), timer.GetMinute(), timer.GetSecond());UpdateData(FALSE);//给控件传值//CDialog::OnTimer(nIDEvent);

}

void CAutoAddDlg::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
CDialog::OnWindowPosChanged(lpwndpos);

// TODO: Add your message handler code here::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);

}

void CAutoAddDlg::OnBnClickedBtnfile()
{
// TODO: Add your control notification handler code here
OpenFolder();
}

void CAutoAddDlg::OpenFolder()
{
m_listBox.ResetContent();

BROWSEINFO bRowSeinfo;TCHAR buf[MAX_PATH] = {0};//初始化入口参数bRowSeinfobRowSeinfo.hwndOwner=this->GetSafeHwnd();bRowSeinfo.pidlRoot=NULL;//初始化制定的root目录很不容易bRowSeinfo.pszDisplayName = buf;//此参数为NULL则不能显示对话框bRowSeinfo.lpszTitle=_T("请选择一个文件夹");bRowSeinfo.ulFlags=BIF_EDITBOX;//BIF_STATUSTEXT/BIF_VALIDATE 对窗口的一些操作类型bRowSeinfo.iImage=IDR_MAINFRAME;bRowSeinfo.lParam=0;bRowSeinfo.lpfn=NULL;//完成初始化//调用显示选择对话框LPITEMIDLIST pIDList=SHBrowseForFolder(&bRowSeinfo);if (pIDList){    //取得文件夹路径    SHGetPathFromIDList(pIDList, buf);    m_strDirPath = buf;    pThread = AfxBeginThread(ThreadWorkFunction, (LPVOID)(this), 0, 0, NULL);    if (!pThread)    {        MessageBox(_T("begin thread failed!!!"));    }    SetDlgItemText(IDC_STATIC_FILEPATH, m_strDirPath);}

}
void CAutoAddDlg::OnDestroy()
{
CDialog::OnDestroy();

// TODO: Add your message handler code hereDeleteIcon();

}

void CAutoAddDlg::SetSdScanFolder()
{
int nRet=0;
vector vctFileProperty;
nRet = GetFileAllInformation(m_strDirPath, _T(“Setup.ini”), vctFileProperty);
if (nRet < 0)
{
AfxMessageBox(_T(“没有找到Setup.ini文件”));
return ;
}
CGlobalInterface::SetSdScanDirectory(vctFileProperty[0].FilePath);
}

void CAutoAddDlg::WriteStringToIniFile()
{
CProfile::WriteString(CGlobalInterface::GetSdScanDirectory() + _T(“Setup.ini”),_T(“Setup”),_T(“init”),CGlobalInterface::GetLanguage(), FALSE);
}
void CAutoAddDlg::OnCbnSelchangeComboLanguage()
{
// TODO: Add your control notification handler code here
int iSelLanguage = m_ComboLanguage.GetCurSel();
switch (iSelLanguage)
{
case 0:
CGlobalInterface::SetLanguage(_T(“EN”)); break;
case 1:
CGlobalInterface::SetLanguage(_T(“CN”)); break;
case 2:
CGlobalInterface::SetLanguage(_T(“DE”)); break;
case 3:
CGlobalInterface::SetLanguage(_T(“FR”)); break;
case 4:
CGlobalInterface::SetLanguage(_T(“NL”)); break;
case 5:
CGlobalInterface::SetLanguage(_T(“SE”)); break;
case 6:
CGlobalInterface::SetLanguage(_T(“PT”)); break;
case 7:
CGlobalInterface::SetLanguage(_T(“KR”)); break;
case 8:
CGlobalInterface::SetLanguage(_T(“JP”)); break;
case 9:
CGlobalInterface::SetLanguage(_T(“RU”)); break;
case 10:
CGlobalInterface::SetLanguage(_T(“IT”)); break;
case 11:
CGlobalInterface::SetLanguage(_T(“PL”)); break;
case 12:
CGlobalInterface::SetLanguage(_T(“HU”)); break;
case 13:
CGlobalInterface::SetLanguage(_T(“TH”)); break;
case 14:
CGlobalInterface::SetLanguage(_T(“HK”)); break;
case 15:
CGlobalInterface::SetLanguage(_T(“ES”)); break;
case 16:
CGlobalInterface::SetLanguage(_T(“HE”)); break;
default:
CGlobalInterface::SetLanguage(_T(“EN”)); break;
}
WriteStringToIniFile();
}

void CAutoAddDlg::TestMyString()
{
// 验证默认构造函数
CMyString str(“Hello World”);
cout<

include “stdafx.h”

include “arithmetic.h”

int SeparatorString(const string &strSrc,const string &strSeparator,vector &vctStrSave)
{
vctStrSave.clear();
if (strSrc.empty() || strSeparator.empty())
{
return 0;
}

// 一个都没出现时if (strSrc.find(strSeparator) == -1) {    vctStrSave.push_back(strSrc);    return vctStrSave.size();}// 多个时int iEnd = -1;int iStart = 0;while ( -1 != (iEnd = strSrc.find(strSeparator, iStart))  ){    vctStrSave.push_back(strSrc.substr(iStart, iEnd - iStart));    iStart = iEnd + strSeparator.size();}vctStrSave.push_back(strSrc.substr(iStart, iEnd - iStart));return vctStrSave.size();

}

unsigned char Char2Hex(unsigned char ucTemp)
{
unsigned char ucResult = 0;
if (ucTemp >= ‘0’ && ucTemp <= ‘9’)
{
ucResult = ucTemp - ‘0’;
}
else if (ucTemp >= ‘a’ && ucTemp <= ‘f’)
{
ucResult = ucTemp - ‘a’ + 10;
}
else if (ucTemp >= ‘A’ && ucTemp <= ‘F’)
{
ucResult = ucTemp - ‘A’ + 10;
}
return ucResult;
}

int String2Hex(const string &strSrc)
{
int iRet = 0;
char *p;
vector vctStr;

SeparatorString(strSrc,",",vctStr);if(vctStr.size() == 1)    iRet = strtoul(strSrc.data(),&p,16);else{    for(int i = 0;i < vctStr.size();i ++)    {        string str;        str = vctStr[i].c_str();        iRet += ((strtoul(str.data(),&p,16))<<((vctStr.size()-i-1)*8));    }}return iRet;

}

LONG64 String2Hex4(const string &strSrc)
{
LONG64 l64Ret = 0;
char *p;
vector vctStr;

SeparatorString(strSrc,",",vctStr);if(vctStr.size() == 1)    l64Ret = strtoul(strSrc.data(),&p,16);else{    for(int i = 0;i < vctStr.size();i ++)    {        string str;        str = vctStr[i].c_str();        l64Ret += ((strtoul(str.data(),&p,16))<<((vctStr.size()-i-1)*8));    }}return l64Ret;

}

W_U32 String2ul(const string &strSrc)
{
W_U32 iRet;
char *p;

iRet = strtoul(strSrc.data(),&p,16);return iRet;

}

int String2Dec(const string &strSrc)
{
int iRet;

iRet = _atoi64(strSrc.c_str());return iRet;

}
W_FLOAT String2Float(const string &strSrc)
{
float fRet;

fRet = atof(strSrc.data());return fRet;

}

string Byte2HexString(unsigned char val)
{
string str;
char chvalue[8] = {0};

sprintf(chvalue,"%02X",val);str = chvalue;return str;

}

//将字符串中小写字母转换成大写
string StringConvert(const string &strSource)
{
int i,len;
string str;

len = strSource.length();for (i=0; i<len; i++){    if(strSource.at(i) == 0x20)        continue;    if(strSource.at(i) >= 0x61 && strSource.at(i) <= 0x7A) //a-z        str += strSource.at(i)-0x20;    else        str += strSource.at(i);}return str;

}

int TestString2Int()
{
string str4Hex=”80101010”;
CString str4Hex2 = _T(“80101010”);
LONG64 l64;
int isize = sizeof(l64);
l64 = String2Hex(str4Hex);
l64 = String2Hex4(str4Hex);
STIF_FLAGS p=16;
LONGLONG ll[64];
StrToInt64Ex(str4Hex2, p, ll);

l64 = Hex2Dec(str4Hex.c_str());int he;    int re=0;   // 保存转换为10进制的结果int k=16;   // 16进制int n=1;    // 位权//scanf("%d", &he);  // 接收用户输入的16进制数,不含0x前缀while(ll[0] != 0)  {    l64 += (ll[0]%10)*n;  // 取出各位位码值,并乘以对应的位权值    re += (ll[0]%10)*n;    ll[0] /= 10;   // 去掉16进制数的最低位,次低位变为最低位    n *= k;     // 位权乘以16}l64 +=0;re +=0;return re;

}

//返回16进制字符串s对应的整数值,遇到任何一个非法字符都返回-1。
int Hex2Dec(const char *s)
{
const char *p = s;
//空串返回0。
if(*p == ‘\0’) return 0;
//忽略开头的’0’字符
while(*p == ‘0’) p++;
int dec = 0; char c;
//循环直到字符串结束。
while(c = *p++)
{
//dec乘16
dec <<= 4;
//数字字符。
if(c >= ‘0’ && c <= ‘9’)
{
dec += c - ‘0’;
continue;
}
//小写abcdef。
if(c >= ‘a’ && c <= ‘f’)
{
dec += c - ‘a’ + 10;
continue;
}
//大写ABCDEF。
if(c >= ‘A’ && c <= ‘F’)
{
dec += c - ‘A’ + 10;
continue;
}
//没有从任何一个if语句中结束,说明遇到了非法字符。
return -1;
} //正常结束循环,返回10进制整数值。
return dec;
}

//将TCHAR转为char
//*tchar是TCHAR类型指针,*_char是char类型指针
void Tchar2Char (const TCHAR * tchar, char * _char)
{
int iLength;
//获取字节长度
iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL);
//将tchar值赋给_char
WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL);
}

//同上
void CharToTchar (const char * _char, TCHAR * tchar)
{
int iLength;

iLength = MultiByteToWideChar (CP_ACP, 0, _char, strlen (_char) + 1, NULL, 0);MultiByteToWideChar (CP_ACP, 0, _char, strlen (_char) + 1, tchar, iLength);

}
arithmetic.h

include

include

include

define W_U32 unsigned int

define W_FLOAT float

/* 函数功能:分割字符串
* strSrc:要分割的字符串
* strSeparator:分割符
* vctStrSave:存放分割后字符串
* 返回值:vctStrSave的大小
*/
int SeparatorString(const string &strSrc,const string &strSeparator,vector &vctStrSave);
unsigned char Char2Hex(unsigned char ucTemp);

int String2Hex(const string &strSrc);
int String2Dec(const string &strSrc);
int Hex2Dec(const char *s);
LONG64 String2Hex4(const string &strSrc);
W_U32 String2ul(const string &strSrc);
W_FLOAT String2Float(const string &strSrc);

/* 函数功能:将字符串中的小写替换成大写
* 返回值:转换后的字符串
*/
string StringConvert(const string &strSrc);

/* 函数功能:byte字节转换成字符串
*
*/
string Byte2HexString(unsigned char val);
/* 测试字符串转int,字符串高位是80,按照之前的方法转换会导致转换后的int是负数
*
*/
int TestString2Int();

void Tchar2Char (const TCHAR * tchar, char * _char);
void CharToTchar (const char * _char, TCHAR * tchar);

0 0
原创粉丝点击