Using Win32 functions in Visual FoxPro Image Gallery
Monitor Configuration (Vista)
Code examples:
How to adjust monitor brightness (Vista, monitor with DDC support)
How to adjust monitor brightness (Vista, monitor with DDC support)

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
The Monitor Configuration API was first made available in Windows Vista. These functions are applicable only if the monitor supports the Display Data Channel (DDC/CI) connection with the graphics adapter.

At least thirteen Monitor Configuration functions exist. Those include GETs and/or SETs for brightness, color temperature, contrast, display area position & size, factory defaults and more. Some models may have limited Monitor Configuration support.

The following code sample includes calls to several Monitor Configuration functions, in particular those reading and changing the brightness of a monitor.

See also:
  • How to change display settings: screen resolution, screen refresh rate
  • How to detect if additional monitor is connected and active
    DO declare
    LOCAL hMonitor, cMonitorName, hPhysMonitor,;
        nPhysMonitorCount, cPhysMonitorArray, nResult
    * find out on which monitor
    * the main VFP window resides
    hMonitor = MonitorFromWindow(_vfp.hWnd,;
    * find out the number of physical monitors
    * associated with the hMonitor handle
    = GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor,;
    IF nPhysMonitorCount = 0
        ? "No physical monitor detected."
    * allocate space for the array
    * of PHYSICAL_MONITOR structures
    cPhysMonitorArray = REPLICATE(CHR(0), 4096)
    * retrieves the physical monitors data
    nResult = GetPhysicalMonitorsFromHMONITOR(hMonitor,;
        nPhysMonitorCount, @cPhysMonitorArray)
    IF nResult = 0
        ? "GetPhysicalMonitorsFromHMONITOR() failed:",;
    * this pseudo-handle starts with 0 and increments
    * for each following physical monitor
    hPhysMonitor = buf2dword(SUBSTR(cPhysMonitorArray, 1,4))
    ? "Physical Monitor handle:", hPhysMonitor
    cMonitorName = SUBSTR(cPhysMonitorArray, 5)
    cMonitorName = SUBSTR(m.cMonitorName, 1,;
        AT(CHR(0)+CHR(0), cMonitorName))
    ? "Monitor name:", STRCONV(cMonitorName,6)
    LOCAL capMonitor, capColorTemp
    STORE 0 TO capMonitor, capColorTemp
    * takes about a second to return
    IF GetMonitorCapabilities(hPhysMonitor,;
        @capMonitor, @capColorTemp) <> 0
        ? "Monitor Cap flags:", capMonitor
        ? "Monitor Color Temp flags:", capColorTemp
    LOCAL minBrightness, curBrightness, maxBrightness
    STORE 0 TO minBrightness, curBrightness, maxBrightness
    * retrieving the brightness value (%) for the monitor
    IF GetMonitorBrightness(hPhysMonitor,;
        @minBrightness, @curBrightness, @maxBrightness) <> 0
        ? "Brightness min, current, max:",;
            minBrightness, curBrightness, maxBrightness
        * setting the brightness
        * uncomment to try
        * = SetMonitorBrightness(hPhysMonitor, 100)
        ? "GetMonitorBrightness() failed:",;
    * this is the must on exit: closes the array of open
    * physical monitor handles
    = DestroyPhysicalMonitors(nPhysMonitorCount,;
    * end of main
    PROCEDURE declare
        DECLARE INTEGER MonitorFromWindow IN user32;
            INTEGER hWindow, INTEGER dwFlags
        DECLARE INTEGER GetLastError IN kernel32
        DECLARE INTEGER GetMonitorCapabilities IN dxva2;
            INTEGER hMonitor, LONG @pdwMonitorCapabilities,;
            LONG @pdwSupportedColorTemperatures
        DECLARE INTEGER GetPhysicalMonitorsFromHMONITOR IN dxva2;
            INTEGER hMonitor, LONG dwPhysicalMonitorArraySize,;
            STRING @pPhysicalMonitorArray
        DECLARE INTEGER GetNumberOfPhysicalMonitorsFromHMONITOR IN dxva2;
            INTEGER hMonitor, LONG @pdwNumberOfPhysicalMonitors
        DECLARE INTEGER DestroyPhysicalMonitors IN dxva2;
            LONG dwPhysicalMonitorArraySize, STRING @pPhysicalMonitorArray
        DECLARE INTEGER GetMonitorBrightness IN dxva2;
            INTEGER hMonitor, LONG @pdwMinimumBrightness,;
            LONG @pdwCurrentBrightness, LONG @pdwMaximumBrightness
        DECLARE INTEGER SetMonitorBrightness IN dxva2;
            INTEGER hMonitor, LONG dwNewBrightness
    FUNCTION buf2dword(cBuffer)
    RETURN Asc(SUBSTR(cBuffer, 1,1)) + ;
        BitLShift(Asc(SUBSTR(cBuffer, 2,1)),  8) +;
        BitLShift(Asc(SUBSTR(cBuffer, 3,1)), 16) +;
        BitLShift(Asc(SUBSTR(cBuffer, 4,1)), 24)

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    3355 bytes  
    Created: 2008-12-10 16:54:43  
    Modified: 2010-12-22 20:45:51  
    Visits in 7 days: 69  
    Listed functions:
    Printer friendly API declarations
    My comment:
    Code sample tested on Vista Business 64-bit SP1. The video card was NVIDIA Quadro FX 570 with two monitors connected: Samsung SyncMaster T240 and VisionQuest VQL-24WSHD.
    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian offers instant, free translations of text or web pages.
    User Contributed Notes:
    There are no notes on this subject.

    Copyright 2001-2018 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.6.39), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (
    12 sec.Function: 'RegQueryValueEx'
    24 sec.Function: 'SetupDiGetClassImageIndex'
    Function group: 'Setup API functions'
    33 sec.Example: 'Creating a unique filename based on existing filename'
    45 sec.
    Function group: 'Cursor'
    56 sec.Function: 'CeRegQueryInfoKey'
    Function group: 'Remote Application Programming (RAPI)'
    1.3 min.Function: 'PrinterProperties'
    Function group: 'Printing and Print Spooler'
    1.48 min.Function: 'FreeLibrary'
    1.62 min.Example: 'GDI+: Implementing image scrolling with inertia'
    1.85 min.Function: 'CeGetTempPath'
    Function group: 'Remote Application Programming (RAPI)'
    2.02 min.Example: 'Storing registration key in the resources of an executable file'
    Advertise here!