[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

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

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?
0
dbalman
Asked:
dbalman
  • 3
  • 3
  • 2
  • +1
1 Solution
 
basicinstinctCommented:
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.
0
 
basicinstinctCommented:
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.

<package>
   <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 "~"
      </script>
   </job>
</package>
0
 
P1Commented:
You need to SendMessage,HWND_BROADCAST,WM_FONTCHANGE.  I believe this will update without the re-boot.

Regards,  P1 8-)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dbalmanAuthor Commented:
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]
                   "FontSmoothing"="2"
                   "FontSmoothingOrientation"=dword:00000001
                   "FontSmoothingType"=dword:00000002

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.

0
 
nffvrxqgrcfqvvcCommented:
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
http://msdn.microsoft.com/library/en-us/sysinfo/base/systemparametersinfo.asp

SPI_GETFONTSMOOTHING
SPI_GETFONTSMOOTHINGCONTRAST
SPI_GETFONTSMOOTHINGTYPE

SPI_SETFONTSMOOTHING
SPI_SETFONTSMOOTHINGCONTRAST
SPI_SETFONTSMOOTHINGTYPE
0
 
nffvrxqgrcfqvvcCommented:
I wrote an quick example for you. Paste into form


Option Explicit

'uAction
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

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

'pvParam
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 _
            SPIF_UPDATEINIFILE)
   
End Sub

Private Sub Command1_Click()
    SetFontSmoothing STANDARD
End Sub
0
 
dbalmanAuthor Commented:
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?
0
 
nffvrxqgrcfqvvcCommented:
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
0
 
dbalmanAuthor Commented:
You are right of course, I'll figure this out later. Thank you very much for you help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now