EVC编程点滴(概述)-注册表操作类

我辞职前,在公司负责在Windows CE系统上,通过串口控制GSM模块,实现一般手机的功能。即通话、SMS、通话记录、电话本(SIM和手机上);还有设置部分,如一般手机上的;然后就是多媒体部分,如Camera拍照、录音、图片浏览与一些基本操作;最后就是一些小的工具,如手机号码归属地查询、秒表、备忘录等。
还有就是Windows CE系统定制,如前述文章所描述的那样。
其实编程都是很细节的问题,一般都是发现再想办法解决。在解决过程中积累经验,现在辞职了,我就想将以前工作遇到的问题、和一些内容进行整理。对自己也是再学习的过程。这里主要整理EVC编程相关的部分,很多内容也是以前在网上查找到的(希望不会有侵权问题出现,如果出现请联系我,我将进行处理。多谢!)
今天先列个目录出来,后继再慢慢的完善啦!
1)注册表操作类
2)GIF动画显示类
3)TIMER的测试
4)键盘钩子
5)GSM模块的问题
6)图片游览:CxImage和VOImage
7)手机号码归属地查询
此功能用于来电时,直接显示号码所属地;同时提供一个小的工具,用户可以自己输入号码进行查询。
8)日历与时间控件
9)多语言的实现
10)界面实现的一些想法
11)输入法状态栏的处理
12)日历算法
13)拍照功能的实现
14)录音(WAV)格式
15)GSM AT命令
今天只能想起这么多了,以后想到再更新。
先说说注册表操作类,这个类在网上有很多实现的版本。我也在网上找到一个CE下注册表操作的源代码,实现风格与PC平台上的regedit的风格类似。大家可以去找来参考!
(1)RegClass.h的内容:
 1 #ifndef GSMPHONE_REG_H
 2 #define GSMPHONE_REG_H
 3 #include "wtypes.h"
 4 class CRegOp  
 5 {
 6 public:
 7     BOOL DeleteKey(LPCTSTR szName);
 8     BOOL DeleteValue(LPCTSTR szName);
 9     BOOL SetMultiSZ(LPCTSTR szName, LPCTSTR lpszValue, DWORD dwLen);
10     BOOL SetBinary(LPCTSTR szName, LPBYTE lpbValue, DWORD dwLen);
11     BOOL SetDW(LPCTSTR szName, DWORD dwValue);
12     BOOL SetSZ(LPCTSTR szName, LPCTSTR szValue);
13     BOOL SetSZ(LPCTSTR szName, LPCTSTR szValue, DWORD dwLen);
14     DWORD GetValueDW(LPCTSTR szName, DWORD dwDefault=0);
15     LPCTSTR GetValueSZ(LPCTSTR szName);
16     LPBYTE GetValueBinary(LPCTSTR szName);
17     DWORD GetValueBinary(LPCTSTR szName, LPBYTE lpbValue, DWORD dwLen);
18     BOOL GetValueSZ(LPCTSTR szName, LPTSTR szValue, DWORD dwLen);
19     BOOL EnumValue(LPTSTR pszName, DWORD dwLenName, LPTSTR pszValue, DWORD dwLenValue);
20     BOOL EnumKey(LPTSTR psz, DWORD dwLen);
21     BOOL IsOK();
22     operator HKEY();
23     void Reset();
24     CRegOp(HKEY hkRoot, LPCTSTR pszKey);
25     BOOL Open(HKEY hkRoot, LPCTSTR pszKey, REGSAM sam=KEY_READ);
26     BOOL Create(HKEY hkRoot, LPCTSTR pszKey);
27     CRegOp();
28     virtual ~CRegOp();
29 private:
30     HKEY m_hKey;
31     int m_Index;
32     LPBYTE m_lpbValue; // last value read, if any
33 };
34 #endif //#ifndef GSMPHONE_REG_H

(2)RegClass.cpp的内容:

  1 #include "stdafx.h"
  2 #include "RegClass.h"
  3 //=======================================================================
  4 //Macro define
  5 #define MyFree(p)    { /
  6     if(p) LocalFree(p);/
  7     }
  8 //=======================================================================
  9 /**///////////////////////////////////////////////////////////////////////
 10 // Construction/Destruction
 11 /**///////////////////////////////////////////////////////////////////////
 12 CRegOp::CRegOp()
 13 {
 14     m_hKey = NULL;
 15     m_Index = 0;
 16     m_lpbValue = NULL;
 17 }
 18 CRegOp::CRegOp(HKEY hkRoot, LPCTSTR pszKey)
 19 {
 20     m_hKey = NULL;
 21     m_Index = 0;
 22     m_lpbValue = NULL;
 23     Open(hkRoot,pszKey);
 24 }
 25 CRegOp::~CRegOp()
 26 {
 27     if(m_hKey)
 28     {
 29         RegCloseKey(m_hKey);
 30     }
 31     MyFree(m_lpbValue);
 32 }
 33 //-------------------------------------------------------------------
 34 //Description:
 35 //    Create the key
 36 //-------------------------------------------------------------------
 37 BOOL CRegOp::Create(HKEY hkRoot,LPCTSTR pszKey)
 38 {
 39     DWORD dwDisp;
 40     return ERROR_SUCCESS == RegCreateKeyEx(hkRoot,pszKey,0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&m_hKey,&dwDisp);
 41 }
 42 //-------------------------------------------------------------------
 43 //Description:
 44 //    Open the key
 45 //-------------------------------------------------------------------
 46 BOOL CRegOp::Open(HKEY hkRoot,LPCTSTR pszKey,REGSAM sam)
 47 {
 48     return ERROR_SUCCESS == RegOpenKeyEx(hkRoot,pszKey,0,sam,&m_hKey);
 49 }
 50 //-------------------------------------------------------------------
 51 //Description:
 52 //    Reset the value
 53 //-------------------------------------------------------------------
 54 void CRegOp::Reset()
 55 {
 56     if(m_hKey)
 57     {
 58         RegCloseKey(m_hKey); 
 59     }
 60     MyFree(m_lpbValue);
 61     m_hKey = NULL;
 62     m_Index = 0;
 63     m_lpbValue = NULL;
 64 }
 65 //-------------------------------------------------------------------
 66 //Description:
 67 //    Operator overload
 68 //-------------------------------------------------------------------
 69 CRegOp::operator HKEY()
 70 {
 71     return m_hKey;
 72 }
 73 //-------------------------------------------------------------------
 74 //Description:
 75 //    Test whether is the handle of the key OK for next operate
 76 //-------------------------------------------------------------------
 77 BOOL CRegOp::IsOK()
 78 {
 79     return m_hKey != NULL;
 80 }
 81 
 82 //-------------------------------------------------------------------
 83 //Description:
 84 //    Enum the key
 85 //-------------------------------------------------------------------
 86 BOOL CRegOp::EnumKey(LPTSTR psz,DWORD dwLen)
 87 {
 88     if(!m_hKey)
 89     {
 90         return FALSE;
 91     }
 92     
 93     return ERROR_SUCCESS == RegEnumKeyEx(m_hKey,m_Index++,psz,&dwLen,NULL,NULL,NULL,NULL);
 94 }
 95 //-------------------------------------------------------------------
 96 //Description:
 97 //    Enum registry Value
 98 //-------------------------------------------------------------------
 99 BOOL CRegOp::EnumValue(LPTSTR pszName,DWORD dwLenName,LPTSTR pszValue,DWORD dwLenValue)
100 {
101     DWORD dwType;
102     if(!m_hKey) 
103     {
104         return FALSE;
105     }
106     
107     dwLenValue *= sizeof(TCHAR); // convert length in chars to bytes
108     
109     return ERROR_SUCCESS == RegEnumValue(m_hKey,m_Index++,pszName,&dwLenName,NULL,&dwType,(LPBYTE)pszValue,&dwLenValue);
110 }
111 //-------------------------------------------------------------------
112 //Description:
113 //    Get the string value
114 //-------------------------------------------------------------------
115 BOOL CRegOp::GetValueSZ(LPCTSTR szName,LPTSTR szValue,DWORD dwLen)
116 {
117     if(!m_hKey)
118     {
119         return FALSE;
120     }
121     
122     dwLen *= sizeof(TCHAR); // convert length in chars to bytes
123     
124     return ERROR_SUCCESS == RegQueryValueEx(m_hKey,szName,NULL,NULL,(LPBYTE)szValue,&dwLen);
125 }
126 //-------------------------------------------------------------------
127 //Description:
128 //    Get the binary value
129 //-------------------------------------------------------------------
130 DWORD CRegOp::GetValueBinary(LPCTSTR szName,LPBYTE lpbValue,DWORD dwLen)
131 {
132     if(!m_hKey) 
133     {
134         return FALSE;
135     }
136     DWORD dwLenWant = dwLen;
137     if(ERROR_SUCCESS == RegQueryValueEx(m_hKey,szName,NULL,NULL,lpbValue,&dwLen))
138     {
139         return dwLen;
140     }
141     else
142     {
143         return 0;
144     }
145 }
146 
147 //-------------------------------------------------------------------
148 //Description:
149 //    Get the binary value
150 //-------------------------------------------------------------------
151 LPBYTE CRegOp::GetValueBinary(LPCTSTR szName)
152 {
153     return (LPBYTE)GetValueSZ(szName);
154 }
155 
156 //-------------------------------------------------------------------
157 //Description:
158 //    Get the string value
159 //-------------------------------------------------------------------
160 LPCTSTR CRegOp::GetValueSZ(LPCTSTR szName)
161 {
162     return 0;
163 }
164 //-------------------------------------------------------------------
165 //Description:
166 //    Get the DWORD value
167 //
168 //Parameters:
169 //    szName:[in] The value of registry
170 //    dwDefault:[in] The default value return when failed in getting the 
171 //DWORD value.
172 //-------------------------------------------------------------------
173 DWORD CRegOp::GetValueDW(LPCTSTR szName,DWORD dwDefault)
174 {
175     if(!m_hKey) 
176     {
177         return FALSE;
178     }
179     DWORD dwValue = dwDefault;
180     DWORD dwLen = sizeof(DWORD);
181     RegQueryValueEx(m_hKey,szName,NULL,NULL,(LPBYTE)&dwValue,&dwLen);
182     return dwValue;
183 }
184 //-------------------------------------------------------------------
185 //Description:
186 //    Set the string value
187 //-------------------------------------------------------------------
188 BOOL CRegOp::SetSZ(LPCTSTR szName,LPCTSTR szValue,DWORD dwLen)
189 {
190     //Prefix
191     if(!m_hKey) 
192     {
193         return FALSE;
194     }
195     
196     return ERROR_SUCCESS == RegSetValueEx(m_hKey,szName,0,REG_SZ,(LPBYTE)szValue,sizeof(TCHAR)*dwLen);
197 }
198 
199 //-------------------------------------------------------------------
200 //Description:
201 //    Set the string value
202 //-------------------------------------------------------------------
203 BOOL CRegOp::SetSZ(LPCTSTR szName, LPCTSTR szValue)
204 {
205     return SetSZ(szName, szValue, 1+lstrlen(szValue));
206 }
207 
208 //-------------------------------------------------------------------
209 //Description:
210 //    Get the DWORD value
211 //-------------------------------------------------------------------
212 BOOL CRegOp::SetDW(LPCTSTR szName, DWORD dwValue)
213 {
214     //Prefix
215     if(!m_hKey) 
216     {
217         return FALSE;
218     }
219     
220     return ERROR_SUCCESS==RegSetValueEx(m_hKey, szName, 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(DWORD));
221 }
222 
223 //-------------------------------------------------------------------
224 //Description:
225 //    Get the binary value
226 //-------------------------------------------------------------------
227 BOOL CRegOp::SetBinary(LPCTSTR szName, LPBYTE lpbValue, DWORD dwLen)
228 {
229     //Prefix
230     if(!m_hKey) 
231     {
232         return FALSE;
233     }
234     return ERROR_SUCCESS == RegSetValueEx(m_hKey, szName, 0, REG_BINARY, lpbValue, dwLen);
235 }
236 
237 //-------------------------------------------------------------------
238 //Description:
239 //    Set the Multi value
240 //-------------------------------------------------------------------
241 BOOL CRegOp::SetMultiSZ(LPCTSTR szName, LPCTSTR lpszValue, DWORD dwLen)
242 {
243     return ERROR_SUCCESS == RegSetValueEx(m_hKey, szName, 0, REG_MULTI_SZ, (LPBYTE)lpszValue, sizeof(TCHAR)*dwLen);
244 }
245 
246 //-------------------------------------------------------------------
247 //Description:
248 //    Delete the value
249 //-------------------------------------------------------------------
250 BOOL CRegOp::DeleteValue(LPCTSTR szName)
251 {
252     //Prefix
253     if(!m_hKey) 
254     {
255         return FALSE;
256     }
257     //
258     return ERROR_SUCCESS == RegDeleteValue(m_hKey, szName);
259 }
260  
261 //-------------------------------------------------------------------
262 //Description:
263 //    Delete Key
264 //-------------------------------------------------------------------
265 BOOL CRegOp::DeleteKey(LPCTSTR szName)
266 {
267     if(!m_hKey) 
268     {
269         return FALSE;
270     }
271     
272     return ERROR_SUCCESS == RegDeleteKey(m_hKey, szName);
273 }

 

posted @ 2016-03-08 21:09  91program  阅读(419)  评论(0编辑  收藏  举报