Dynamically change the screen to set resolution, color, etc.

zhaozj2021-02-11  224

Dynamic changing screen settings' - definition

Private Declare Function Lstrcpy_

LIB "kernel32" alias "lstrcpya" _

(lpstring1 as any, lpstring2 as any) _

As long

Const cchdevicename = 32

Const cchformname = 32

Private Type Devmode

DMDevicename as string * cchdevicename

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 * CchFormName

Dmunusedpadding as in

DMBITSPEL AS INTEGER

DMPELSWIDTH AS Long

DMPELSHEIGHT AS long

DMDISPLAYFLAGS As Long

DMDisplayFrequency As Long

End Type

Private Declare Function_

ChangeDisplaySettings LIB _

"User32" Alias ​​"ChangeDisplaySettingsa" (_

Byval LPDEVMODE As Long, _

BYVAL DWFLAGS As long) As long

'- function

Public Function setDisplayMode (Width as _

Integer, Height AS Integer, Color As_

Integer) As Long

Const DM_PELSWIDTH = & h80000

Const DM_PELSHEIGHT = & h100000

Const DM_BITSPEL = & H40000

Dim newdevmode as devmode

Dim PDEVMODE AS Long

With Newdevmode

.dmsize = 122

IF color = -1 Then

.dmfields = DM_PELSWIDTH OR DM_PELSHEIGHT

Else

.dmfields = DM_PELSWIDTH OR _

DM_PELSHEIGHT OR DM_BITSPERPEL

END IF

.dmpelswidth = width

.dmpelsheight = height

IF color <> -1 Then

.dmbitsperpel = color

END IF

End with

PDEVMODE = LSTRCPY (NewDevmode, NewDevmode)

SetDisplayMode = ChangeDisplaySettings (PDEVMODE, 0) End Function

Example call: change to 640x480x24 bit:

i = setDisplaymode (640, 480, 24)

If you successfully returns 0.

转载请注明原文地址:https://www.9cbs.com/read-4623.html

New Post(0)