Guidance
指路人
g.yi.org
software / rapidq / Examples / Devices / Display / Change Resolution.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'by John White
'Below is a PROPER working code of
'how to change a window`s resolution.

'The biggest things to note are:

'The registry is no longer corrupted.
'And the DEVMODE is now correct.

'THE DEVMODE IN THE WIN32API.INC
'IS WRONG. It gives long (integer value)
'declarations where there should be WORD
'declarations (probably the reason for many
'codes not working). If you use the win32api.inc
'for the code below you get a corrupt registry
'(CDS_UPDATEREGISTRY). Why? because
'although EnumDisplaySettings() just fills in
'a block of code (of any size - I.e incorrect
'DEVMODE Integers) when that code is
'saved to the registry, as incorrect integer
'values instead of word values, the registry
'becomes mangled. Hence why I did a
'DEVMODE Type.....End Type definition
'that uses the proper values from the
'win32 api manual.

'Note: The code below only changes
'sizes (not frequencies properties
'etc).

'Also note, that there are other values/flags
'you can set. I just did a quick example.

'BTW. Rapidq will change DWORD to long
'so don`t worry about the DWORD
'declarations. Besides. Keeps it simple
'for the Linux programmers!!

'Finally. If you do get a corrupt registry
'and/or this code does not work on
'the fly (in an instance - no reboot)
'then more than likely you have registry
'problems to begin with. For example.
'If you corrupted your display code from
'previous attempts at converting the
'VB code (or whatever) for example
'and could not get that converted rapidq
'code to work you may of just thought
'"oh well it did not work", not realizing
'it messed up your registry. One way
'to tell is to run the code below. If it
'works on the fly then it works, but if
'you need a reboot then.......!!.....you
'will probably get a low resolution
'screen but now try and put it back to
'800 x 600 and you may have problems!
'but hopefully not. How do I know all this?!
'Because I debugged it to the point of
'having so many reboots and fiddling
'to get back to 800x 600 before I finally
'realized what was going on. Bad DevMode,
'Registry buggered, etc.

     $INCLUDE "RAPIDQ.INC"
     $OPTIMIZE ON
'$APPTYPE GUI
     $TYPECHECK ON
     $ESCAPECHARS ON

     CONST EWX_LOGOFF = 0
     CONST EWX_SHUTDOWN = 1
     CONST EWX_REBOOT = 2
     CONST EWX_FORCE = 4
     CONST DM_BITSPERPEL = &H40000
     CONST DM_PELSWIDTH = &H80000
     CONST DM_PELSHEIGHT = &H100000
     CONST CDS_UPDATEREGISTRY = &H1
     CONST CDS_TEST = &H4
     CONST CDS_FULLSCREEN = &H4
     CONST CDS_GLOBAL = &H8
     CONST CDS_SET_PRIMARY = &H10
     CONST CDS_RESET = &H40000000
     CONST CDS_SETRECT = &H20000000
     CONST CDS_NORESET = &H10000000
     CONST DISP_CHANGE_SUCCESSFUL = 0
     CONST DISP_CHANGE_RESTART = 1
     CONST DISP_CHANGE_FAILED = -1
     CONST DISP_CHANGE_BADMODE = -2
     CONST DISP_CHANGE_NOTUPDATED = -3
     CONST DISP_CHANGE_BADFLAGS = -4
     CONST DISP_CHANGE_BADPARAM = -5
     CONST ENUM_CURRENT_SETTINGS = -1
     CONST ENUM_REGISTRY_SETTINGS = -2
     CONST STRING_SIZE=32

     TYPE DEVMODE
      dmDeviceName AS STRING * STRING_SIZE
      dmSpecVersion AS WORD
      dmDriverVersion AS WORD
      dmSize AS WORD
      dmDriverExtra AS WORD
      dmFields AS DWORD
      dmOrientation AS SHORT
      dmPaperSize AS SHORT
      dmPaperLength AS SHORT
      dmPaperWidth AS SHORT
      dmScale AS SHORT
      dmCopies AS SHORT
      dmDefaultSource AS SHORT
      dmPrintQuality AS SHORT
      dmColor AS SHORT
      dmDuplex AS SHORT
      dmYResolution AS SHORT
      dmTTOption AS SHORT
      dmCollate AS SHORT
      dmFormName AS STRING * STRING_SIZE
      dmLogPixels AS WORD
      dmBitsPerPel AS DWORD
      dmPelsWidth AS DWORD
      dmPelsHeight AS DWORD
      dmDisplayFlags AS DWORD
      dmDisplayFrequency AS DWORD
     END TYPE

     DECLARE FUNCTION EnumDisplaySettings LIB "user32" ALIAS "EnumDisplaySettingsA" (BYVAL lpszDeviceName AS LONG, BYVAL iModeNum AS LONG, lpDevMode AS LONG) AS LONG
     DECLARE FUNCTION ChangeDisplaySettings LIB "user32" ALIAS "ChangeDisplaySettingsA" (lpDevMode AS LONG, BYVAL dwFlags AS LONG) AS LONG
     DECLARE FUNCTION ExitWindowsEx LIB "user32" ALIAS "ExitWindowsEx" (BYVAL uFlags AS LONG, BYVAL dwReserved AS LONG) AS LONG

     DIM devm AS DEVMODE, stg$ AS STRING, rtn AS INTEGER

     rtn=EnumDisplaySettings("", ENUM_CURRENT_SETTINGS, devm)
     IF rtn<>0 THEN

      devm.dmFields = DM_PELSWIDTH OR DM_PELSHEIGHT OR DM_BITSPERPEL 'OR DM_DISPLAYFREQUENCY
      devm.dmPelsWidth = 800 'Pixel (screen) Width
      devm.dmPelsHeight = 600 'Pixel (Screen) Height
      devm.dmBitsPerPel = 16 'Bits Per Colours. 4=16 colours, 8=256 colours
'and 16=65536 colours.
'devm.dmDisplayFrequency=0 ' display switch - 0 or 1.

      rtn=ChangeDisplaySettings(devm, CDS_TEST OR CDS_UPDATEREGISTRY)
      IF rtn>-1 THEN

       IF rtn=DISP_CHANGE_SUCCESSFUL THEN
        SHOWMESSAGE("successfull") ' works on my win98 se.
       ELSEIF rtn=DISP_CHANGE_RESTART THEN
        SHOWMESSAGE("re-booting now...")
        ExitWindowsEx(EWX_REBOOT ,0)
       ELSE
        SHOWMESSAGE("failed")
       END IF

      ELSE
       SHOWMESSAGE("cds failed")
      END IF
     ELSE
      SHOWMESSAGE("eds failed")
     END IF
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-3-29  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2002-05-21 21:07:12