Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003

    Unanswered: How to get this little bit of code into this big bit of code...

    Hello all

    A while back Cyberlynx gave me a bit of code for changing screen resolution automatically on launching my DB (cheers m8).
    Have one problem with it though, that I just can't fix - on auto changing the resolution up to 1024 x 768 from 800 x 600, the Windows taskbar is undocked about a 3rd up the screen, and reduced in size. There'll be much moanage about this from the client

    I've since found code which I think may sort this out by repositioning the taskbar at the screen bottom, in 0,0 position. Problem is I'm still very much a coding novice, and any attempts I've made so far to get this into Cyber's code haven't worked.

    Could I ask someone who is arsed, and has the time, to take the bit for repositioning the taskbar, and show me how to place it within Cyberlynx's code?

    Both sets of code incuded below.......
    __________________________________________________ ________

    Big Resolution Bit.....

    Option Compare Database
    Option Explicit

    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_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
    .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)

    End Function

    ************************************************** *********

    Small Repositioning Bit..............

    ************************************************** *********
    Declare Function SetWindowPos Lib "user32" (ByVal hwnd _
    As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, _
    ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal _
    wFlags As Long) As Long

    Declare Function FindWindow Lib "user32" Alias _
    "FindWindowA" (ByVal lpClassName As String, ByVal _
    lpWindowName As String) As Long

    Const SWP_HIDEWINDOW = &H80
    Const SWP_SHOWWINDOW = &H40

    Code to Hide the Taskbar

    Dim Thwnd as Long
    Thwnd = FindWindow("Shell_traywnd", "")
    Call SetWindowPos(Thwnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)

    Code to Show the Taskbar

    Dim Thwnd as Long
    Thwnd = FindWindow("Shell_traywnd", "")
    Call SetWindowPos(Thwnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)

    ************************************************** **********

  2. #2
    Join Date
    Nov 2003
    For the sake of closure on this (for me, if nothing else!) and in case anybody needs to do this in the future, in the change resolution code, instead of

    lngResult = ChangeDisplaySettings(typDevM, CDS_TEST)


    lngResult = ChangeDisplaySettings(typDevM, CDS_UPDATEREGISTRY)

    solves the problem of the undocked taskbar - no need for the code to redock it......


Posting Permissions

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