kevin shen
May 16th, 2001, 08:51 PM
How can I set application GUI size according to the screen resolution(800x600,1024x769)? I want the GUI to look the same size as different rsolution. How can I do?
Thank you for your help!
Best Regards,
Kevin Shen
d.paulson
May 16th, 2001, 09:36 PM
http://support.microsoft.com/support/kb/articles/Q182/0/70.ASP?LN=EN-US&SD=gn&FR=0&qry=screen%20resolution&rnk=1&src=DHCS_MSPSS_gn_SRCH&SPR=VBB
David Paulson
Cakkie
May 17th, 2001, 01:26 AM
You can use the screen object to get the width and height of the screen.
me.Width = Screen.Width
me.Height = Screen.Height
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
Cimperiali
May 17th, 2001, 02:08 AM
I know you asked something else, but how about changing screen resolution in runtime and restore it at end? It may be intereseting...
I find this code at VB2TheMax:
ChangeScreenResolution - Change the current screen resolution
Date: 1/20/2001
Versions: VB4/32 VB5 VB6 Level: Intermediate
Author: The VB2TheMax Team
Option Explicit
Const DM_BITSPERPEL As Long = &H40000
Const DM_PELSWIDTH As Long = &H80000
Const DM_PELSHEIGHT As Long = &H100000
Const CDS_FORCE As Long = &H80000000
Const CCDEVICENAME As Long = 32
Const CCFORMNAME As Long = 32
Private Type DEVMODE
dmDeviceName As String * CCDEVICENAME
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 * CCFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Long
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Private Declare Function EnumDisplaySettings Lib "user32" Alias _
"EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, _
ByVal modeIndex As Long, lpDevMode As Any) As Boolean
Private Declare Function ChangeDisplaySettings Lib "user32" Alias _
"ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwflags As Long) As Long
' change the screen resolution mode
'
' returns True if the requested resolution mode is among those
' supported by the display adapter (otherwise it doesn't even
' try to change the screen resolution)
Function ChangeScreenResolution(ByVal Width As Long, ByVal Height As Long, _
ByVal NumColors As Long, Optional Frequency As Long) As Boolean
Dim lpDevMode As DEVMODE
Dim index As Long
' set the DEVMODE flags and structure size
lpDevMode.dmSize = Len(lpDevMode)
lpDevMode.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
' retrieve info on the Nth display mode, exit if no more
Do While EnumDisplaySettings(0, index, lpDevMode) > 0
' check whether this is the mode we're looking for
If lpDevMode.dmPelsWidth = Width And lpDevMode.dmPelsHeight = Height _
And 2 ^ lpDevMode.dmBitsPerPel = NumColors Then
' check that the frequency is also the one we're looking for
If Frequency = 0 Or Frequency = lpDevMode.dmDisplayFrequency Then
' try changing the resolution
If ChangeDisplaySettings(lpDevMode, CDS_FORCE) = 0 Then
' zero means success
ChangeScreenResolution = True
Exit Do
End If
End If
End If
' skip to next screen mode
index = index + 1
Loop
End Function
'----------------------------------------------------------------------
GetDisplaySettings - Retrieve information about available display modes
Date: 1/20/2001
Versions: VB4/32 VB5 VB6 Level: Intermediate
Author: The VB2TheMax Team
Const DM_BITSPERPEL As Long = &H40000
Const DM_PELSWIDTH As Long = &H80000
Const DM_PELSHEIGHT As Long = &H100000
Const CCDEVICENAME As Long = 32
Const CCFORMNAME As Long = 32
Private Type DEVMODE
dmDeviceName As String * CCDEVICENAME
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 * CCFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Long
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Private Declare Function EnumDisplaySettings Lib "user32" Alias _
"EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, _
ByVal modeIndex As Long, lpDevMode As Any) As Boolean
' Fill two arrays with information about all available display modes
'
' displayInfo() is a bi-dimentional matrix where each row is a display mode
' displayInfo(n, 0) is the horizontal resolution
' displayInfo(n, 1) is the vertical resolution
' displayInfo(n, 2) is the number of colors
' displayInfo(n, 0) is refresh rate (in MHz) or zero if not available
' displayDescr() is an array of string that contains the same information
' but in a textual format, ready to be displayed in a menu or listbox
Sub GetDisplaySettings(displayInfo() As Long, displayDescr() As String)
Dim lpDevMode As DEVMODE
Dim index As Long
Dim displayCount As Long
Dim colorDescr As String
' set the DEVMODE flags and structure size
lpDevMode.dmSize = Len(lpDevMode)
lpDevMode.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
' count how many display settings are there
Do While EnumDisplaySettings(0, displayCount, lpDevMode) > 0
displayCount = displayCount + 1
Loop
' now displayCount holds the number of display settings
' and we can DIMension the result arrays
ReDim displayInfo(0 To displayCount - 1, 0 To 3) As Long
ReDim displayDescr(0 To displayCount - 1) As String
For index = 0 To displayCount - 1
' retrieve info on the Nth display mode
EnumDisplaySettings 0, index, lpDevMode
' fill the displayInfo structure
displayInfo(index, 0) = lpDevMode.dmPelsWidth
displayInfo(index, 1) = lpDevMode.dmPelsHeight
displayInfo(index, 2) = 2 ^ IIf(lpDevMode.dmBitsPerPel > 24, 24, _
lpDevMode.dmBitsPerPel)
If lpDevMode.dmDisplayFrequency > 1 Then
displayInfo(index, 0) = lpDevMode.dmDisplayFrequency
End If
' prepare a description for this display mode
Select Case displayInfo(index, 2)
Case 16
colorDescr = "16 colors"
Case 256
colorDescr = "256 colors"
Case Is <= 65536
colorDescr = "High color"
Case Else
colorDescr = "True color"
End Select
displayDescr(index) = lpDevMode.dmPelsWidth & " x " & _
lpDevMode.dmPelsHeight & ", " & colorDescr
If lpDevMode.dmDisplayFrequency > 1 Then
displayDescr(index) = displayDescr(index) & ", " & _
lpDevMode.dmDisplayFrequency & " MHz"
End If
Next
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.