?
Solved

Reading form the registry (binary code)

Posted on 1998-12-16
6
Medium Priority
?
620 Views
Last Modified: 2012-05-04
There's a problem when reading form the system registry.
RegQueryValueEx API does not seem to be working with
the non-string values (for example with
ActiveWindowFontName) or i'm not able to read (convert)
the querried value into the String. Please help.
0
Comment
Question by:ABE2276
  • 4
  • 2
6 Comments
 
LVL 12

Expert Comment

by:Trygve
ID: 1971183
I would like to help, but I can't seem to find ActiveWindowFontName in my registry. Neither could I find any information about it on Microsofts development CDs. Could you tell me where I may find it and what the typical value you want returned looks like ?
0
 

Author Comment

by:ABE2276
ID: 1971184
You've to look for
HKEY_CURRENT_USER\Control Panel\desktop\WindowMetrics\CaptionFont
in your registry.

Thanks for answering :)
0
 
LVL 12

Expert Comment

by:Trygve
ID: 1971185
Try this:
Copy and paste into a module. Note that you might get duplicate declaration since you already have done some API programming. The function can be expanded to include other parameters, but this is what I had the time to do for now.

From the debug window in my app.

print getwindowssystemfont("Caption","Name")
returns...
MS Sans Serif


    Global Const HKEY_CLASSES_ROOT = &H80000000
    Global Const HKEY_CURRENT_USER = &H80000001
    Global Const HKEY_LOCAL_MACHINE = &H80000002
    Global Const HKEY_USERS = &H80000003
    Global Const HKEY_CURRENT_CONFIG As Long = &H80000005

    Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
        "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
        ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As _
        Long) As Long
   
    Private Declare Function RegQueryValueEx Lib "advapi32.dll" _
        Alias "RegQueryValueExA" _
        (ByVal hKey As Long, ByVal lpValueName As String, _
        ByVal lpReserved As Long, lpType As Long, lpData As Any, _
        lpcbData As Long) As Long
       
    Declare Function RegCloseKey Lib "advapi32.dll" _
        (ByVal hKey As Long) As Long

Function GetWindowsSystemFont(FontType As String, Parameter As String) As String

    Dim temp As String
    Dim Ind As Integer

    Select Case FontType
        Case "Caption"
            temp = RegGetString$(HKEY_CURRENT_USER, "Control Panel\desktop\WindowMetrics", "CaptionFont")
        Case "Icon"
            temp = RegGetString$(HKEY_CURRENT_USER, "Control Panel\desktop\WindowMetrics", "IconFont")
        Case "Menu"
            temp = RegGetString$(HKEY_CURRENT_USER, "Control Panel\desktop\WindowMetrics", "MenuFont")
        Case "Message"
            temp = RegGetString$(HKEY_CURRENT_USER, "Control Panel\desktop\WindowMetrics", "MessageFont")
        Case "SmCaption"
            temp = RegGetString$(HKEY_CURRENT_USER, "Control Panel\desktop\WindowMetrics", "SmCaptionFont")
        Case "Status"
            temp = RegGetString$(HKEY_CURRENT_USER, "Control Panel\desktop\WindowMetrics", "StatusFont")
        Case Else
            ' Return Caption Font
            temp = RegGetString$(HKEY_CURRENT_USER, "Control Panel\desktop\WindowMetrics", "CaptionFont")
    End Select
   
    GetWindowsSystemFont = temp
    Select Case Parameter
        Case "Name"
            'For Ind = 1 To Len(temp)
            '    Debug.Print Ind, Mid(temp, Ind, 1), Asc(Mid(temp, Ind, 1))
            'Next
            GetWindowsSystemFont = Mid(temp, 19, InStr(19, temp, Chr(0)) - 19)
        Case "Size"
            GetWindowsSystemFont = Mid(temp, 41, 1) 'InStr(19, temp, Chr(0)) - 19)
        Case "Color"
        Case "Bold"
        Case "Italic"
        Case Else
            GetWindowsSystemFont = Mid(temp, 19, InStr(19, temp, Chr(0)) - 19)
    End Select
End Function


    Function RegGetString$(hInKey As Long, ByVal subkey$, ByVal valname$)

        Dim RetVal$, hSubKey As Long, dwType As Long, SZ As Long
        Dim v$
        Dim R As Long
        RetVal$ = ""
        Const KEY_ALL_ACCESS As Long = &HF0063
        Const ERROR_SUCCESS As Long = 0
        Const REG_SZ As Long = 1
        R = RegOpenKeyEx(hInKey, subkey$, 0, KEY_ALL_ACCESS, hSubKey)
        If R <> ERROR_SUCCESS Then GoTo Quit_Now
        SZ = 256: v$ = String$(SZ, 0)
        R = RegQueryValueEx(hSubKey, valname$, 0, dwType, ByVal v$, SZ)
        If R = ERROR_SUCCESS And dwType = REG_SZ Then
            RetVal$ = left$(v$, SZ)
        Else
            'RetVal$ = "--Not String--" &
            RetVal$ = left$(v$, SZ)
        End If
        If hInKey = 0 Then R = RegCloseKey(hSubKey)
Quit_Now:
        RegGetString$ = RetVal$
        End Function

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 12

Accepted Solution

by:
Trygve earned 400 total points
ID: 1971186
Ooops, forgot to mark the question "Answered"
0
 

Author Comment

by:ABE2276
ID: 1971187
Dear Sir,

It works excellent, but looks a bit heavy: "goto" is just a hat-trick. Thank You anyway - it realy is a good job.

Best regards,
            ABE

0
 
LVL 12

Expert Comment

by:Trygve
ID: 1971188
You can strip of the parts that you don't need (look in the select case parts of the code. The rest is API stuff. These parts are best programmed by copying from someone elses code :-)

Have a nice day !
Trygve
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question