dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Changing the Screen Resolution through VB

  1. #1
    Join Date
    Mar 2006
    Posts
    41

    Thumbs up Changing the Screen Resolution through VB

    hi Gurus,

    i am putting the code as:

    Code:
    'Including system library file
    Public Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    
    'This is the small program to identify the screen resolution
    'if resolution is less then 800x600
    '~~~~~~~~~~~~~~~~~
    Private Function IsValidScreenResolution() As Boolean
    
    Dim intWidth, intHeight As Integer
    
    intWidth = GetSystemMetrics(SM_CXSCREEN)
    intHeight = GetSystemMetrics(SM_CYSCREEN)
    
    If (intWidth < 800) Or (intHeight < 600) Then
    MsgBox "Screen resolution is less then 800 x 600"
    Else
    IsValidScreenResolution = True
    End If
    End Function
    '''~~~~~~~~~~~~~~~~~
    
    Private Sub Form_Load()
    
    Call IsValidScreenResolution
    
    End Sub
    But, when i Run the program, it is giving me Compile Error saying:

    "Constants, fixed-length strings, arrays, user-defined types and declare statements not allow as Public members of object modules."

    Then i removed the 'Public' from the declaring statement. Still, its not working.

    Also, i want to change the machine's resolution to 1280 x 1024, irrespective of the current machine's resolution.

    can u help me to do this ?

    thanx in adv.

    -@shik143.
    Last edited by WizBang; July 26th, 2007 at 06:16 AM. Reason: Added [code] tags

  2. #2
    Join Date
    Mar 2006
    Posts
    41

    Re: Changing the Screen Resolution through VB

    Quote Originally Posted by ashik143
    hi Gurus,

    i am putting the code as:

    Code:
    'Including system library file
    Public Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    
    'This is the small program to identify the screen resolution
    'if resolution is less then 800x600
    '~~~~~~~~~~~~~~~~~
    Private Function IsValidScreenResolution() As Boolean
    
    Dim intWidth, intHeight As Integer
    
    intWidth = GetSystemMetrics(SM_CXSCREEN)
    intHeight = GetSystemMetrics(SM_CYSCREEN)
    
    If (intWidth < 800) Or (intHeight < 600) Then
    MsgBox "Screen resolution is less then 800 x 600"
    Else
    IsValidScreenResolution = True
    End If
    End Function
    '''~~~~~~~~~~~~~~~~~
    
    Private Sub Form_Load()
    
    Call IsValidScreenResolution
    
    End Sub
    But, when i Run the program, it is giving me Compile Error saying:

    "Constants, fixed-length strings, arrays, user-defined types and declare statements not allow as Public members of object modules."

    Then i removed the 'Public' from the declaring statement. Still, its not working.

    Also, i want to change the machine's resolution to 1280 x 1024, irrespective of the current machine's resolution.

    can u help me to do this ?

    thanx in adv.

    -@shik143.
    Hello Gurus,

    The code worked for me. I just changed the 'Public' to 'Private' in the Defination Line. That's it.

    But, now, i want to change the Resolution to 1280 x 1024. How is it possible?

    Thanx in adv.
    -@shik143

  3. #3
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Changing the Screen Resolution through VB

    I would not be the only one to suggest that it isn't recommended to alter user settings, even if you'll be setting them back upon exiting. Your app may not be the only one running. Of course, if your app isn't for wide distribution, it may not be quite as much an issue.

    Perhaps if you can describe why you want to change the resolution, we might be able to suggest an alternative method of accomplishing the desired effect.

    Anyway, here's an example of how to change screen resolution:
    http://www.freevbcode.com/ShowCode.asp?ID=4187
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)