This class supports functionality to list all available video modes and switch to the desired mode. Since some mode changes require a shutdown of Windows, this is also supported.
|(Declarations)||Declarations||Declarations and private variables for the CChangeRes class.|
|AllowReboot||Property||Get whether or not the class offers the option to reboot Windows if a display mode change requires it. Certain mode changes may require a reboot. For example, changing the color depth on some systems requires a reboot for the changes to take effect. If you set this property to True, the class will prompt for a reboot as needed. If this property is set to False, the class will not prompt for reboot, nor will it reboot.|
|ForceMode||Property||Get whether or not the video mode is reset when the mode requested is the same as the current mode.|
|hDC||Property||Set the hDC of a form in the app. This is required to get the list of supported modes.|
|Mode||Property||Retrieve the video mode at the specified position in the collection. This property is only valid after calling the LoadModes method. After calling the LoadModes method, the class Modes collection contains a 1-based list of available modes. Use the Mode property with a long integer index value to retrieve a specific mode.|
|ModeCount||Property||A 1-based count of available video modes. This property is only valid after calling the LoadModes method.|
|Class_Initialize||Initialize||Code called when the class is instantiated.|
|ChangeResolution||Method||Changes resolution to the selected value. The lngSelMode argument corresponds to an available video mode. Since this property is 0-based and the Mode collection is one-based, subtract 1 from a Mode collection item to get the corresponding value to pass to this method.|
|LoadModes||Method||Loads the modes supported by the current display adapter into the class collection, along with strings describing the available modes.|
|IsNT||Private||Determine if the OS is Windows NT.|
' Example of the CChangeRes class ' ' To use this example: ' 1. Create a new form. ' 2. Create a list box called lstModes ' 3. Create a command button called cmdTest ' 4. Create a checkbox called chkForce ' 5. Paste the entire contents of this module into the new form's module. Private mChangeRes As CChangeRes Private Sub chkNT_Click() Call LoadList End Sub Private Sub cmdTest_Click() Dim lngCurrent As Long ' Get the selected item from the list box. ' Increment by one to synchronize with the CChangeRes class's 1-based mode collection. lngCurrent = lstModes.ListIndex + 1 ' Prompt for change If MsgBox("Change resolution?", vbYesNo) = vbYes Then ' Set the Force property mChangeRes.ForceMode = chkForce.Value ' Call the method to change the resolution mChangeRes.ChangeResolution (lngCurrent - 1) End If End Sub Private Sub Form_Load() ' Set up the form With lstModes .Left = 45 .Top = 45 .Height = 3960 .Width = 2865 End With With chkForce .Left = 3015 .Top = 45 .Height = 600 .Width = 1545 End With With cmdTest .Caption = "Change Resolution" .Left = 3015 .Top = chkForce.Top + chkForce.Height + 100 .Height = 495 .Width = 1530 End With ' Instantiate the class Set mChangeRes = New CChangeRes ' Allow reboots if necessary mChangeRes.AllowReboot = True ' Pass this form's hDC mChangeRes.hDC = Me.hDC Call LoadList End Sub Private Sub LoadList() Dim lngCounter As Long lstModes.Clear ' Load the modes mChangeRes.LoadModes ' Show the modes in the list box For lngCounter = 1 To mChangeRes.ModeCount lstModes.AddItem mChangeRes.Mode(lngCounter) Next lngCounter End Sub
The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.
Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!
Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!
"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."
Van T. Dinh, Microsoft MVP