Solved

Win95 API to change resolutions and/or colors

Posted on 1997-08-25
3
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

710 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