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

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Save screen resolution in an .ini file (w95, w2000, vb6)

    Author
    Topic
    #368957

    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

    Viewing 2 reply threads
    Author
    Replies
    • #579582

      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.

    • #579589

      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.

      • #579611

        believe it or not my users wouldn’t know how to change their resolution. doh

        • #579613

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

          • #579637

            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

            • #579666

              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

            • #579695

              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.

            • #579747

              ok, that i can do. now it makes sense thanks for hanging in there with me to explain. dizzy

            • #579786

              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.

            • #580004

              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.

            • #580084

              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.

            • #580111

              The request specifically referred to “screen rez”.

            • #580119

              I refer you to Post #129209.

    • #580532

      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.

      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 ,
      '  using 
      and to find item. 'If item not found, is returned. 'If is not sent, or sent as ' True, any text following ";" is removed. 'If 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 to , ' in
      , using = format. 'If
      doesn't exist, it is added. 'Verifies ,
      & are ' valid, but allows blank . If Dir$(IniFile) > "" _ And Section > "" _ And Key > "" Then WritePrivateProfileString Section, Key, Value, IniFile endif End Sub

      Feel free to e-mail with questions.

      • #580535

        thank you very much. i wonder if you could look at this post and see if you see anything obvious i’m doing wrong. thanks

        post # 129790

        • #580589

          Sorry, that’s not exactly my area. Besides, I don’t have a win95 box to test it on.

    Viewing 2 reply threads
    Reply To: Reply #579695 in Save screen resolution in an .ini file (w95, w2000, vb6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel