;========================================================================
; Initiallize program settings from the registry
;========================================================================
Initialize PROC
LOCAL    charF:CHARFORMAT2
LOCAL    hReg:DWORD

      INVOKE     RegOpenKeyEx, HKEY_CURRENT_USER, addr szRedit, 0,\
                 KEY_WRITE or KEY_READ, addr hReg
      .if eax == ERROR_SUCCESS
            jmp     NotFirst
      .endif
      INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, addr szRedit, 0, addr szREGSZ, 0,\
                 KEY_WRITE or KEY_READ, 0, addr hReg, addr lpdwDisp
      .if !eax == ERROR_SUCCESS
; Do message
            jmp     Ret0
      .endif

      INVOKE     SendMessage, hREdit, EM_GETCHARFORMAT, TRUE, addr charF
      INVOKE     lstrlen, addr FontName
         mov     lpcbData, eax
      INVOKE     RegSetValueEx, hReg, addr szFont, 0, REG_SZ, addr FontName, lpcbData
      INVOKE     lstrcpy, addr charF.szFaceName, addr FontName
;      INVOKE     RegSet, addr szMask, 0feffffffh
;      INVOKE     RegSet, addr szEffects, 0

      INVOKE     RegSet, addr szFontH, charF.yHeight
      INVOKE     RegSet, addr szFontW, charF.wWeight
      INVOKE     RegSet, addr szMask, charF.dwMask
      INVOKE     RegSet, addr szEffects, charF.dwEffects
      INVOKE     RegSet, addr szCharSet, charF.bCharSet
      INVOKE     RegSet, addr szPitchFam, charF.bPitchAndFamily
      INVOKE     RegSet, addr szTextColor, TextC
      INVOKE     RegSet, addr szTextBGColor, TextBGC
      INVOKE     RegSet, addr szBackGColor, BackGC

;========================================================================
; Save values to the Registry
;========================================================================
RegSave PROC
LOCAL    rect:RECT
LOCAL    charF:CHARFORMAT2
LOCAL    hReg:DWORD

      INVOKE     RegCreateKeyEx, HKEY_CURRENT_USER, offset szRedit, 0, offset szREGSZ, 0,\
                 KEY_WRITE or KEY_READ, 0, addr hReg, offset lpdwDisp

        call     GetDesktopWindow
      INVOKE     GetWindowRect, eax, addr rect
        push     rect.right
      INVOKE     GetWindowRect, hWnd, addr rect
         pop     eax
         cmp     eax, rect.right
         jle     NoSavePos
      INVOKE     RegSet, offset szLeft, rect.left
      INVOKE     RegSet, offset szRight, rect.right
      INVOKE     RegSet, offset szTop, rect.top
      INVOKE     RegSet, offset szBottom, rect.bottom

NoSavePos:
      INVOKE     SendMessage, hREdit, EM_GETCHARFORMAT, TRUE, addr charF
      INVOKE     lstrlen, addr FontName
         mov     lpcbData, eax
      INVOKE     RegSetValueEx, hReg, offset szFont, 0, REG_SZ,\
                 offset charF.szFaceName, lpcbData
      INVOKE     RegSet, offset szPoint, PointSize ;charF.yHeight
      INVOKE     RegSet, offset szMask, charF.dwMask
      INVOKE     RegSet, offset szEffects, charF.dwEffects

      INVOKE     RegSet, offset rTC, TextC
      INVOKE     RegSet, offset rBC, BackGC

      INVOKE     RegCloseKey, hReg
         ret
RegSave ENDP
