![]() |
API
Does anyone know if there is an API function to change the
screen resolution? I'd like to be able to switch from 1024x748 to 800x600 and back. |
API
Not a good idea to mess with the screen resolution (IMO). Could you not
handle it with resizing the worksheet and/or fonts? -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Dennis" wrote in message ... Does anyone know if there is an API function to change the screen resolution? I'd like to be able to switch from 1024x748 to 800x600 and back. |
API
Dennis,
There is no API calls that will change screen resolution from within any application. This can only be done by leaving Excel and adjusting the desktop parameters. -- Dennis Eisen |
API
Hi Dennis;
You can try: Private Declare Function EnumDisplaySettings Lib "user32" _ Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName& _ , ByVal iModeNum&, lpDevMode As Any) As Boolean Private Declare Function ChangeDisplaySettings& Lib "user32" _ Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwflags&) Private Type DEVMODE dmDeviceName As String * 32 dmSpecVersion% dmDriverVersion% dmSize% dmDriverExtra% dmFields& dmOrientation% dmPaperSize% dmPaperLength% dmPaperWidth% dmScale% dmCopies% dmDefaultSource% dmPrintQuality% dmColor% dmDuplex% dmYResolution% dmTTOption% dmCollate% dmFormName As String * 32 dmUnusedPadding% dmBitsPerPel% dmPelsWidth& dmPelsHeight& dmDisplayFlags& dmDisplayFrequency& End Type Private Declare Function EnumDisplaySettings Lib "user32" _ Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName& _ , ByVal iModeNum&, lpDevMode As Any) As Boolean Private Declare Function ChangeDisplaySettings& Lib "user32" _ Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwflags&) Private Type DEVMODE dmDeviceName As String * 32 dmSpecVersion% dmDriverVersion% dmSize% dmDriverExtra% dmFields& dmOrientation% dmPaperSize% dmPaperLength% dmPaperWidth% dmScale% dmCopies% dmDefaultSource% dmPrintQuality% dmColor% dmDuplex% dmYResolution% dmTTOption% dmCollate% dmFormName As String * 32 dmUnusedPadding% dmBitsPerPel% dmPelsWidth& dmPelsHeight& dmDisplayFlags& dmDisplayFrequency& End Type Private Sub ChangeResolution(W As Single, H As Single) Dim OK As Boolean, i&, DVM As DEVMODE Do OK = EnumDisplaySettings(0&, i&, DVM) i = i + 1 Loop Until OK = False DVM.dmFields = &H80000 Or &H100000 DVM.dmPelsWidth = W DVM.dmPelsHeight = H ChangeDisplaySettings DVM, 0 End Sub Sub Screen_800X600() ChangeResolution 800, 600 End Sub Sub Screen_1024X768() ChangeResolution 1024, 768 End Sub MP "Dennis" a écrit dans le message de ... Does anyone know if there is an API function to change the screen resolution? I'd like to be able to switch from 1024x748 to 800x600 and back. |
API
Re Dennis;
The good declaration for Type is: Private 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 dmBitsPerPel As Integer dmPelsWidth As Long dmPelsHeight As Long dmDisplayFlags As Long dmDisplayFrequency As Long End Type "Dennis" a écrit dans le message de ... Does anyone know if there is an API function to change the screen resolution? I'd like to be able to switch from 1024x748 to 800x600 and back. |
API
I set up the API procedure you so kindly provided, and it worked like a charm.
Many thanks. -- Dennis Eisen |
API
"DennisE" skrev i melding
... I set up the API procedure you so kindly provided, and it worked like a charm. Many thanks. Hi Dennis I'd really really hate it if you did that to my laptop. Be very careful with code like that. (I'm sure you know what you do, where and why. But there are students reading these groups. Don't try this at home, kids) Best wishes Harald |
API
"Harald Staff" wrote...
... (I'm sure you know what you do, where and why. But there are students reading these groups. Don't try this at home, kids) ... Experimentation is the cornerstone of scientific knowledge. Expensive mistakes teach certain lessons more effectively in a shorter period of time than darn near anything else. -- To top-post is human, to bottom-post and snip is sublime. |
API
Harald,
I'd never in a million years mess with anyone's laptop in an arbitrary fashion. The decision to switch from 1280X768 to 800X600 (or the reverse) will be left entirely in the hands of users who might wish to see userforms larger or smaller (perhaps even selectively so as they move through the program) without having to leave Excel to adjust their desktop parameters. -- Dennis Eisen |
API
ChangeDisplaySettings can be really useful in a controlled environment.
However, if you really must offer this on other people's systems, can I please make a couple of suggestions. Remember, this is a fundamental change to the computer's settings At the very least, check the return value of ChangeDisplaySettings Const DISP_CHANGE_SUCCESSFUL As Long = 0 Const DISP_CHANGE_RESTART As Long = 1 If it returns 0, the machine thinks it has succeeded If it returns 1, you have made a change the user won't see till next time (s)he reboots. That can be really nasty. Any other return value probably means failure of some sort. Const DISP_CHANGE_FAILED As Long = -1 Const DISP_CHANGE_BADMODE As Long = -2 Const DISP_CHANGE_NOTUPDATED As Long = -3 Const DISP_CHANGE_BADFLAGS As Long = -4 Const DISP_CHANGE_BADPARAM As Long = -5 I recommend after a successful change you ask the user to confirm all is OK (do not use a msgBox or modal form) and, if not, reset the resolution after say 45 seconds. And, of course, whatever else you do, aways reset to the original settings before finishing. These settings may well be neither 1280x768 nor 800x600 Having said all that, I still think you'd be much better to offer alternate versions of you forms to the user instead of messing with things of which the users may not understand the significance. DennisE wrote: Harald, I'd never in a million years mess with anyone's laptop in an arbitrary fashion. The decision to switch from 1280X768 to 800X600 (or the reverse) will be left entirely in the hands of users who might wish to see userforms larger or smaller (perhaps even selectively so as they move through the program) without having to leave Excel to adjust their desktop parameters. -- Dennis Eisen |
API
Looking at Michel's code again, I see I failed to notice that he is
calling it with dwflags set to 0 This is significantly less dangerous, as a reboot will reverse it, so my comments about a return value of 1 do not apply Nonetheless, 1) the return value still needs to be checked, 2) you need to reassure yourself that the user isn't sitting looking at a blank screen and wondering what you've done to them 3)(something I forgot to say earlier) other windows should be notified that the screen resolution has changed, using SendMessage HWND_BROADCAST, WM_DISPLAYCHANGE 4) You really should restore the screen resolution when tou've finished. And a really minor point, you will probably get users complaining that you've moved the icons around on their desktop. Steve Garman wrote: ChangeDisplaySettings can be really useful in a controlled environment. However, if you really must offer this on other people's systems, can I please make a couple of suggestions. Remember, this is a fundamental change to the computer's settings At the very least, check the return value of ChangeDisplaySettings Const DISP_CHANGE_SUCCESSFUL As Long = 0 Const DISP_CHANGE_RESTART As Long = 1 If it returns 0, the machine thinks it has succeeded If it returns 1, you have made a change the user won't see till next time (s)he reboots. That can be really nasty. |
API
Hi Dennis;
If you want to do that in full safety, you can also use: Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _ (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String _ , ByVal lpParameters As String, ByVal lpDirectory As String _ , ByVal nShowCmd As Long) As Long Sub ScreenProperties() Shell "rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,3" End Sub Regards MP "Dennis" a écrit dans le message de ... Does anyone know if there is an API function to change the screen resolution? I'd like to be able to switch from 1024x748 to 800x600 and back. |
All times are GMT +1. The time now is 09:04 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com