Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Restoring Screen Resolutions
Hi All,
I have an Excel application in which I change the resolution on entr if the resolution is less than 1024 X768. The application consists of different workbooks, on exit I want to restore the original settings. I have been successfully changing the resolution but I cannot seem t return the original settings when I dynamically set the resolution. I was under the impression that when I used the flag 0& I was changin the resolution dynamically & it was not written to the registry. Call ChangeDisplaySettings(DevM, 0&) And when I used the Null as the mode the original settings in th registry would be restored. Call ChangeDisplaySettings(vbNullString, 0&) Has anyone had any experience with this? The application will b running Office 2000 & upwards (OS Win95- WindowsXP). I know it is not good practice to change users display settings but a this stage I have to use this method. Thanks, Adam. Private Declare Function EnumDisplaySettings Lib "user32" _ Alias "EnumDisplaySettingsA" _ (ByVal lpszDeviceName As Long, _ ByVal iModeNum As Long, _ lpDevMode As Any) As Boolean Private Declare Function ChangeDisplaySettings Lib "user32" _ Alias "ChangeDisplaySettingsA" _ (lpDevMode As Any, _ ByVal dwFlags As Long) As Long 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 Sub ChangeRes() 'Change resolution to 1024 X 768 Const CDS_UPDATEREGISTRY = &H1 Const CDS_TEST = &H4 Dim blnWorked As Boolean Dim i As Long Dim DevM As DEVMODE i = 0 Do blnWorked = EnumDisplaySettings(0&, i, DevM) i = i + 1 Loop Until (blnWorked = False) With DevM .dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT .dmPelsWidth = 1024 .dmPelsHeight = 768 End With 'Update dynamically Call ChangeDisplaySettings(DevM, 0&) End Sub Sub ReturnSettings() 'Return Settings Call ChangeDisplaySettings(vbNullString, 0&) End Sub [b]: -- Message posted from http://www.ExcelForum.com |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Restoring Screen Resolutions
Hi Adam,
Can't test it as my new LCD screen gets *very* unhappy with having its resolution changed, but, for the reset, try changing it to: ChangeDisplaySettings ByVal 0&, 0& HTH Peter Beach "adam99 " wrote in message ... Hi All, I have an Excel application in which I change the resolution on entry if the resolution is less than 1024 X768. The application consists of 7 different workbooks, on exit I want to restore the original settings. I have been successfully changing the resolution but I cannot seem to return the original settings when I dynamically set the resolution. I was under the impression that when I used the flag 0& I was changing the resolution dynamically & it was not written to the registry. Call ChangeDisplaySettings(DevM, 0&) And when I used the Null as the mode the original settings in the registry would be restored. Call ChangeDisplaySettings(vbNullString, 0&) Has anyone had any experience with this? The application will be running Office 2000 & upwards (OS Win95- WindowsXP). I know it is not good practice to change users display settings but at this stage I have to use this method. Thanks, Adam. Private Declare Function EnumDisplaySettings Lib "user32" _ Alias "EnumDisplaySettingsA" _ (ByVal lpszDeviceName As Long, _ ByVal iModeNum As Long, _ lpDevMode As Any) As Boolean Private Declare Function ChangeDisplaySettings Lib "user32" _ Alias "ChangeDisplaySettingsA" _ (lpDevMode As Any, _ ByVal dwFlags As Long) As Long 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 Sub ChangeRes() 'Change resolution to 1024 X 768 Const CDS_UPDATEREGISTRY = &H1 Const CDS_TEST = &H4 Dim blnWorked As Boolean Dim i As Long Dim DevM As DEVMODE i = 0 Do blnWorked = EnumDisplaySettings(0&, i, DevM) i = i + 1 Loop Until (blnWorked = False) With DevM dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT dmPelsWidth = 1024 dmPelsHeight = 768 End With 'Update dynamically Call ChangeDisplaySettings(DevM, 0&) End Sub Sub ReturnSettings() 'Return Settings Call ChangeDisplaySettings(vbNullString, 0&) End Sub [b]:) --- Message posted from http://www.ExcelForum.com/ |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Restoring Screen Resolutions
Thanks for replying Peter, it works well on my PC(further testing o
other OS will be required). I really don't like changing the scree resolutioin but at the moment I can't get around it. I will have to pu some error handling for situations where reboots are required & thos similair to your LCD monitor. Thanks Again, Adam.: -- Message posted from http://www.ExcelForum.com |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Restoring Screen Resolutions
Hi Adam,
Glad the solution passed the first hurdle <g. Just to explain the difference. The API wizard, accurately, defines the function as: Private Declare Function ChangeDisplaySettings Lib "user32" _ Alias "ChangeDisplaySettingsA" _ (lpDevMode As Any, _ ByVal dwFlags As Long) As Long The first parameter is passed by reference (i.e. a pointer in C parlance). API calls are treated by the O/S using C language. In C Null is the *value* 0. When you pass in 0& (unqualified), which is what vbNullString evaluates to, you are telling the O/S to reference the memory at address 0 (sadly this is the start of the O/S memory and unless your computer is in a sad state its value will not be zero!). By changing the call to ByVal 0& you overwrite the function declaration and tell the O/S to use the value 0 which is correctly interpreted as Null. Best wishes, Peter Beach "adam99 " wrote in message ... Thanks for replying Peter, it works well on my PC(further testing on other OS will be required). I really don't like changing the screen resolutioin but at the moment I can't get around it. I will have to put some error handling for situations where reboots are required & those similair to your LCD monitor. Thanks Again, Adam.:) --- Message posted from http://www.ExcelForum.com/ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Status bar disappears when restoring screen size | Excel Discussion (Misc queries) | |||
Need to convert point on screen to various screen resolutions | Excel Discussion (Misc queries) | |||
How to position form in same place with different screen resolutions | Excel Programming | |||
Resizing BackgroundPicture Gifs programmatically for varying screen resolutions | Excel Programming | |||
different screen resolutions | Excel Programming |