Solved

Win95 API to change resolutions and/or colors

Posted on 1997-08-25
3
224 Views
Last Modified: 2008-03-06
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.
0
Comment
Question by:CowGod
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
vmpn earned 100 total points
ID: 1432196
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
 

Author Comment

by:CowGod
ID: 1432197
That's perfect, thanks.
0
 
LVL 3

Expert Comment

by:vmpn
ID: 1432198
You welcome.

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

708 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

12 Experts available now in Live!

Get 1:1 Help Now