用户操作
[留言]  [发消息]  [加为好友] 
订阅我的博客
XML聚合    FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
linhong34的公告
<a href="http://www.cppblog.com/files/linhong34/简历.rar">简历下载</a><br> <a href="http://www.cppblog.com/files/linhong34/林宏个人简历1.rar">林宏简历下载</a><br> <a href="mailto:linhong34@163.com">如果贵公司需要我,请联系我</a><br> <!-- 时钟 --> <EMBED src=http://www.clocklink.com/Clocks/0001P-Blue.swf?Place=Beijing&amp;TimeZone=CCT width=150 height=150 type=application/x-shockwave-flash wmode="transparent"> <!-- 日历 --> <IFRAME ID='ifm2' WIDTH='180' HEIGHT='190' ALIGN='CENTER' MARGINWIDTH='0' MARGINHEIGHT='0' HSPACE='0' VSPACE='0' FRAMEBORDER='0' SCROLLING='NO' SRC='http://weather.qq.com/inc/ss180.htm'></IFRAME> <!-- QQ在线状态显示 --> <a target=blank href=http://wpa.qq.com/msgrd?V=1&Uin=29751387&Exe=QQ&Site=Simplelife&Menu=yes><img border="0" SRC=http://wpa.qq.com/pa?p=1:29751387:alt="点击发送消息"></a> <!-- google --> <script type="text/javascript"><!-- google_ad_client = "pub-1269003995808546"; google_ad_width = 125; google_ad_height = 125; google_ad_format = "125x125_as_rimg"; google_cpa_choice = "CAAQ4aSdzgEaCByiq1J203ivKM_M93M"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <!-- google --> <script type="text/javascript"><!-- google_ad_client = "pub-1269003995808546"; google_ad_width = 120; google_ad_height = 60; google_ad_format = "120x60_as_rimg"; google_cpa_choice = "CAAQxIjL9gEaCJ9cTLdx2BNRKITT6n4"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <!-- google --> <script type="text/javascript"><!-- google_ad_client = "pub-1269003995808546"; google_ad_width = 120; google_ad_height = 60; google_ad_format = "120x60_as_rimg"; google_cpa_choice = "CAAQy8L8zwEaCDUSP1b6Y2DoKL-_93M"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <!-- google广告 --> <script type="text/javascript"><!-- google_ad_client = "pub-1269003995808546"; google_ad_width = 125; google_ad_height = 125; google_ad_format = "125x125_as"; google_ad_type = "text"; google_ad_channel =""; google_color_border = "336699"; google_color_bg = "FFFFFF"; google_color_link = "0000FF"; google_color_url = "008000"; google_color_text = "000000"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <!-- 计数器 --> <script src="http://www.xcinfo.ha.cn/jsq/default.asp?User=linhong34&Length=9&x=15&y=20&Mode=002"></script>
文章分类
    计算机
    csdn
    msdn
    天空之城
    学校
    桂林电子科技大学
    综合
    网易
    存档

    转载  Windows API一日一练(63)RegOpenKeyEx和RegCreateKeyEx函数 收藏

    由于电脑经常会关闭,或者应用程序也会经常关闭,但有一些参数是经常需要保存。比如当你打开程序,并设置了窗口的大小,想每次打开时都设置窗口为上次打开的大小。这样就需要保存窗口的大小,那么窗口大小的参数保存到那里呢?其实在Windows里最方便的做法,就是保存到注册表里。又比如游戏登录时,总是想保存最后一个登录的用户,那么也需要保存这个用户到注册表里。其实注册表是Windows保存系统配置的数据库,比如不同的语言设置,不同的时区设置,不同的用户登录,不同的权限等等。下面就来学习怎么样使用函数RegOpenKeyEx来打开注册表里的键和用函数RegCreateKeyEx来创建新的键。
     
    函数RegOpenKeyEx和RegCreateKeyEx声明如下:
     
    WINADVAPI
    LONG
    APIENTRY
    RegOpenKeyExA (
        __in HKEY hKey,
        __in_opt LPCSTR lpSubKey,
        __reserved DWORD ulOptions,
        __in REGSAM samDesired,
        __out PHKEY phkResult
        );
    WINADVAPI
    LONG
    APIENTRY
    RegOpenKeyExW (
        __in HKEY hKey,
        __in_opt LPCWSTR lpSubKey,
        __reserved DWORD ulOptions,
        __in REGSAM samDesired,
        __out PHKEY phkResult
        );
    #ifdef UNICODE
    #define RegOpenKeyEx RegOpenKeyExW
    #else
    #define RegOpenKeyEx RegOpenKeyExA
    #endif // !UNICODE
     
     
    WINADVAPI
    LONG
    APIENTRY
    RegCreateKeyExA (
        __in HKEY hKey,
        __in LPCSTR lpSubKey,
        __reserved DWORD Reserved,
        __in_opt LPSTR lpClass,
        __in DWORD dwOptions,
        __in REGSAM samDesired,
        __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
        __out PHKEY phkResult,
        __out_opt LPDWORD lpdwDisposition
        );
    WINADVAPI
    LONG
    APIENTRY
    RegCreateKeyExW (
        __in HKEY hKey,
        __in LPCWSTR lpSubKey,
        __reserved DWORD Reserved,
        __in_opt LPWSTR lpClass,
        __in DWORD dwOptions,
        __in REGSAM samDesired,
        __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
        __out PHKEY phkResult,
        __out_opt LPDWORD lpdwDisposition
        );
    #ifdef UNICODE
    #define RegCreateKeyEx RegCreateKeyExW
    #else
    #define RegCreateKeyEx RegCreateKeyExA
    #endif // !UNICODE
     
    hKey是主键。
    lpSubKey是子键。
    ulOptions是选项。
    samDesired是键的操作。
    phkResult是打开的键返回。
    lpClass是新键值。
     
    调用函数的例子如下:
    #001 //打注册表。HKEY_CURRENT_USER\"Software"\"Wincpp"\"testreg"
    #002  //蔡军生 2007/11/02 QQ:9073204 深圳
    #003  HKEY GetAppRegistryKey(void)
    #004  {
    #005         HKEY hAppKey = NULL;
    #006         HKEY hSoftKey = NULL;
    #007         HKEY hCompanyKey = NULL;
    #008
    #009         //打开HKEY_CURRENT_USER\"Software"。
    #010        if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("software"), 0, KEY_WRITE|KEY_READ,
    #011              &hSoftKey) == ERROR_SUCCESS)
    #012         {
    #013               DWORD dw;
    #014               //创建并打开HKEY_CURRENT_USER\"Software"\"Wincpp"
    #015              if (RegCreateKeyEx(hSoftKey, _T("Wincpp"), 0, REG_NONE,
    #016                   REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
    #017                   &hCompanyKey, &dw) == ERROR_SUCCESS)
    #018               {
    #019                    //创建并打开HKEY_CURRENT_USER\"Software"\"Wincpp"\"testreg"
    #020                    RegCreateKeyEx(hCompanyKey, _T("testreg"), 0, REG_NONE,
    #021                          REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
    #022                          &hAppKey, &dw);
    #023               }
    #024         }
    #025
    #026         //关闭打开的键值。
    #027         if (hSoftKey != NULL)
    #028         {
    #029               RegCloseKey(hSoftKey);
    #030         }   
    #031
    #032         if (hCompanyKey != NULL)
    #033         {
    #034               RegCloseKey(hCompanyKey);
    #035         }   
    #036
    #037         return hAppKey;
    #038  } 

    发表于 @ 2008年04月17日 13:07:00 | 评论( loading... ) | 编辑| 举报| 收藏

    旧一篇:Windows API一日一练(62)GetDiskFreeSpaceEx函数 | 新一篇:Windows API一日一练(64) RegSetValueEx和RegDeleteValue函数

    • 发表评论
    • 评论内容:
    •  
    Copyright © linhong34
    Powered by CSDN Blog