|
-
Apr 20th, 2001, 11:00 PM
#1
Thread Starter
Lively Member
can get the screen resolution
-
Apr 21st, 2001, 04:25 AM
#2
Addicted Member
You can use this code example:
Code:
'in module:
Option Explicit
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1
' Check whether screen resolution is set to 800x600
' Returns True if the resolution is at 800x600 else
' False is returned
Public Function GetScreenResolution800x600() As Boolean
Dim lTemp As String
' Temporary string to hold returned screen
' resolution
lTemp = GetSystemMetrics(SM_CXSCREEN) & "x" & GetSystemMetrics(SM_CYSCREEN)
' Call the API function twice to return
' screen size for each axis as format into
' the temporary string
If lTemp = "800x600" Then
' Check whether resolution is set to 800x600
GetScreenResolution800x600 = True
' True
Else
GetScreenResolution800x600 = False
' False
End If
End Function
'(in form-commandbutton)
Private Sub cmdGetRes_Click()
If GetScreenResolution800x600 = True Then
MsgBox "Your settings are 800x600", vbInformation
Else
MsgBox "Your display settings are not at 800x600", vbExclamation
End If
End Sub
HTH,
Xdream
-
Apr 21st, 2001, 07:34 AM
#3
Guru
You don't really need the API for this. 
Code:
Dim X As Long, Y As Long
X = Screen.Width / Screen.TwipsPerPixelX
Y = Screen.Height / Screen.TwipsPerPixelY
Call MsgBox("Your resolution is " & X & "x" & Y & " pixels")
VBBrowser v2.2.1
But you would need the API if you also want the color depth part of the resolution. Put this in a module:
Code:
Option Explicit
Public Const ENUM_CURRENT_SETTINGS = -1
Public Const CCHDEVICENAME = 32
Public Const CCHFORMNAME = 32
Public Type DEVMODE
dmDeviceName As String * CCHDEVICENAME
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 * CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Public Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As String, ByVal iModeNum As Long, lpDevMode As DEVMODE) As Long
Public Function GetResolution() As String
Dim dm As DEVMODE
Call EnumDisplaySettings(vbNullString, ENUM_CURRENT_SETTINGS, dm)
GetResolution = dm.dmPelsWidth & "x" & dm.dmPelsHeight & " pixels, " & dm.dmBitsPerPel & "-bit color"
End Function
VBBrowser v2.2.1
Then, anywhere in your code, you can use the GetResolution function to get the resolution details including color depth.
-
Apr 21st, 2001, 07:36 AM
#4
omg
talk about exaggeration bro! here is code that actually does what u want Wazup guys!
'declarations for resolution changing
Public Type DEVMODE
dmDeviceName As String * 32
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 * 32
dmUnusedPadding As Integer
dmBitsPerPixel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
dmICMMethod As Long
dmICMIntent As Long
dmMediaType As Long
dmDitherType As Long
dmReserved1 As Long
dmReserved2 As Long
End Type
Public Declare Function EnumDisplaySettings Lib "user32.dll" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As String, ByVal iModeNum As Long, lpDevMode As DEVMODE) As Long
Public Declare Function ChangeDisplaySettings Lib "user32.dll" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long
Public Const ENUM_CURRENT_SETTINGS = -1
Dim dm As DEVMODE
dm.dmSize = Len(dm)
rval& = EnumDisplaySettings(vbNullString, ENUM_CURRENT_SETTINGS, dm)
=============
dm.pelswidth is ur x resolution
dm.pelsheight is ur y resolution
-
Apr 21st, 2001, 07:43 AM
#5
Guru
Is my code exaggerated? Then why's your code so similar to mine?
-
Apr 21st, 2001, 08:29 AM
#6
Monday Morning Lunatic
Probably because there's only a 2-minute difference, so I expect he was referring to an earlier post 
Damn you've got me started now
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 21st, 2001, 08:35 AM
#7
Guru
Originally posted by parksie
Damn you've got me started now
You'll get over it
-
Apr 21st, 2001, 09:28 AM
#8
Thread Starter
Lively Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|