home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD1277212172000.psc / ChangeRes.bas next >
Encoding:
BASIC Source File  |  2000-12-06  |  2.5 KB  |  65 lines

  1. Attribute VB_Name = "ChRes"
  2. Public Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
  3. Public Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
  4. Public Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwflags As Long) As Long
  5.     
  6. 'constants for GetDeviceCaps
  7. Public Const BITSPIXEL As Long = 12
  8. Public Const HORZRES As Long = 8
  9. Public Const VERTRES As Long = 10
  10. 'constants for EnumDisplaySettings
  11. Public Const CCDEVICENAME = 32
  12. Public Const CCFORMNAME = 32
  13. Public Const DM_BITSPERPEL = &H40000
  14. Public Const DM_PELSWIDTH = &H80000
  15. Public Const DM_PELSHEIGHT = &H100000
  16. 'constants for ChangeDisplaySettings
  17. Public Const CDS_FORCE As Long = &H80000000
  18.  
  19.  
  20. Public Type typDEVMODE
  21.     dmDeviceName As String * CCDEVICENAME
  22.     dmSpecVersion As Integer
  23.     dmDriverVersion As Integer
  24.     dmSize As Integer
  25.     dmDriverExtra As Integer
  26.     dmFields As Long
  27.     dmOrientation As Integer
  28.     dmPaperSize As Integer
  29.     dmPaperLength As Integer
  30.     dmPaperWidth As Integer
  31.     dmScale As Integer
  32.     dmCopies As Integer
  33.     dmDefaultSource As Integer
  34.     dmPrintQuality As Integer
  35.     dmColor As Integer
  36.     dmDuplex As Integer
  37.     dmYResolution As Integer
  38.     dmTTOption As Integer
  39.     dmCollate As Integer
  40.     dmFormName As String * CCFORMNAME
  41.     dmUnusedPadding As Integer
  42.     dmBitsPerPel As Integer
  43.     dmPelsWidth As Long
  44.     dmPelsHeight As Long
  45.     dmDisplayFlags As Long
  46.     dmDisplayFrequency As Long
  47. End Type
  48.  
  49. Public DevM As typDEVMODE
  50. Public Function ChangeRes() As Integer
  51.     'ScrWidth As Single, ScrHeight As Single, BPP As Integer
  52.     DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
  53.     DevM.dmPelsWidth = ScrWidth
  54.     DevM.dmPelsHeight = ScrHeight
  55.     DevM.dmBitsPerPel = BPP
  56.     'note that if CDS_FORCE is not specified, Windows will NEVER change the BPP!
  57.     'btw. I found with my graphics adapter, the colors will screw up when switching from
  58.     '32 to 16 Bit (esp. grey) but hey, still better than rebooting :-)
  59.     Call ChangeDisplaySettings(DevM, CDS_FORCE)
  60.     'we could check for return values here: they would be
  61.     'DISP_CHANGE_SUCCESSFUL = 0 'DISP_CHANGE_RESTART = 1 'DISP_CHANGE_FAILED = -1 'DISP_CHANGE_BADMODE = -2
  62.     'DISP_CHANGE_NOTUPDATED = -3 'DISP_CHANGE_BADFLAGS = -4 'DISP_CHANGE_BADPARAM = -5
  63.     'but since no one should be there to notice, why bother?
  64. End Function
  65.