isladogs
MVP / VIP
- Local time
- Today, 21:08
- Joined
- Jan 14, 2017
- Messages
- 18,827
Hi
Does anyone know how to control multiple display settings using VBA?
I'll explain the reason in a later post if I get anywhere with this...
As I think it's a fairly obscure topic I'm posting this on more than one forum.
Also at: http://www.utteraccess.com/forum/index.php?showtopic=2044813
Specifically I want to do the following using VBA when running a particular db:
1. check if there is more than one monitor
2. if so, identify the current display setting e.g. extend these displays
3. change the display setting to one of the following:
a) duplicate displays
b) show display only on monitor 1
Then when I close the database, I would restore the original display setting
I would imagine this can be done using an API but haven't been able to find anything about this online
The nearest I've got is the following which changes the resolution of monitor 2.
Code from http://www.vbforums.com/showthread.php?644046-RESOLVED-Change-display-settings-for-2nd-monitor
Thanks in advance for any help with this
Does anyone know how to control multiple display settings using VBA?
I'll explain the reason in a later post if I get anywhere with this...
As I think it's a fairly obscure topic I'm posting this on more than one forum.
Also at: http://www.utteraccess.com/forum/index.php?showtopic=2044813
Specifically I want to do the following using VBA when running a particular db:
1. check if there is more than one monitor
2. if so, identify the current display setting e.g. extend these displays
3. change the display setting to one of the following:
a) duplicate displays
b) show display only on monitor 1
Then when I close the database, I would restore the original display setting
I would imagine this can be done using an API but haven't been able to find anything about this online
The nearest I've got is the following which changes the resolution of monitor 2.
Code from http://www.vbforums.com/showthread.php?644046-RESOLVED-Change-display-settings-for-2nd-monitor
Code:
Option Compare Database
Option Explicit
'Code from http://www.vbforums.com/showthread.php?644046-RESOLVED-Change-display-settings-for-2nd-monitor
Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
Private Declare Function ChangeDisplaySettingsEx Lib "user32" Alias _
"ChangeDisplaySettingsExA" (lpszDeviceName As Any, lpDevMode As Any, _
ByVal hWnd As Long, ByVal dwFlags As Long, lParam As Any) As Long
Const CCDEVICENAME = 32
Const CCFORMNAME = 32
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const CDS_TEST = &H4
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 Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Dim DevM As DEVMODE
Private Sub Command1_Click()
Dim a As Boolean: Dim i&
i = 0
Do
a = EnumDisplaySettings(0&, i, DevM)
i = i + 1
Loop Until (a = False)
Dim b&
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
DevM.dmPelsWidth = 1024 '(Horizontal)
DevM.dmPelsHeight = 768 '(Vertical)
Call ChangeDisplaySettingsEx(ByVal "\\.\DISPLAY2", DevM, ByVal 0&, CDS_TEST, ByVal 0&)
End
End Sub
Thanks in advance for any help with this
Last edited: