Resolution Independent Application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vdraceil
    New Member
    • Jul 2007
    • 236

    Resolution Independent Application

    Hi..i work with vb6.I've created an application in 1024*768 resolution.When it is run in 1280*728 resolution,the controls in it are misaligned(not exactly as what i designed).
    Does anyone know how to make my app. resolution independent?
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    you need to handle all that at the start up. you can resize the form as per the monitor resolution and reposition controls accordingly.

    Comment

    • lotus18
      Contributor
      • Nov 2007
      • 865

      #3
      Originally posted by vdraceil
      Hi..i work with vb6.I've created an application in 1024*768 resolution.When it is run in 1280*728 resolution,the controls in it are misaligned(not exactly as what i designed).
      Does anyone know how to make my app. resolution independent?
      You need to declare APIs for that.

      Code:
      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 LongPrivate Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
      Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
      Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Any) As Long
      Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
      Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long
      For getting the current screen resolution
      Code:
      Private OldX As Long
      Private OldY As Long
      Private nDC As Long
      Set your constant screen resolutions' width and height

      Code:
      Private Const ScreenWidth As Long = 1024
      Private Const ScreenHeight  As Long = 768
      Implementation. Note: I set my Startup Object as Sub Main()
      Code:
      Public Sub Main()
          'Check if the system is already running
          If App.PrevInstance = True Then
              MsgBox "Cannot run the program. System is already running.", 64
              End
          End If
          'Get the current screen resolutions' width and height
          OldX = Screen.Width / Screen.TwipsPerPixelX
          OldY = Screen.Height / Screen.TwipsPerPixelY
      
          'Check if it is equal to your defined resolution
          If OldX = ScreenWidth And OldY = ScreenHeight Then
              <Show your first form here>
          Else
              If MsgBox("The program can be best viewed in 1024x768 " & _
              "resolution. Some forms and controls may not be properly displayed if you " & _
              "click No. In order to maintain the system's performance, it is " & _
              "recommended to change the resolution. " & vbCrLf & vbCrLf & "Do " & _
              "you want to change the current screen resolution? Click Yes to " & _
              "change, or No otherwise.", 32 + 4, "Change Screen Resolution") = 6 Then
                  'Create a device context, compatible with the screen
                  nDC = CreateDC("DISPLAY", vbNullString, vbNullString, ByVal 0&)
                  'Change the screen's resolution
                  ChangeRes ScreenWidth, ScreenHeight, GetDeviceCaps(nDC, BITSPIXEL)
              <Show your first form here>
              End If
          End If
      End Sub
      For retrieving back to its original resolution, you need to declare a Public Sub routine when your main or last form has been unloaded.


      Rey Sean

      Comment

      Working...