WIN32汇编语言教程:第15章 注册表和INI文件 · 15.3 对注册表的操作(3)

                             EM_REPLACESEL,0,addr @szBuffer1

                     inc    @dwIndex

              .endw

             invoke RegCloseKey,@hKey

      .endif

;********************************************************************

; 枚举键值

;********************************************************************

      mov @dwIndex,0

      invoke RegOpenKeyEx,HKEY_LOCAL_MACHINE,_lpKey,NULL,\

             KEY_QUERY_VALUE,addr @hKey

      .if eax == ERROR_SUCCESS

             .while TRUE

                     mov    @dwSize,sizeof @szBuffer

                     mov    @dwSize1,sizeof @szValue

                    invoke RegEnumValue,@hKey,@dwIndex,addr @szBuffer,\

                               addr @dwSize,NULL,addr @dwType,\

                                addr @szValue,addr @dwSize1

                     .break .if eax == ERROR_NO_MORE_ITEMS

                     mov    eax,@dwType

                     .if    eax == REG_SZ

                             invoke wsprintf,addr @szBuffer1,\

                             addr szFmtSz,addr @szBuffer,addr @szValue

                     .elseif eax == REG_DWORD

                             invoke wsprintf,addr @szBuffer1,\

                                     addr szFmtDw,addr @szBuffer,\

                                     dword ptr @szValue

                             .else

                             invoke wsprintf,addr @szBuffer1,\

                                     addr szFmtValue,addr @szBuffer

                     .endif

                     invoke SendDlgItemMessage,hWinMain,IDC_KEYLIST,\

                             EM_REPLACESEL,0,addr @szBuffer1

                     inc @dwIndex

             .endw

             invoke RegCloseKey,@hKey

      .endif

      ret

 

_EnumKey      endp

;####################################################################

_ProcDlgMain      proc   uses ebx edi esi hWnd,wMsg,wParam,lParam

                local  @szKey[256]:byte,@szSubkey[256]:byte

                local  @szValueName[256]:byte,@szValue[256]:byte

                 local  @dwType,@dwSize

 

                mov    eax,wMsg

;********************************************************************

                .if    eax == WM_CLOSE

                       invoke EndDialog,hWnd,NULL

;********************************************************************

                .elseif eax == WM_INITDIALOG

                       push      hWnd

                        pop    hWinMain

                        invoke LoadIcon,hInstance,ICO_MAIN

                        invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax

                       invoke SendDlgItemMessage,hWnd,IDC_TYPE,\

                               CB_ADDSTRING,0,addr szTypeSz

                       invoke SendDlgItemMessage,hWnd,IDC_TYPE,\

                               CB_ADDSTRING,0,addr szTypeDw

                     invoke SendDlgItemMessage,hWnd,\

                             IDC_TYPE,CB_SETCURSEL,0,0

                     invoke _EnumKey,NULL

;********************************************************************

;由于印刷宽度有限,WM_COMMAND消息处理代码的缩进格式有所影响,请读者注意

;********************************************************************

.elseif eax == WM_COMMAND

      invoke GetDlgItemText,hWnd,IDC_KEY,addr @szKey,256

      invoke GetDlgItemText,hWnd,IDC_SUBKEY,addr @szSubkey,256

      invoke GetDlgItemText,hWnd,IDC_VALUENAME,addr @szValueName,256

      mov    eax,wParam

      .if    ax >=  IDC_KEY && ax <= IDC_SUBKEY

             mov    eax,TRUE

             ret

      .elseif ax ==  IDC_REMOVE_VALUE

             invoke _RegDelValue,addr @szKey,addr @szValueName

      .elseif ax ==  IDC_GET_VALUE

;********************************************************************

; 读取键值

;********************************************************************

             mov    @dwSize,sizeof @szValue

             invoke RtlZeroMemory,addr @szValue,@dwSize

             invoke _RegQueryValue,addr @szKey,addr @szValueName,\

                     addr @szValue,addr @dwSize,addr @dwType

             .if    eax == ERROR_SUCCESS

                     mov    eax,@dwType

                     .if    eax == REG_SZ

                             invoke SetDlgItemText,hWnd,\

                                     IDC_VALUE,addr @szValue

                             invoke SendDlgItemMessage,hWnd,\

                                 IDC_TYPE,CB_SETCURSEL,0,0

                     .elseif eax == REG_DWORD

                             invoke SendDlgItemMessage,hWnd,\

                                     IDC_TYPE,CB_SETCURSEL,1,0

                             invoke SetDlgItemInt,hWnd,IDC_VALUE,\

                                     dword ptr @szValue,FALSE

                     .else

                             invoke SetDlgItemText,hWnd,IDC_VALUE,\

                           addr szNotSupport

                     .endif

             .else

                     invoke SetDlgItemText,hWnd,IDC_VALUE,NULL

              .endif

;********************************************************************

; 设置键值

;********************************************************************

      .elseif ax ==  IDC_SET_VALUE

             invoke SendDlgItemMessage,hWnd,IDC_TYPE,CB_GETCURSEL,0,0

             .if    ! eax

                     invoke GetDlgItemText,hWnd,\

                             IDC_VALUE,addr @szValue,256

                     invoke lstrlen,addr @szValue

                     inc eax

                     invoke _RegSetValue,addr @szKey,addr @szValueName,\

                                addr @szValue,REG_SZ,eax

             .else

                     invoke GetDlgItemInt,hWnd,IDC_VALUE,NULL,FALSE

                     mov d  word ptr @szValue,eax

                     invoke _RegSetValue,addr @szKey,addr @szValueName,\

                                 addr @szValue,REG_DWORD,4

             .endif

      .elseif ax ==  IDC_CREATE_SUBKEY

             invoke _RegCreateKey,addr @szKey,addr @szSubkey

      .elseif ax ==  IDC_REMOVE_SUBKEY

             invoke _RegDelSubKey,addr @szKey,addr @szSubkey

      .endif

      invoke _EnumKey,addr @szKey

;********************************************************************

;恢复代码的缩进格式,请读者注意

;********************************************************************                 .else

                         mov eax,FALSE

上页:第15章 注册表和INI文件 · 15.3 对注册表的操作(2) 下页:第15章 注册表和INI文件 · 15.3 对注册表的操作(4)

第15章 注册表和INI文件

版权所有 © 中山市飞娥软件工作室 证书:粤ICP备09170368号