By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,059 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

screen resolution

P: n/a
when my vb program run on another computer instead of my computer, the
user interface is biggger..this is because of the screen resolution...
anyone know how to solve pls?
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
One way is to check the users screen resolution with the procedure below. If the screen resolution is incorrect you can send the user a message or exit the application.

Public Function CheckRez(pixelWidth As Long, pixelHeight As Long) As Boolean
Dim lngTwipsX As Long
Dim lngTwipsY As Long

' convert pixels to twips
lngTwipsX = pixelWidth * 15
lngTwipsY = pixelHeight * 15

' check against current settings
If lngTwipsX <> Screen.Width Then
CheckRez = False
Else
If lngTwipsY <> Screen.Height Then
CheckRez = False
Else
CheckRez = True
End If
End If
End Function

Private Sub Form_Load()
If CheckRez(800, 600) = False Then
MsgBox "Incorrect screen size!"
Else
MsgBox "Screen Resolution Matches!"
End If
End Sub

Another way is to force a screen resolution change usin API. (Not that adviseable unless you really know what you're doing) To do this you first must add a basic module to your project (if you don't already have one). Place the following declarations into your module:

Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean

Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long

Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

Public Const EWX_LOGOFF = 0
Public Const EWX_SHUTDOWN = 1
Public Const EWX_REBOOT = 2
Public Const EWX_FORCE = 4

Public Const CCDEVICENAME = 32
Public Const CCFORMNAME = 32
Public Const DM_BITSPERPEL = &H40000
Public Const DM_PELSWIDTH = &H80000
Public Const DM_PELSHEIGHT = &H100000
Public Const CDS_UPDATEREGISTRY = &H1
Public Const CDS_TEST = &H4
Public Const DISP_CHANGE_SUCCESSFUL = 0
Public Const DISP_CHANGE_RESTART = 1

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 Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long

dmDisplayFrequency As Long
End Type

NOW PLACE THE FOLLOWING CODE IN THE DECLARATIONS SECTION OF YOUR FORM:

Private Sub Form_Activate()
Dim DevM As DEVMODE
Dim erg&
Dim an

'Get the info into DevM
erg& = EnumDisplaySettings(0&, 0&, DevM)

'We don't change the colordepth, because a reboot will be necessary

DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT 'Or DM_BITSPERPEL
DevM.dmPelsWidth = 1024 'ScreenWidth - could also be 800, etc
DevM.dmPelsHeight = 768 'ScreenHeight - could also be 600, etc

'DevM.dmBitsPerPel = 32 (could be 8, 16, 32 or even 4)

'Now change the display and check if possible
erg& = ChangeDisplaySettings(DevM, CDS_TEST)

'Check if succesfull
Select Case erg&

Case DISP_CHANGE_RESTART
an = MsgBox("You need to reboot", vbYesNo + vbSystemModal, "Info")
If an = vbYes Then
erg& = ExitWindowsEx(EWX_REBOOT, 0&)
End If
Case DISP_CHANGE_SUCCESSFUL
erg& = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
MsgBox "Everything's ok", vbOKOnly + vbSystemModal, "It worked!"

Case Else
MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "Error"
End Select
End Sub

Hope this helps.
"ZaGras" <za*******@hotmail.com> wrote in message news:ef**************************@posting.google.c om...
when my vb program run on another computer instead of my computer, the
user interface is biggger..this is because of the screen resolution...
anyone know how to solve pls?

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.