From 8665e17282f79fefb4191e0db4788de3fdd22d9d Mon Sep 17 00:00:00 2001 From: Zhong Yang Date: Sun, 12 Jul 2020 00:10:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E6=9C=AC=E6=A1=86=E4=B8=AD=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E7=9A=84COLORREF=E5=92=8CRGB=E5=80=BC=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=87=AA=E5=8A=A8=E5=88=A4=E6=96=AD=E8=BF=9B=E5=88=B6?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=8110=E3=80=818=E3=80=8116=E8=BF=9B?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ColorPicker/ColorPicker.rc | Bin 28246 -> 28054 bytes ColorPicker/ColorPickerDlg.cpp | 12 ++++++------ ColorPicker/Common.cpp | 16 ++++++++++++++++ ColorPicker/Common.h | 3 +++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/ColorPicker/ColorPicker.rc b/ColorPicker/ColorPicker.rc index 101e91dfa2bd7c40ca2dcd5c88fa338e78f74bb9..961b7e4ed28cf6e3fd87e9929ed2e4f9a311f685 100644 GIT binary patch delta 151 zcmcb1hjH3%#tm@_j3$#msu)h@QdHV}O5qmcWHD8}$*+`Ffax2`D<&JcJ8Zt8vPp^A zlmVgghx-*qW+Mhepw?iZYLFqhp8mq_3_1*^3`RiG97yW`Sr8RBloc2)z$%=8q81Eh RXetaR+qs);*6`6&0sx5hE*Ag* delta 301 zcmbPsoAKHm#tm@_lP9RCi7PPFFeos%G6XZkGx#xtGWaq$0eL}_1KssEZ&J9$h*LqL zvi{^& str.LoadString(id); return StringFormat(str.GetString(), paras); } + +unsigned int CCommon::StringToNumber(const CString& str) +{ + //判断进制 + int radix{ 10 }; + if (str.GetLength() >= 3 && str[0] == _T('0') && (str[1] == _T('x') || str[1] == _T('X'))) + { + radix = 16; + } + else if (str.GetLength() >= 2 && str[0] == _T('0')) + { + radix = 8; + } + TCHAR* end_ptr{}; + return _tcstoul(str.GetString(), &end_ptr, radix); +} diff --git a/ColorPicker/Common.h b/ColorPicker/Common.h index 693c7c4..ae81905 100644 --- a/ColorPicker/Common.h +++ b/ColorPicker/Common.h @@ -39,5 +39,8 @@ class CCommon //从资源文件中载入字符串,并将资源字符串中形如<%序号%>的字符串替换成可变参数列表中的参数 static CString LoadTextFormat(UINT id, const std::initializer_list& paras); + //将字符串转换成数字,支持自动识别十六进制、八进制和十进制 + static unsigned int StringToNumber(const CString& str); + };