Win95 API to change resolutions and/or colors

Hi. I normally run Win95 in 16-bit (65K colors). I'm trying to write a program that, when run, will switch to 256 colors if it's in 65K, or switch to 65K if it's in 256. Basically, to toggle between the two. I know you don't need to restart Win95 to change colors, because QuickRes, the PowerToy provided by Microsoft, does it w/o restarting. Can someone tell me how this can be done? Thanks.
CowGodAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vmpnCommented:
I wrote a code to change a screen resolution but not colors here is a specialy modified version for you.  Trid parameter is number of bits per pixel if you do not know what that is see coments in ChangeResolution function.

Attribute VB_Name = "Module1"
Option Explicit

Private Declare Function EnumDisplaySettings _
Lib "user32" Alias "EnumDisplaySettingsA" _
(ByVal lpszDeviceName As Long, ByVal _
iModeNum As Long, lpDevMode As Any) As Boolean

Private Declare Function _
ChangeDisplaySettings Lib "user32" Alias _
"ChangeDisplaySettingsA" (lpDevMode As Any, _
ByVal dwflags As Long) As Long _
 
Const CCDEVICENAME = 32
Const CCFORMNAME = 32
Const DM_BITSPERPEL = &H40000
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const DM_DISPLAYFLAGS = &H200000

Private Type DEVMODE
    dmDeviceName As String * CCDEVICENAME
    dmSpecVersion As Integer
    dmDriverVersion As Integer
    dmSize As Integer
    dmDriverExtra As Integer
    dmFields As Long
    dmOrientation As Integer
    dmPaperSize As Integer
    dmPaperLength As Integer
    dmPaperWidth As Integer
    dmScale As Integer
    dmCopies As Integer
    dmDefaultSource As Integer
    dmPrintQuality As Integer
    dmColor As Integer
    dmDuplex As Integer
    dmYResolution As Integer
    dmTTOption As Integer
    dmCollate As Integer
    dmFormName As String * CCFORMNAME
    dmUnusedPadding As Integer
    dmBitsPerPel As Integer
    dmPelsWidth As Long
    dmPelsHeight As Long
    dmDisplayFlags As Long
    dmDisplayFrequency As Long
    'for Windows 95 only
    dmICMMethod As Long
    dmICMIntent As Long
    dmMediaType As Long
    dmDitherType As Long
    dmReserved1 As Long
    dmReserved2 As Long
End Type

Dim DevM As DEVMODE

Public Function ChangeResolution(lWidth As Long, lHeight As Long, iBitsPerPel As Integer) As Long
'If you do not want to change colors set iBitsPerPel equal to 0
'Parameters:
'lWidth = width in pixels
'lHeight = height in pixels
'iBitsPerPel = bits per pixel (0 do not change colors)
'Returns:
'0 - Successful
'1 - Need to restart computer to make changes
'<0 - Unable to change display mode
'---
'iBitsPerPel
'4 = 16 colors
'8 = 256 colors
'16 = HiColor
'24 and above = TrueColor (have to have a good video card and a lot of vdeo memory)

If Not IsResolutionSupported(lWidth, lHeight, iBitsPerPel) Then
    ChangeResolution = -1
    Exit Function
End If

Dim b As Long
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
If iBitsPerPel <> 0 Then DevM.dmFields = DevM.dmFields Or DM_BITSPERPEL
DevM.dmPelsWidth = lWidth
DevM.dmPelsHeight = lHeight
ChangeResolution = ChangeDisplaySettings(DevM, 0)
End Function

Public Function IsResolutionSupported(lWidth As Long, lHeight As Long, iBitsPerPel As Integer) As Boolean
Dim a As Boolean
Dim i As Long
Dim RetCode As Boolean

RetCode = False
i = 0

Do
    a = EnumDisplaySettings(vbEmpty, i, DevM)
    i = i + 1
    If DevM.dmPelsWidth = lWidth And DevM.dmPelsHeight = lHeight And (iBitsPerPel = DevM.dmBitsPerPel Or iBitsPerPel = 0) Then
        RetCode = True
    End If
Loop Until (a = False)
IsResolutionSupported = RetCode
End Function


'Example of call to the changeresolution
MsgBox ChangeResolution(800, 600, 0)  '  0 means do not change colors
MsgBox ChangeResolution(800, 600, 16)  ' 16 means use HiColor
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CowGodAuthor Commented:
That's perfect, thanks.
0
vmpnCommented:
You welcome.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.