?
Solved

Reading form the registry (binary code)

Posted on 1998-12-16
6
Medium Priority
?
612 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

762 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