Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2003
    Posts
    66

    Unanswered: Auto set Screen Resolution? (This is a long shot)

    Hi all - 3 months into development, and with the frontend complete, client now informs me she doesn't want to use the screen resolution of 1024 x 768 that the db is designed for. It's needed cos of the sheer size of the forms and to be able to preview reports properly.
    Is there a way of somehow automatically setting the screen res on her machine up to 1024 x 768 from 800 x 600 when the database is launched? (And back again when closed). I've heard it's possible on some apps, tho I've never seen it myself.

    I've had a look at the form resizer app, but it seems to involve loads of coding on each individual form, and I have 50 frickin forms in all. (and I'm a crap coder). Seems like a lot of work / expense for what it would ultimately achieve.

    Any thoughts? Need help.
    Cheers
    D

  2. #2
    Join Date
    Feb 2004
    Posts
    37
    Changing screen resolution, you need to use API's to do it.
    There is a sight which explains the process (even has an example in VB6), you can use that example as a basis for what you need to do in VBA, the API is ChangeDisplaySettings
    http://www.thescarms.com/VBasic/chgres.asp

    (you can open up VB6 sourcecode in wordpad or notepad if you don't have VB6).

    Brian.

  3. #3
    Join Date
    Dec 2001
    Posts
    79
    Changing screen resolutions on the fly can be a severe pain on your end-users.

    There are third-party form scaling solutions available that might help:

    A shareware version of a form rescaling module I wrote called ShrinkerStretcher is available at this web site: http://www.peterssoftware.com/ss.htm

    With ShrinkerStretcher, you don't need to make any form changes. You just open your forms with SS_OpenForm instead of DoCmd.OpenForm.

    FMS has a sizer module at www.fmsinc.com.

    The Access Developer's Handbook has form resizing code included:
    http://www.amazon.com/exec/obidos/IS...064361-7403703

    Hope this helps,

    Peter De Baets
    Peter's Software - MS Access Tools for Developers
    http://www.peterssoftware.com
    Peter De Baets
    Peter's Software - Microsoft Access Tools for Developers
    http://www.peterssoftware.com

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    Windows API/Global Declarations for Changing Windows Display Resolution.

    Place the code below into a Database Code Module:
    Code:
    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 typDevMODE
        dmDeviceNameAs String * CCDEVICENAME
        dmSpecVersion As Integer
        dmDriverVersionAs Integer
        dmSize As Integer
        dmDriverExtra As Integer
        dmFieldsAs Long
        dmOrientation As Integer
        dmPaperSizeAs Integer
        dmPaperLength As Integer
        dmPaperWidthAs Integer
        dmScaleAs Integer
        dmCopiesAs Integer
        dmDefaultSourceAs Integer
        dmPrintQuality As Integer
        dmColorAs Integer
        dmDuplexAs Integer
        dmYResolution As Integer
        dmTTOption As Integer
        dmCollate As Integer
        dmFormName As String * CCFORMNAME
        dmUnusedPaddingAs Integer
        dmBitsPerPelAs Integer
        dmPelsWidthAs Long
        dmPelsHeightAs Long
        dmDisplayFlags As Long
        dmDisplayFrequency As Long
     End Type
    
    Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" _
    (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lptypDevMode As Any) As Boolean
    
    Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" _
    (lptypDevMode As Any, ByVal dwFlags As Long) As Long
    
    Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved _
    As Long) As Long
    
    'A Function you can use.
    Public Function ChangeResolution(ByVal ScrnWidth as Integer, ByVal ScrnHeight as Integer)
        Dim typDevM As typDevMODE
        Dim lngResult As Long
        Dim intAnsAs Integer
        'Retrieve info about the current graphics mode
        'on the current display device.
        lngResult = EnumDisplaySettings(0, 0, typDevM)
        'Set the new resolution. Don't change the color
        'depth so a restart is not necessary.
    
        With typDevM
            .dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
            .dmPelsWidth = ScrnWidth    'Where ScrnWidth is either 640, 800, or 1024, etc.)
            .dmPelsHeight = ScrnHeight   'Where ScrnHeight is either 480, 600, or 768, etc.)
        End With
        'Change the display settings to the specified graphics mode.
        lngResult = ChangeDisplaySettings(typDevM, CDS_TEST)
    
        'Remove the MsgBox functions below if you like.
        Select Case lngResult
            Case DISP_CHANGE_RESTART
                 intAns = MsgBox("You must restart your computer to apply these changes." & _
                 vbCrLf & vbCrLf & "Do you want to restart now?", _
                 vbYesNo + vbQuestion, "Screen Resolution")
                 If intAns = vbYes Then Call ExitWindowsEx(EWX_REBOOT, 0)
            Case DISP_CHANGE_SUCCESSFUL
                 Call ChangeDisplaySettings(typDevM, CDS_UPDATEREGISTRY)
                 MsgBox "Screen resolution changed", vbInformation, "Resolution Changed"
            Case Else
                 MsgBox "Mode not supported", , "Error"
        End Select
    End Function
    Usage:

    Place the line below into the OnOpen event of your startup form...

    Call ChangeResolution(1024, 768)

    and

    place the line below into the OnClose event on any form that can
    end the database application...

    Call ChangeResolution(640, 480)

    etc...

    Hope this helps

  5. #5
    Join Date
    Nov 2003
    Posts
    66
    Hi all - Thanks for the replies.
    Sinking feeling I'm in over my head on this one!
    I'll take a look at the various links, but from what I've seen, seems I'm gettin into very codey territory.

    Briefly, Cyber, when I followed your instructions and pasted in the various bits of code and opened up my startup form, I got a compile error in line
    dmDeviceNameAs String * CCDEVICENAME
    saying a "(" was expected, and with the "*" highlighted. No idea what this means let alone how to fix it.....

    D

  6. #6
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    421
    I think the * should be an = sign as the ccdevicename is declared above.

    Either that or it should be an '

    Regards

  7. #7
    Join Date
    Nov 2003
    Posts
    66
    Thanks Namliam - that was it - a couple of other little changes and I stopped gettin the compile errors.

    It's certainly doin something, cos when I launch the DB I get an Access Application Error -

    The instruction at "0x779d9256" referenced memory at "0x00000038". The memory could not be "Read"

    Aaargh. Dunno whether to laugh or cry....!

    D

  8. #8
    Join Date
    Nov 2003
    Posts
    1,487
    Well, wasn't that a "DOH" thing to do (type errors - slap me upside the head)

    daver....I owe you and everyone else that has copied the previous code, a BIG apology. If I would have tried compiling the code myself, the typing errors would have stuck out like a sore thumb. Again, I apologise.

    The code does work people....and below I have supplied the corrected code. In some cases I did not have spaces between the parameter and the "AS" clause within the TYPE variable declaration (now corrected) and the very same problem within a dimensioned variable located in the 'ChangeResolution' Function (also now corrected). And yes...I tested it.

    The dmDeviceNameAs String * CCDEVICENAME is correct but notice that I did not put a space between dmDeviceName and As. There were a number of others like this as well. The line must read:

    dmDeviceName As String * CCDEVICENAME

    What is important here is that the all the constants are declared first. In the case for the line above, the code sample has CCDEVICENAME equal the value of 32 (Public Const CCDEVICENAME = 32). This would then have then been the same as typing:

    dmDeviceName As String * 32

    In any case.....it works. AND....daver....it's better to laugh than cry for life is far to short to start worring about VB code with real dumb errors in it.

    __________________________________________________ __________________________________

    Windows API/Global Declarations for Changing Windows Display Resolution.

    Place the code below into a Database Code Module:
    Code:
    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 typDevMODE
        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
    
    Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" _
    (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lptypDevMode As Any) As Boolean
    
    Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" _
    (lptypDevMode As Any, ByVal dwFlags As Long) As Long
    
    Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved _
    As Long) As Long
    
    'A Function you can use.
    Public Function ChangeResolution(ByVal ScrnWidth as Integer, ByVal ScrnHeight as Integer)
        Dim typDevM As typDevMODE
        Dim lngResult As Long
        Dim intAns As Integer
        'Retrieve info about the current graphics mode
        'on the current display device.
        lngResult = EnumDisplaySettings(0, 0, typDevM)
        'Set the new resolution. Don't change the color
        'depth so a restart is not necessary.
    
        With typDevM
            .dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
            .dmPelsWidth = ScrnWidth    'Where ScrnWidth is either 640, 800, or 1024, etc.)
            .dmPelsHeight = ScrnHeight   'Where ScrnHeight is either 480, 600, or 768, etc.)
        End With
        'Change the display settings to the specified graphics mode.
        lngResult = ChangeDisplaySettings(typDevM, CDS_TEST)
    
        'Remove the MsgBox functions below if you like.
        Select Case lngResult
            Case DISP_CHANGE_RESTART
                 intAns = MsgBox("You must restart your computer to apply these changes." & _
                 vbCrLf & vbCrLf & "Do you want to restart now?", _
                 vbYesNo + vbQuestion, "Screen Resolution")
                 If intAns = vbYes Then Call ExitWindowsEx(EWX_REBOOT, 0)
            Case DISP_CHANGE_SUCCESSFUL
                 Call ChangeDisplaySettings(typDevM, CDS_UPDATEREGISTRY)
                 MsgBox "Screen resolution changed", vbInformation, "Resolution Changed"
            Case Else
                 MsgBox "Mode not supported", , "Error"
        End Select
    End Function
    Usage:

    Place the line below into the OnOpen event of your startup form...

    Call ChangeResolution(1024, 768)

    and

    place the line below into the OnClose event on any form that can
    end the database application...

    Call ChangeResolution(640, 480)

    etc...

    PS: Here's a tip...Run the 'Compile And Save All Modules' menu item located under the 'Debug' menu before running your application. It can find almost all code errors which you can fix right away so as to prevent a application or system crash. Access itself does not do this.


  9. #9
    Join Date
    Nov 2003
    Posts
    66
    Not to worry bout the errors - that's one nifty piece of code!!!

    Couple o' finicky questions on it -

    1. when I was testing it, (ie machine set at 800 x 600, launch DB, get message 'Screen resolution has changed', OK, machine now at 1024 x 768 (sweet..!) )
    Database launches in a window, rather than at full screen. You have to click minimise, and then maximise in order to get the window at the correct size. Is this the way it's sposed to work?

    2. After closing down the DB, (I put the Call ChangeResolution (800 x 600) on the DB's Exit button, the machine reverts back to 800 x 600 fine, but I've lost the 'Start' Toolbar at the bottom of the screen. Did you find that?

    3. U think this would work ok on different OS's? Win95, Win98, NT4, Win2000?

    Sorry if I'm sounding anal, cyber, but if the user has to do ANY messing around in order to get the DB lookin OK in the new auto resolution they won't want this workaround and I'll have to redesign the frontend.....

    Cheers
    Dave

  10. #10
    Join Date
    Nov 2003
    Posts
    1,487
    Answer to 1) Thats the way the cookie crumbles You can, if you like, call the DoCmd.Maximize funtion within the OnOpen event of your startup form so that the form is automatically maximized when started.

    Answer to 2) I tested it with XP and all worked just fine. I can't really say why the Task bar vanishes (sorry).

    Answer to 3) Should work on all 32 bit (or Win32) Windows Operating systems and on all computers who's video and monitor support the resolution change you want to make. Make video drivers are updated (if real old).


  11. #11
    Join Date
    Nov 2003
    Posts
    66

    Nearly have it...

    Almost have it -

    Put in AppMinimize / AppMaximize in the same AutoExec that runs the change resolution command - gets rid of the small window, so the DB looks as though it's loaded in full screen.

    Only remaining problem now is that on opening the DB (after the auto res change) the Start menu bar appears in the middle of the screen and has to be manually dragged to the bottom of the screen in order to dock it.
    Any chance there's code out there that could be run to automatically dock the Start Menu bar in it's correct position when the resolution change is run?

    Cheers
    D

  12. #12
    Join Date
    Nov 2003
    Posts
    1,487
    The task bar should automatically dock for you, Check your Windows setup.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •