Solved

Reading form the registry (binary code)

Posted on 1998-12-16
6
594 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
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 100 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now