Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Save screen resolution in an .ini file (w95, w2000, vb6)

    How do I save the user's screen rez height and width so I can use it when they open my vb program the next time? I know i have to save it in an .ini file but have no idea how to do it. Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Save screen resolution in an .ini file (w95, w2000, vb6)

    Take a look at this post for some routines that read and write to an .ini file. In that case it's printer information, but you can adapt it for your needs.

    Another alternative is to use SaveSetting and GetSetting to create and read a registry key , which is much simpler but can't be migrated to another machine the way an .ini file can.
    Charlotte

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Save screen resolution in an .ini file (w95, w2000, vb6)

    There's no point in saving those values.

    The user can change those at will. You have to determine the values each time you need to use them.
    Tho unlikely, a user might even change the screen resolution while a macro is running.

  4. #4
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Save screen resolution in an .ini file (w95, w2000, vb6)

    believe it or not my users wouldn't know how to change their resolution. <img src=/S/doh.gif border=0 alt=doh width=15 height=15>

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Save screen resolution in an .ini file (w95, w2000, vb6)

    Perhaps, but your code needs to account for that day.

  6. #6
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Jeddah, Saudi Arabia
    Posts
    243
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Save screen resolution in an .ini file (w95, w2000, vb6)

    I agree with Howard. Why store those values when the .Height and .Width properties of the Screen object return the values you need. After all, if you store them you have to retrieve them and that is a lot more work than using the Height and Width properties of the Screen object.

    Regards,

    Kevin Bell

  7. #7
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Save screen resolution in an .ini file (w95, w2000, vb6)

    ok, yes now i see. After the user resizes their window i want to save the height and width and use the next time they open the program. I looked up code on saving to an .ini file but don't understand it. I just want to save it somehow in my vb6 program so when the user opens the program up the window will be the same size as when they closed it. thanks for all the posts and the help

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Save screen resolution in an .ini file (w95, w2000, vb6)

    IT's deeper than that.

    You do not want to SAVE those values, rather, you need to have your code set up to automagically react to screen resolution changes.

    The user might change the screen resolution whilst the macro is running. Whilst this may not happen often, you need to take this into account.

    Look into the Resize event.

  9. #9
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Save screen resolution in an .ini file (w95, w2000, vb6)

    ok, that i can do. now it makes sense thanks for hanging in there with me to explain. <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15>

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Save screen resolution in an .ini file (w95, w2000, vb6)

    Actually, I think the program needs to save both sets of values, user's desired window size and user's screen resolution, to make future adjustments possible. I do think it's a good idea to save it in an .ini file. We have an application that saves screen coordinates in an Access database with all its other data, and every now and again the window will disappear offscreen due to some faulty program logic applied to extra-high resolution displays. I have to open the table in Excel to fix the data to avoid upconverting the data file to the latest version of Access. One shouldn't have to do that; .ini file good.

  11. #11
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Save screen resolution in an .ini file (w95, w2000, vb6)

    Saving the values is of no use.
    The macro has to check the resolutiion when it is running.

    The programmer has to include the design time resolution within the code, ie., the resolution on whatever system the code was written.

    Size is then adjusted at run-time whenever the macro runs.

    This topic is covered in a number of VB and Access programming books.

    I know that Ken Getz covers this in his Access programming books and, I believe, that Gary Cornell addresses the issue in Visual Basic 6 from the Ground Up.

  12. #12
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Save screen resolution in an .ini file (w95, w2000, vb6)

    Yes, the developer must size the window the first time, that's beyond dispute, but I think the original request was to save the user's modified window size preferences for future start-ups, and to adjust those as necessary if the screen resolution were to shrink.

  13. #13
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Save screen resolution in an .ini file (w95, w2000, vb6)

    The request specifically referred to "screen rez".

  14. #14
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Save screen resolution in an .ini file (w95, w2000, vb6)

    I refer you to <!post=Post #129209,129209>Post #129209<!/post>.

  15. #15
    Star Lounger
    Join Date
    Jan 2001
    Location
    L.A., California
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Save screen resolution in an .ini file (w95, w2000, vb6)

    I noticed nobody actually answered your question,
    rather explained why you would or wouldn't want to do
    what you want to do. Here's a couple of routines
    which should help.

    <pre>Private Declare Function GetPrivateProfileString Lib "kernel32" _
    Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
    ByVal lpKeyName As Any, ByVal lpDefault As String, _
    ByVal lpReturnedString As String, _
    ByVal nSize As Long, ByVal lpFileName As String) As Long
    Private Declare Function WritePrivateProfileString Lib "kernel32" _
    Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
    ByVal lpKeyName As Any, ByVal lpString As Any, _
    ByVal lpFileName As String) As Long

    Function ReadIni(IniFile As String, _
    Section As String, _
    Key As String, _
    Optional Default As String = "", _
    Optional TrimSemicolon As Boolean = True, _
    Optional TrimSpaces As Boolean = True) _
    As String

    'Reads and returns data from <IniFile>,
    ' using <Section> and <Key> to find item.
    'If item not found, <Default> is returned.
    'If <TrimSemicolon> is not sent, or sent as
    ' True, any text following ";" is removed.
    'If <TrimSpaces> is not sent, or sent as
    ' True, any trailing blank spaces are removed.

    Dim lBufSize As Long
    Dim sBuffer As String
    Dim lSize As Long

    lBufSize = 2048
    sBuffer = Space$(lBufSize)

    'Retrieve the string
    lSize = GetPrivateProfileString(Section, _
    Key, _
    Default, _
    sBuffer, _
    lBufSize, _
    IniFile)

    sBuffer = Left$(sBuffer, lSize)

    If TrimSemicolon And InStr(1, sBuffer, ";") > 0 Then
    sBuffer = Left$(sBuffer, _
    InStr(1, sBuffer, ";") - 1)
    End If

    If TrimSpaces Then
    sBuffer = RTrim$(sBuffer)
    End If

    ReadIni = sBuffer

    End Function

    Sub WriteIni(IniFile As String, _
    Section As String, _
    Key As String, _
    Value As String)

    'Writes <Value> to <IniFile>,
    ' in <Section>, using <Key>=<Value> format.
    'If <Section> doesn't exist, it is added.
    'Verifies <IniFile>, <Section> & <Key> are
    ' valid, but allows blank <Value>.

    If Dir$(IniFile) > "" _
    And Section > "" _
    And Key > "" Then

    WritePrivateProfileString Section, Key, Value, IniFile
    endif

    End Sub
    </pre>


    Feel free to e-mail with questions.

Page 1 of 2 12 LastLast

Posting Permissions

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