#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default 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.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default 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.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default API

I set up the API procedure you so kindly provided, and it worked like a charm.
Many thanks.

-- Dennis Eisen
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default 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


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default 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.
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default 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
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default 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




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default 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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"