EVC編程點滴(概述)-註冊表操作類

來源:互聯網
上載者:User

我辭職前,在公司負責在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)IME狀態列的處理
12)日曆演算法
13)拍照功能的實現
14)錄音(WAV)格式
15)GSM AT命令

今天只能想起這麼多了,以後想到再更新。

先說說註冊表操作類,這個類在網上有很多實現的版本。我也在網上找到一個CE下註冊表操作的原始碼,實現風格與PC平台上的regedit的風格類似。大家可以去找來參考!

(1)RegClass.h的內容:
#ifndef GSMPHONE_REG_H
#define GSMPHONE_REG_H

#include "wtypes.h"

class CRegOp 
{
public:
    BOOL DeleteKey(LPCTSTR szName);
    BOOL DeleteValue(LPCTSTR szName);
    BOOL SetMultiSZ(LPCTSTR szName, LPCTSTR lpszValue, DWORD dwLen);
    BOOL SetBinary(LPCTSTR szName, LPBYTE lpbValue, DWORD dwLen);
    BOOL SetDW(LPCTSTR szName, DWORD dwValue);
    BOOL SetSZ(LPCTSTR szName, LPCTSTR szValue);
    BOOL SetSZ(LPCTSTR szName, LPCTSTR szValue, DWORD dwLen);
    DWORD GetValueDW(LPCTSTR szName, DWORD dwDefault=0);
    LPCTSTR GetValueSZ(LPCTSTR szName);
    LPBYTE GetValueBinary(LPCTSTR szName);
    DWORD GetValueBinary(LPCTSTR szName, LPBYTE lpbValue, DWORD dwLen);
    BOOL GetValueSZ(LPCTSTR szName, LPTSTR szValue, DWORD dwLen);
    BOOL EnumValue(LPTSTR pszName, DWORD dwLenName, LPTSTR pszValue, DWORD dwLenValue);
    BOOL EnumKey(LPTSTR psz, DWORD dwLen);
    BOOL IsOK();
    operator HKEY();
    void Reset();
    CRegOp(HKEY hkRoot, LPCTSTR pszKey);
    BOOL Open(HKEY hkRoot, LPCTSTR pszKey, REGSAM sam=KEY_READ);
    BOOL Create(HKEY hkRoot, LPCTSTR pszKey);
    CRegOp();
    virtual ~CRegOp();

private:
    HKEY m_hKey;
    int m_Index;
    LPBYTE m_lpbValue; // last value read, if any
};

#endif //#ifndef GSMPHONE_REG_H

(2)RegClass.cpp的內容:
#include "stdafx.h"
#include "RegClass.h"

//=======================================================================
//Macro define
#define MyFree(p)    { /
    if(p) LocalFree(p);/
    }
//=======================================================================
/**///////////////////////////////////////////////////////////////////////
// Construction/Destruction
/**///////////////////////////////////////////////////////////////////////

CRegOp::CRegOp()
{
    m_hKey = NULL;
    m_Index = 0;
    m_lpbValue = NULL;
}

CRegOp::CRegOp(HKEY hkRoot, LPCTSTR pszKey)
{
    m_hKey = NULL;
    m_Index = 0;
    m_lpbValue = NULL;
    Open(hkRoot,pszKey);
}

CRegOp::~CRegOp()
{
    if(m_hKey)
    {
        RegCloseKey(m_hKey);
    }
    MyFree(m_lpbValue);
}

//-------------------------------------------------------------------
//Description:
//    Create the key
//-------------------------------------------------------------------
BOOL CRegOp::Create(HKEY hkRoot,LPCTSTR pszKey)
{
    DWORD dwDisp;
    return ERROR_SUCCESS == RegCreateKeyEx(hkRoot,pszKey,0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&m_hKey,&dwDisp);
}

//-------------------------------------------------------------------
//Description:
//    Open the key
//-------------------------------------------------------------------
BOOL CRegOp::Open(HKEY hkRoot,LPCTSTR pszKey,REGSAM sam)
{
    return ERROR_SUCCESS == RegOpenKeyEx(hkRoot,pszKey,0,sam,&m_hKey);
}

//-------------------------------------------------------------------
//Description:
//    Reset the value
//-------------------------------------------------------------------
void CRegOp::Reset()
{
    if(m_hKey)
    {
        RegCloseKey(m_hKey);
    }
    MyFree(m_lpbValue);
    m_hKey = NULL;
    m_Index = 0;
    m_lpbValue = NULL;
}

//-------------------------------------------------------------------
//Description:
//    Operator overload
//-------------------------------------------------------------------
CRegOp::operator HKEY()
{
    return m_hKey;
}

//-------------------------------------------------------------------
//Description:
//    Test whether is the handle of the key OK for next operate
//-------------------------------------------------------------------
BOOL CRegOp::IsOK()
{
    return m_hKey != NULL;
}

//-------------------------------------------------------------------
//Description:
//    Enum the key
//-------------------------------------------------------------------
BOOL CRegOp::EnumKey(LPTSTR psz,DWORD dwLen)
{
    if(!m_hKey)
    {
        return FALSE;
    }
   
    return ERROR_SUCCESS == RegEnumKeyEx(m_hKey,m_Index++,psz,&dwLen,NULL,NULL,NULL,NULL);
}

//-------------------------------------------------------------------
//Description:
//    Enum registry Value
//-------------------------------------------------------------------
BOOL CRegOp::EnumValue(LPTSTR pszName,DWORD dwLenName,LPTSTR pszValue,DWORD dwLenValue)
{
    DWORD dwType;

    if(!m_hKey)
    {
        return FALSE;
    }
   
    dwLenValue *= sizeof(TCHAR); // convert length in chars to bytes
   
    return ERROR_SUCCESS == RegEnumValue(m_hKey,m_Index++,pszName,&dwLenName,NULL,&dwType,(LPBYTE)pszValue,&dwLenValue);
}

//-------------------------------------------------------------------
//Description:
//    Get the string value
//-------------------------------------------------------------------
BOOL CRegOp::GetValueSZ(LPCTSTR szName,LPTSTR szValue,DWORD dwLen)
{
    if(!m_hKey)
    {
        return FALSE;
    }
   
    dwLen *= sizeof(TCHAR); // convert length in chars to bytes
   
    return ERROR_SUCCESS == RegQueryValueEx(m_hKey,szName,NULL,NULL,(LPBYTE)szValue,&dwLen);
}

//-------------------------------------------------------------------
//Description:
//    Get the binary value
//-------------------------------------------------------------------
DWORD CRegOp::GetValueBinary(LPCTSTR szName,LPBYTE lpbValue,DWORD dwLen)
{
    if(!m_hKey)
    {
        return FALSE;
    }

    DWORD dwLenWant = dwLen;
    if(ERROR_SUCCESS == RegQueryValueEx(m_hKey,szName,NULL,NULL,lpbValue,&dwLen))
    {
        return dwLen;
    }
    else
    {
        return 0;
    }
}

//-------------------------------------------------------------------
//Description:
//    Get the binary value
//-------------------------------------------------------------------
LPBYTE CRegOp::GetValueBinary(LPCTSTR szName)
{
    return (LPBYTE)GetValueSZ(szName);
}

//-------------------------------------------------------------------
//Description:
//    Get the string value
//-------------------------------------------------------------------
LPCTSTR CRegOp::GetValueSZ(LPCTSTR szName)
{
    return 0;
}

//-------------------------------------------------------------------
//Description:
//    Get the DWORD value
//
//Parameters:
//    szName:[in] The value of registry
//    dwDefault:[in] The default value return when failed in getting the
//DWORD value.
//-------------------------------------------------------------------
DWORD CRegOp::GetValueDW(LPCTSTR szName,DWORD dwDefault)
{
    if(!m_hKey)
    {
        return FALSE;
    }
    DWORD dwValue = dwDefault;
    DWORD dwLen = sizeof(DWORD);
    RegQueryValueEx(m_hKey,szName,NULL,NULL,(LPBYTE)&dwValue,&dwLen);
    return dwValue;
}

//-------------------------------------------------------------------
//Description:
//    Set the string value
//-------------------------------------------------------------------
BOOL CRegOp::SetSZ(LPCTSTR szName,LPCTSTR szValue,DWORD dwLen)
{
    //Prefix
    if(!m_hKey)
    {
        return FALSE;
    }
   
    return ERROR_SUCCESS == RegSetValueEx(m_hKey,szName,0,REG_SZ,(LPBYTE)szValue,sizeof(TCHAR)*dwLen);
}

//-------------------------------------------------------------------
//Description:
//    Set the string value
//-------------------------------------------------------------------
BOOL CRegOp::SetSZ(LPCTSTR szName, LPCTSTR szValue)
{
    return SetSZ(szName, szValue, 1+lstrlen(szValue));
}

//-------------------------------------------------------------------
//Description:
//    Get the DWORD value
//-------------------------------------------------------------------
BOOL CRegOp::SetDW(LPCTSTR szName, DWORD dwValue)
{
    //Prefix
    if(!m_hKey)
    {
        return FALSE;
    }
   
    return ERROR_SUCCESS==RegSetValueEx(m_hKey, szName, 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(DWORD));
}

//-------------------------------------------------------------------
//Description:
//    Get the binary value
//-------------------------------------------------------------------
BOOL CRegOp::SetBinary(LPCTSTR szName, LPBYTE lpbValue, DWORD dwLen)
{
    //Prefix
    if(!m_hKey)
    {
        return FALSE;
    }

    return ERROR_SUCCESS == RegSetValueEx(m_hKey, szName, 0, REG_BINARY, lpbValue, dwLen);
}

//-------------------------------------------------------------------
//Description:
//    Set the Multi value
//-------------------------------------------------------------------
BOOL CRegOp::SetMultiSZ(LPCTSTR szName, LPCTSTR lpszValue, DWORD dwLen)
{
    return ERROR_SUCCESS == RegSetValueEx(m_hKey, szName, 0, REG_MULTI_SZ, (LPBYTE)lpszValue, sizeof(TCHAR)*dwLen);
}

//-------------------------------------------------------------------
//Description:
//    Delete the value
//-------------------------------------------------------------------
BOOL CRegOp::DeleteValue(LPCTSTR szName)
{
    //Prefix
    if(!m_hKey)
    {
        return FALSE;
    }
    //
    return ERROR_SUCCESS == RegDeleteValue(m_hKey, szName);
}

 

//-------------------------------------------------------------------
//Description:
//    Delete Key
//-------------------------------------------------------------------
BOOL CRegOp::DeleteKey(LPCTSTR szName)
{
    if(!m_hKey)
    {
        return FALSE;
    }
   
    return ERROR_SUCCESS == RegDeleteKey(m_hKey, szName);
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.