October 30, 2025, 04:22:09 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Setting the screen resolution

Started by Andy, January 07, 2014, 05:06:47 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi,

Happy new year to all!

My friend has a laptop, and she plugs in a TV to the external monitor connection on the laptop so she can watch films etc on the bigger TV screen.

But when she unplugs the TV, the laptop screen resolution does not revert back to the previous setting of
1024 x 768.

Is there a way of setting the screen resolution using IWB+ code so I can write a quick fix program?

She is not very compitant with computers, so asking her to reset the screen resolution herself is not really
an option for her.

She has Windows XP.

Thanks,
Andy.
:)


Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

The API you want to use is ChangeDisplaySettings

You shouldn't have any trouble converting this Creative Basic code by Sapero to what you want to do.
declare "user32", EnumDisplaySettingsA(lpszDeviceName:pointer,iModeNum:int,lpDevMode:memory),int
declare "user32", ChangeDisplaySettingsA(lpDevMode:memory, dwflags:int),int

const CCHDEVICENAME = 32
const ENUM_CURRENT_SETTINGS = -1

type DEVMODE,2
def dmDeviceName[CCHDEVICENAME]:char
def dmSpecVersion:word
def dmDriverVersion:word
def dmSize:word
def dmDriverExtra:word
def dmFields:int
def reserved[16]:int

def dmPelsWidth:int
def dmPelsHeight:int
def reserved2:int
def dmDisplayFrequency:int
endtype

def lpDevMode:memory
def dmCurrent:DEVMODE
def dmNew:DEVMODE
def NULL:pointer

allocmem(lpDevMode, 1, len(dmCurrent))
dmCurrent.dmSize = len(dmCurrent)
writemem lpDevMode, 1, dmCurrent
' get the current settings
EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, lpDevMode)
readmem lpDevMode, 1, dmCurrent
readmem lpDevMode, 1, dmNew

messagebox 0, using("#x#", dmCurrent.dmPelsWidth, dmCurrent.dmPelsHeight), "current display mode"


dmNew.dmPelsWidth = 640
dmNew.dmPelsHeight = 480
writemem lpDevMode, 1, dmNew
if (ChangeDisplaySettingsA(lpDevMode, 0) = 0)
messagebox 0, using("changed to #x#", dmNew.dmPelsWidth, dmNew.dmPelsHeight), ""
writemem lpDevMode, 1, dmCurrent
ChangeDisplaySettingsA(lpDevMode, 0)
else
messagebox 0, using("failed to switch to #x#", dmNew.dmPelsWidth, dmNew.dmPelsHeight), ""
endif

freemem lpDevMode

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thank Larry,

Will have a look at it!

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Thanks Larry,

Thats perfect for her.

Made two versions of the program, 1 to set the laptop resolution and 1 for the tv resolution, she just has to double click on the one she wants.

Thanks again,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library