Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /WcsAPI/StringConvert.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (hide annotations) (download) (as text)
Wed Feb 10 18:21:00 2010 UTC (14 years ago) by sho1get
File MIME type: text/x-chdr
File size: 2350 byte(s)


1 sho1get 11 #pragma once
2    
3     #include <afxwin.h>
4    
5     //////////////////////////////////////////////////////////////////////////
6    
7     class CStringConvert
8     {
9     public:
10     CStringConvert() {}
11     virtual ~CStringConvert() {}
12    
13     CString DwToIPAddress(DWORD dwAddress)
14     {
15     CString cs;
16     dwAddress = htonl(dwAddress);
17     cs.Format(_T("%d.%d.%d.%d"),
18     (dwAddress >> 24) & 0xff,
19     (dwAddress >> 16) & 0xff,
20     (dwAddress >> 8) & 0xff,
21     dwAddress & 0xff);
22     return cs;
23     }
24    
25     CString DwToString(DWORD dwNumber)
26     {
27     CString cs;
28     cs.Format(_T("%d"), dwNumber);
29     return cs;
30     }
31    
32     CString DbToString(double dwNumber)
33     {
34     CString cs;
35     cs.Format(_T("%10.4lf"), dwNumber);
36     return cs;
37     }
38    
39     CString DbToHMSTime(double dbTime)
40     {
41     CString cs;
42     UINT uHour, uMinute, uSecond;
43    
44     uHour = static_cast<UINT>(dbTime / 3600);
45     uMinute = static_cast<UINT>((dbTime - uHour * 3600) / 60);
46     uSecond = static_cast<UINT>(dbTime - (uHour * 3600 + uMinute * 60));
47     cs.Format(_T("%02d:%02d:%02d"), uHour, uMinute, uSecond);
48    
49     return cs;
50     }
51    
52     CString GetNowTime()
53     {
54     CString cs;
55     SYSTEMTIME st;
56    
57     GetLocalTime(&st);
58     cs.Format(_T("%04d/%02d/%02d %02d:%02d:%02d"),
59     st.wYear, st.wMonth, st.wDay,
60     st.wHour, st.wMinute, st.wSecond);
61    
62     return cs;
63     }
64    
65     void BigNumToString(CString &csParam)
66     {
67     NUMBERFMT nf;
68     TCHAR szBuf[100];
69    
70     lstrcpy(szBuf, csParam.GetBuffer(100));
71     csParam.ReleaseBuffer();
72     nf.NumDigits = 0;
73     nf.LeadingZero = FALSE;
74     nf.Grouping = 3;
75     nf.lpDecimalSep = _T(".");
76     nf.lpThousandSep = _T(",");
77     nf.NegativeOrder = 0;
78     GetNumberFormat(LOCALE_USER_DEFAULT,
79     0,
80     szBuf,
81     &nf,
82     csParam.GetBuffer(),
83     100);
84     csParam.ReleaseBuffer();
85     }
86    
87     void StringToByteArray(CString &cs, CByteArray &data)
88     {
89     LPBYTE lpData;
90     UINT nLength;
91    
92     nLength = cs.GetLength();
93     lpData = reinterpret_cast<LPBYTE>(static_cast<LPTSTR>(cs.GetBuffer()));
94     data.SetSize(cs.GetLength() * sizeof(TCHAR));
95     CopyMemory(data.GetData(), lpData, data.GetSize());
96     cs.ReleaseBuffer();
97     data.FreeExtra();
98     }
99    
100     void ByteArrayToString(CByteArray &data, CString &cs)
101     {
102     cs.SetString(reinterpret_cast<LPTSTR>(data.GetData()), data.GetSize() / sizeof(TCHAR));
103     }
104     };
105    
106     //////////////////////////////////////////////////////////////////////////

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26