How to launch the Display, Appearance, Effects window from VB programmatically

Posted on 2006-06-04
Last Modified: 2012-06-27
I need to check if a XP user has Smooth Edges of Screen Fonts/ClearType selected and if not, give them the option to change it. I check this by looking at the following DWORD value:

      HKCU\Control Panel\Desktop - "FontSmoothingType"    

Where 0=No Font Smoothing, 1=Standard and 2=ClearType

I can change this via the registry, but it doesn't apply until after reboot. If you use the display applet, it takes effect immediately.

The display properties window with the appearance tab selected can be launched with the following command:

      RUNDLL32.EXE SHELL32.DLL,Control_RunDLL desk.cpl,,2

How can I programmatically open the Effects window that opens when you click on it's button?

How can I change this setting via the registry, and apply it without a reboot like the applet does?
Question by:dbalman
    LVL 23

    Expert Comment

    A hack solution would be to open that window programatically, like you say, with:

    RUNDLL32.EXE SHELL32.DLL,Control_RunDLL desk.cpl,,2

    And then use "SendKeys" to manipulate the UI.

    Like I said, this is a hack solution, someone may come up with something more elegant.
    LVL 23

    Expert Comment

    Here's an example foundation of such a hack solution - copy the code below to an empty text file, save it as "whatever.wsf" and run it.

       <job id="vbs">
          <script language="VBScript">
             set WshShell = WScript.CreateObject("WScript.Shell")
             WshShell.Run "RUNDLL32.EXE SHELL32.DLL,Control_RunDLL desk.cpl,,2"
             WScript.Sleep 500
             WshShell.SendKeys "^{TAB}"
           WScript.Sleep 100
             WshShell.SendKeys "{TAB}"
           WScript.Sleep 100
             WshShell.SendKeys "{TAB}"
           WScript.Sleep 100
             WshShell.SendKeys "{TAB}"
           WScript.Sleep 100
             WshShell.SendKeys "~"
    LVL 4

    Expert Comment

    You need to SendMessage,HWND_BROADCAST,WM_FONTCHANGE.  I believe this will update without the re-boot.

    Regards,  P1 8-)

    Author Comment

    Thanks for the suggestions. While the "Hacks" would work, it's not what I'm lookin for. P1 has come the closest with the API call however, I was unable to make this work on XP durning testing using a registry import:

                       [HKEY_CURRENT_USER\Control Panel\Desktop]

    to first change the settings via the registry. Then in VB:

        Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
        (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

        Private Const HWND_BROADCAST = &HFFFF&
        Private Const WM_FONTCHANGE = &H1D

      Private Sub Command1_Click()
        SendMessage HWND_BROADCAST, WM_FONTCHANGE, 0, 0
      End Sub

    This would be one of two possible solutions I would find acceptable (and the best) if I could get it to work.

    LVL 29

    Expert Comment

    You need to use SystemParametersInfo API and the following apply to what you are trying to accomplish.

    Look under Desktop parameter Section at the following link


    LVL 29

    Accepted Solution

    I wrote an quick example for you. Paste into form

    Option Explicit

    Private Const SPI_GETFONTSMOOTHING          As Long = 74
    Private Const SPI_SETFONTSMOOTHING          As Long = 75

    Private Const SPI_GETFONTSMOOTHINGTYPE      As Long = 8202
    Private Const SPI_SETFONTSMOOTHINGTYPE      As Long = 8203

    Private Const SPIF_SENDWININICHANGE         As Long = 2
    Private Const SPIF_UPDATEINIFILE            As Long = &H1

    Public Enum SmoothingOptions
        STANDARD = &H1
        CLEARTYPE = &H2
    End Enum

    Private Declare Function SystemParametersInfoA Lib "user32" ( _
        ByVal uAction As Long, _
        ByVal uiParam As Long, _
        ByVal pvParam As Long, _
        ByVal fuWinIni As Long) As Long

    Public Sub SetFontSmoothing(Settings As SmoothingOptions)

        Dim arg As Long
        'First you must enable font smoothing.
        arg = SystemParametersInfoA(SPI_SETFONTSMOOTHING, True, 0, 0)
        ' Then you may change to Standard or ClearType
        arg = SystemParametersInfoA( _
                SPI_SETFONTSMOOTHINGTYPE, 0, Settings, _
                SPIF_SENDWININICHANGE Or _
    End Sub

    Private Sub Command1_Click()
        SetFontSmoothing STANDARD
    End Sub

    Author Comment

    EXCELLANT!!! - but I get a ByRef argument mismatch when I use the ClearType argument - Standard works great.
    I was unable to figure out what was wrong - any ideas?
    LVL 29

    Expert Comment

    Hmmm... I don't seem to get the error. Maybe you should try to create dummy project to make sure. If you added my code above to your existing project than it could be something else conflicting.

    New project
    Add command button to form1
    Copy paste the above code from previous post into Form1

    Author Comment

    You are right of course, I'll figure this out later. Thank you very much for you help.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now