Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What is their Screen Resolution?
Message
 
 
À
12/09/2005 16:20:41
Joel Hokanson
Services Integration Group
Bellaire, Texas, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows 2000 SP4
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01048941
Message ID:
01049581
Vues:
9
Although it is commonly advisable not to force a change in the screen resolution at a users computer, there are situations where it can be very handy to have this option.

For example during development I regularly switch the resolution to test the user interfaces for different screen resolutions.

For this I added a menu bar to the menu with the available screen resolutions and the user (in most cases the developer) can simply switch between the resolutions.

The currently used resolution is marked, so you see also which resolution is just in place.
*NAME:			ScreenResolution()
*
PROCEDURE ScreenResolution
*
*-- The parameter is the width of the screen in pixels.
LPARAMETERS tnResolution, tlSetMark
*
*-- Use second parameter only to check and set the mark
*-- in the menu (if you have a menu bar).
*
*-- We use the following two libraries: One to 
*-- get the available display settings, the other
*-- to change the setting. If the change fails,
*-- it will just not take the change into effect.
*
Declare Integer EnumDisplaySettings in Win32API ;
	String lpszDeviceName, ;
	Integer iModeNum, ;
	String @lpDevMode
*
Declare Integer ChangeDisplaySettings in Win32API ;
	String @lpDevMode, ;
	Integer dwflags
*
*-- Two class libraries, from 
*-- http://www.foxite.com/downloads/default.aspx?id=&keyword=struct&category=
*
*-- (Download Struct.VCX and WinStruct.VCX.)
Set ClassLib to Struct, WinStruct Additive
loStruct = NEWOBJECT("DevMode")
*
*-- First create the structure using the current
*-- display setting.
Local lcDMCurrent
loStruct.dmSize = loStruct.SizeOf()
loStruct.dmDriverExtra = 0
lcDMCurrent = loStruct.GetString()
EnumDisplaySettings( NULL, -1, @lcDMCurrent)
loStruct.SetString( m.lcDMCurrent)
lnCurrentWidth = loStruct.dmPelsWidth
*
IF tlSetMark = .T.
	*-- (Remove this code if you don't use a menu bar).
	SET MARK OF BAR 1 OF ScreenResolution TO .F.
	SET MARK OF BAR 2 OF ScreenResolution TO .F.
	SET MARK OF BAR 3 OF ScreenResolution TO .F.
	SET MARK OF BAR 4 OF ScreenResolution TO .F.
	SET MARK OF BAR 5 OF ScreenResolution TO .F.
	*
	*-- Set the mark.
	DO CASE
		CASE lnCurrentWidth = 800
			SET MARK OF BAR 1 OF ScreenResolution TO .T.
		CASE lnCurrentWidth = 1024
			SET MARK OF BAR 2 OF ScreenResolution TO .T.
		CASE lnCurrentWidth = 1280
			SET MARK OF BAR 3 OF ScreenResolution TO .T.
		CASE lnCurrentWidth = 1400
			SET MARK OF BAR 4 OF ScreenResolution TO .T.
		CASE lnCurrentWidth = 1600
			SET MARK OF BAR 5 OF ScreenResolution TO .T.
	ENDCASE
	RETURN .T.
ENDIF
*
*-- Now search in the available settings for the one
*-- that we wanted to set. We find the match by comparing
*-- the display width in pixels with the parameter.
Local lnMode, lcDevMode, lnOK, lnLastColor
lnMode = 0
lcDevMode = loStruct.GetString()
lnLastColor = 0
Do While .T.
	m.lnOK = EnumDisplaySettings( NULL, m.lnMode, @lcDevMode )
	loStruct.SetString( m.lcDevMode)
	IF loStruct.dmPelsWidth = tnResolution AND ;
			loStruct.dmBitsPerPel = 32
		lcDMCurrent = loStruct.GetString()
	ENDIF
	*	
	If m.lnOK == 0
		*-- That means we had the last available one.
		Exit
	Endif
	*
	*-- Check the next higher one.
	lnMode = m.lnMode + 1
Enddo
*
loStruct.SetString( m.lcDMCurrent)
#DEFINE DM_BITSPERPEL       0x00040000
#DEFINE DM_PELSWIDTH        0x00080000
#DEFINE DM_PELSHEIGHT       0x00100000
loStruct.dmFields = DM_BITSPERPEL + DM_PELSWIDTH + DM_PELSHEIGHT
lcDMCurrent = loStruct.GetString()
IF ChangeDisplaySettings( @lcDMCurrent, 0 ) = 0
	*
	*-- Now set the mark.
	*-- (Remove this code if you don't use a menu bar).
	lnCurrentWidth = tnResolution
	*
	SET MARK OF BAR 1 OF ScreenResolution TO .F.
	SET MARK OF BAR 2 OF ScreenResolution TO .F.
	SET MARK OF BAR 3 OF ScreenResolution TO .F.
	SET MARK OF BAR 4 OF ScreenResolution TO .F.
	SET MARK OF BAR 5 OF ScreenResolution TO .F.
	DO CASE
		CASE lnCurrentWidth = 800
			SET MARK OF BAR 1 OF ScreenResolution TO .T.
		CASE lnCurrentWidth = 1024
			SET MARK OF BAR 2 OF ScreenResolution TO .T.
		CASE lnCurrentWidth = 1280
			SET MARK OF BAR 3 OF ScreenResolution TO .T.
		CASE lnCurrentWidth = 1400
			SET MARK OF BAR 4 OF ScreenResolution TO .T.
		CASE lnCurrentWidth = 1600
			SET MARK OF BAR 5 OF ScreenResolution TO .T.
	ENDCASE
ENDIF
*
RETURN .T.
*
*
*
>Is there a way of knowing what the user ‘s monitor is set on with regards to screen size?
>
>Is their screen 800x600 or 1024x768 or whatever they have it set on in the Screen resolution settings.
>
>I do not want to change their settings; I just want to know what they are.
>
>
>
>
>Second question, Can I CHANGE their screen resolution settings from inside a FoxPro program?
>
>
>Joel
>Houston, TX
Christian Isberner
Software Consultant
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform