最近新项目要上线,时间真的成了问题,忙里偷闲上来发一篇日志,推荐一下 6droom 的一些新功能,顺便也记下一些开发中的心得 ... 具体的信息可以查看以下页面(
http://www.6droom.com/docs/), 其中最实用的功能应该算是我自己弄得一个 FireFox 和 IE6 / IE7 的扩展,这两个小插件可以帮大家更方便的搜索你想要搜索的东西(一个右键就搞定了,嘿嘿),大家不妨试试看,一定会满意的:)其中 IE 的扩展中我用到了一个操作 Windows 注册表的类,贴上来给大家共享一下吧,还不错,简单实用:
CRegKey.h :
#include
<
windows.h
>
#include < winreg.h >
using namespace std;
class CRegisterKey
{
public:
CRegisterKey();
virtual ~CRegisterKey();
public:
LONG Read(LPCTSTR pszKey , BYTE *pData , DWORD & dwLength);
LONG Read(LPCTSTR pszKey, string &sVal);
LONG Read(LPCTSTR pszKey , DWORD & dwVal);
LONG Write(LPCTSTR pszKey , const BYTE *pData , DWORD dwLength);
LONG Write(LPCTSTR pszKey , LPCTSTR pszVal);
LONG Write(LPCTSTR pszKey , DWORD dwVal);
void Close();
LONG Open(HKEY hKeyRoot , LPCTSTR pszPath , REGSAM dwAccess = KEY_ALL_ACCESS);
protected:
string m_sPath;
HKEY m_hKey;
} ;
#include < winreg.h >
using namespace std;
class CRegisterKey
{
public:
CRegisterKey();
virtual ~CRegisterKey();
public:
LONG Read(LPCTSTR pszKey , BYTE *pData , DWORD & dwLength);
LONG Read(LPCTSTR pszKey, string &sVal);
LONG Read(LPCTSTR pszKey , DWORD & dwVal);
LONG Write(LPCTSTR pszKey , const BYTE *pData , DWORD dwLength);
LONG Write(LPCTSTR pszKey , LPCTSTR pszVal);
LONG Write(LPCTSTR pszKey , DWORD dwVal);
void Close();
LONG Open(HKEY hKeyRoot , LPCTSTR pszPath , REGSAM dwAccess = KEY_ALL_ACCESS);
protected:
string m_sPath;
HKEY m_hKey;
} ;
CRegKey.cpp
#include
"
CRegKey.h
"
//
// Construction/Destruction
//
CRegisterKey::CRegisterKey()
{
m_hKey = NULL;
}
CRegisterKey:: ~ CRegisterKey()
{
Close();
}
LONG CRegisterKey::Open(HKEY hKeyRoot, LPCTSTR pszPath , REGSAM dwAccess)
{
DWORD dw;
m_sPath = pszPath;
return RegCreateKeyEx(hKeyRoot , pszPath , 0L , NULL , REG_OPTION_NON_VOLATILE ,
dwAccess , NULL , &m_hKey , &dw);
}
void CRegisterKey::Close()
{
if(m_hKey)
{
RegCloseKey(m_hKey);
m_hKey = NULL;
}
}
LONG CRegisterKey::Write(LPCTSTR pszKey, DWORD dwVal)
{
ASSERT(m_hKey);
ASSERT(pszKey);
return RegSetValueEx(m_hKey , pszKey , 0L , REG_DWORD , (CONST BYTE *) &dwVal ,
sizeof(DWORD));
}
LONG CRegisterKey::Write(LPCTSTR pszKey, LPCTSTR pszVal)
{
ASSERT(m_hKey);
ASSERT(pszKey);
ASSERT(pszVal);
ASSERT(AfxIsValidAddress(pszVal , strlen(pszVal) , FALSE));
return RegSetValueEx(m_hKey , pszKey , 0L , REG_SZ , (CONST BYTE *) pszVal ,
strlen(pszVal)+1);
}
LONG CRegisterKey::Write(LPCTSTR pszKey, const BYTE * pData, DWORD dwLength)
{
ASSERT(m_hKey);
ASSERT(pszKey);
ASSERT(pData && dwLength>0);
ASSERT(AfxIsValidAddress(pData , dwLength , FALSE));
return RegSetValueEx(m_hKey , pszKey , 0L , REG_BINARY , pData , dwLength);
}
LONG CRegisterKey::Read(LPCTSTR pszKey, DWORD & dwVal)
{
ASSERT(m_hKey);
ASSERT(pszKey);
DWORD dwType;
DWORD dwSize = sizeof(DWORD);
DWORD dwDest;
LONG lRet = RegQueryValueEx(m_hKey , pszKey , NULL , &dwType , (LPBYTE) &dwDest , &dwSize);
if(lRet == ERROR_SUCCESS)
dwVal = dwDest;
return lRet;
}
LONG CRegisterKey::Read(LPCTSTR pszKey, string & sVal)
{
ASSERT(m_hKey);
ASSERT(pszKey);
DWORD dwType;
DWORD dwSize = 512;
char string[512];
LONG lRet = RegQueryValueEx(m_hKey , pszKey , NULL , &dwType , (LPBYTE) string , &dwSize);
if(lRet == ERROR_SUCCESS)
sVal = string;
return lRet;
}
LONG CRegisterKey::Read(LPCTSTR pszKey, BYTE * pData, DWORD & dwLength)
{
ASSERT(m_hKey);
ASSERT(pszKey);
DWORD dwType;
return RegQueryValueEx(m_hKey , pszKey , NULL , &dwType , pData , &dwLength);
}
//
// Construction/Destruction
//
CRegisterKey::CRegisterKey()
{
m_hKey = NULL;
}
CRegisterKey:: ~ CRegisterKey()
{
Close();
}
LONG CRegisterKey::Open(HKEY hKeyRoot, LPCTSTR pszPath , REGSAM dwAccess)
{
DWORD dw;
m_sPath = pszPath;
return RegCreateKeyEx(hKeyRoot , pszPath , 0L , NULL , REG_OPTION_NON_VOLATILE ,
dwAccess , NULL , &m_hKey , &dw);
}
void CRegisterKey::Close()
{
if(m_hKey)
{
RegCloseKey(m_hKey);
m_hKey = NULL;
}
}
LONG CRegisterKey::Write(LPCTSTR pszKey, DWORD dwVal)
{
ASSERT(m_hKey);
ASSERT(pszKey);
return RegSetValueEx(m_hKey , pszKey , 0L , REG_DWORD , (CONST BYTE *) &dwVal ,
sizeof(DWORD));
}
LONG CRegisterKey::Write(LPCTSTR pszKey, LPCTSTR pszVal)
{
ASSERT(m_hKey);
ASSERT(pszKey);
ASSERT(pszVal);
ASSERT(AfxIsValidAddress(pszVal , strlen(pszVal) , FALSE));
return RegSetValueEx(m_hKey , pszKey , 0L , REG_SZ , (CONST BYTE *) pszVal ,
strlen(pszVal)+1);
}
LONG CRegisterKey::Write(LPCTSTR pszKey, const BYTE * pData, DWORD dwLength)
{
ASSERT(m_hKey);
ASSERT(pszKey);
ASSERT(pData && dwLength>0);
ASSERT(AfxIsValidAddress(pData , dwLength , FALSE));
return RegSetValueEx(m_hKey , pszKey , 0L , REG_BINARY , pData , dwLength);
}
LONG CRegisterKey::Read(LPCTSTR pszKey, DWORD & dwVal)
{
ASSERT(m_hKey);
ASSERT(pszKey);
DWORD dwType;
DWORD dwSize = sizeof(DWORD);
DWORD dwDest;
LONG lRet = RegQueryValueEx(m_hKey , pszKey , NULL , &dwType , (LPBYTE) &dwDest , &dwSize);
if(lRet == ERROR_SUCCESS)
dwVal = dwDest;
return lRet;
}
LONG CRegisterKey::Read(LPCTSTR pszKey, string & sVal)
{
ASSERT(m_hKey);
ASSERT(pszKey);
DWORD dwType;
DWORD dwSize = 512;
char string[512];
LONG lRet = RegQueryValueEx(m_hKey , pszKey , NULL , &dwType , (LPBYTE) string , &dwSize);
if(lRet == ERROR_SUCCESS)
sVal = string;
return lRet;
}
LONG CRegisterKey::Read(LPCTSTR pszKey, BYTE * pData, DWORD & dwLength)
{
ASSERT(m_hKey);
ASSERT(pszKey);
DWORD dwType;
return RegQueryValueEx(m_hKey , pszKey , NULL , &dwType , pData , &dwLength);
}
然后是 MingW 的生成 Windows 应用的用法:
gcc -c window.c
gcc -o window window.o -mwindows
第一步生成 Link 要用的 window.o 文件,第二步生成 window.exe 应用程序:)