Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. MS, you funny!

MS, you funny!

Scheduled Pinned Locked Moved The Weird and The Wonderful
helpc++visual-studiocomjson
16 Posts 8 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David ONeil
    wrote on last edited by
    #1

    Poking around, MS doesn't want you to use GetSaveFileName anymore. Instead, they want you to use the 'Common Item Dialog'. So click on that page, and find a function with 11 indentation levels! Copy and paste it, to find that it is part of a sample code, and relies on other functions in that sample. Try to download the sample, and the page isn't found. But you can download an SDK which supposedly contains the sample? Try to run it, though, and you will get a 'Some components cannot be installed' error, and no indication that the samples are included in it. X| Oh MS, you funny! All this because I was trying to figure out a way to allow the user to save program configuration files in the user app work directory, and regular files wherever they wish, but MS, in their infinite non-wisdom, won't allow the directory to be changed using GetSaveFileName, because they believe you will only ever be dealing with one type of file for your application. :doh: (Of course, they have the same issue in MS Word, and other Office programs, because they store config files like macros in a special subdirectory until the user changes where they store them. Afterwards, the dialog will default to that special directory until after you change it once. At least that was the case the last time I played with macros in Word.) Double- :doh:

    The forgotten roots of science | C++ Programming | DWinLib

    M N D B 4 Replies Last reply
    0
    • D David ONeil

      Poking around, MS doesn't want you to use GetSaveFileName anymore. Instead, they want you to use the 'Common Item Dialog'. So click on that page, and find a function with 11 indentation levels! Copy and paste it, to find that it is part of a sample code, and relies on other functions in that sample. Try to download the sample, and the page isn't found. But you can download an SDK which supposedly contains the sample? Try to run it, though, and you will get a 'Some components cannot be installed' error, and no indication that the samples are included in it. X| Oh MS, you funny! All this because I was trying to figure out a way to allow the user to save program configuration files in the user app work directory, and regular files wherever they wish, but MS, in their infinite non-wisdom, won't allow the directory to be changed using GetSaveFileName, because they believe you will only ever be dealing with one type of file for your application. :doh: (Of course, they have the same issue in MS Word, and other Office programs, because they store config files like macros in a special subdirectory until the user changes where they store them. Afterwards, the dialog will default to that special directory until after you change it once. At least that was the case the last time I played with macros in Word.) Double- :doh:

      The forgotten roots of science | C++ Programming | DWinLib

      M Offline
      M Offline
      Marc Clifton
      wrote on last edited by
      #2

      This is why I use .NET :~

      Latest Article - A Concise Overview of Threads Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

      L D 2 Replies Last reply
      0
      • M Marc Clifton

        This is why I use .NET :~

        Latest Article - A Concise Overview of Threads Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        And you are sure that .net will serve you properly for the next ten years? From my Point of view you can use this or that, but you Need in any case to be prepared to adapt your code...

        It does not solve my Problem, but it answers my question

        1 Reply Last reply
        0
        • M Marc Clifton

          This is why I use .NET :~

          Latest Article - A Concise Overview of Threads Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

          D Offline
          D Offline
          David ONeil
          wrote on last edited by
          #4

          In .NET, can you create a program where the save file dialog will default to the user's AppData folder for files like .ini files, and then back to the user's regular folders for their regular files? (I doubt you can, because I think this is a limitation of MS believing they know better than us how programs should work, and overriding their dialogs to disable such use.) If I'm wrong, I'm not going to rewrite, but would be interested to know.

          The forgotten roots of science | C++ Programming | DWinLib

          J R 2 Replies Last reply
          0
          • D David ONeil

            In .NET, can you create a program where the save file dialog will default to the user's AppData folder for files like .ini files, and then back to the user's regular folders for their regular files? (I doubt you can, because I think this is a limitation of MS believing they know better than us how programs should work, and overriding their dialogs to disable such use.) If I'm wrong, I'm not going to rewrite, but would be interested to know.

            The forgotten roots of science | C++ Programming | DWinLib

            J Offline
            J Offline
            Jon McKee
            wrote on last edited by
            #5

            You'd have to write the logic to change the InitialDirectory[^] property based on file type but SaveFileDialog[^] may work for you.

            D 1 Reply Last reply
            0
            • D David ONeil

              Poking around, MS doesn't want you to use GetSaveFileName anymore. Instead, they want you to use the 'Common Item Dialog'. So click on that page, and find a function with 11 indentation levels! Copy and paste it, to find that it is part of a sample code, and relies on other functions in that sample. Try to download the sample, and the page isn't found. But you can download an SDK which supposedly contains the sample? Try to run it, though, and you will get a 'Some components cannot be installed' error, and no indication that the samples are included in it. X| Oh MS, you funny! All this because I was trying to figure out a way to allow the user to save program configuration files in the user app work directory, and regular files wherever they wish, but MS, in their infinite non-wisdom, won't allow the directory to be changed using GetSaveFileName, because they believe you will only ever be dealing with one type of file for your application. :doh: (Of course, they have the same issue in MS Word, and other Office programs, because they store config files like macros in a special subdirectory until the user changes where they store them. Afterwards, the dialog will default to that special directory until after you change it once. At least that was the case the last time I played with macros in Word.) Double- :doh:

              The forgotten roots of science | C++ Programming | DWinLib

              N Offline
              N Offline
              Nelek
              wrote on last edited by
              #6

              Save it in other place and then move the "closed" file there :rolleyes: ;P :laugh: :laugh:

              M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

              D 1 Reply Last reply
              0
              • N Nelek

                Save it in other place and then move the "closed" file there :rolleyes: ;P :laugh: :laugh:

                M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                D Offline
                D Offline
                David ONeil
                wrote on last edited by
                #7

                All well and good, until you want to load one of those files! :doh:

                The forgotten roots of science | C++ Programming | DWinLib

                1 Reply Last reply
                0
                • J Jon McKee

                  You'd have to write the logic to change the InitialDirectory[^] property based on file type but SaveFileDialog[^] may work for you.

                  D Offline
                  D Offline
                  David ONeil
                  wrote on last edited by
                  #8

                  Interesting. Thanks for the knowledge!

                  The forgotten roots of science | C++ Programming | DWinLib

                  1 Reply Last reply
                  0
                  • D David ONeil

                    In .NET, can you create a program where the save file dialog will default to the user's AppData folder for files like .ini files, and then back to the user's regular folders for their regular files? (I doubt you can, because I think this is a limitation of MS believing they know better than us how programs should work, and overriding their dialogs to disable such use.) If I'm wrong, I'm not going to rewrite, but would be interested to know.

                    The forgotten roots of science | C++ Programming | DWinLib

                    R Offline
                    R Offline
                    RickZeeland
                    wrote on last edited by
                    #9

                    That's correct, you can not save app.config settings in the application directory with C#. I have a simple fix which allows this using file based search and replace, if you want I can send you some code, just let me know :-\

                    D 1 Reply Last reply
                    0
                    • R RickZeeland

                      That's correct, you can not save app.config settings in the application directory with C#. I have a simple fix which allows this using file based search and replace, if you want I can send you some code, just let me know :-\

                      D Offline
                      D Offline
                      David ONeil
                      wrote on last edited by
                      #10

                      Please do, and I'll see if I can pound it into C++. :thumbsup:

                      The forgotten roots of science | C++ Programming | DWinLib

                      R 2 Replies Last reply
                      0
                      • D David ONeil

                        Please do, and I'll see if I can pound it into C++. :thumbsup:

                        The forgotten roots of science | C++ Programming | DWinLib

                        R Offline
                        R Offline
                        RickZeeland
                        wrote on last edited by
                        #11

                        I will post it tomorrow, as I don't have the source code at home :)

                        D 1 Reply Last reply
                        0
                        • R RickZeeland

                          I will post it tomorrow, as I don't have the source code at home :)

                          D Offline
                          D Offline
                          David ONeil
                          wrote on last edited by
                          #12

                          Cool! :thumbsup:

                          The forgotten roots of science | C++ Programming | DWinLib

                          1 Reply Last reply
                          0
                          • D David ONeil

                            Poking around, MS doesn't want you to use GetSaveFileName anymore. Instead, they want you to use the 'Common Item Dialog'. So click on that page, and find a function with 11 indentation levels! Copy and paste it, to find that it is part of a sample code, and relies on other functions in that sample. Try to download the sample, and the page isn't found. But you can download an SDK which supposedly contains the sample? Try to run it, though, and you will get a 'Some components cannot be installed' error, and no indication that the samples are included in it. X| Oh MS, you funny! All this because I was trying to figure out a way to allow the user to save program configuration files in the user app work directory, and regular files wherever they wish, but MS, in their infinite non-wisdom, won't allow the directory to be changed using GetSaveFileName, because they believe you will only ever be dealing with one type of file for your application. :doh: (Of course, they have the same issue in MS Word, and other Office programs, because they store config files like macros in a special subdirectory until the user changes where they store them. Afterwards, the dialog will default to that special directory until after you change it once. At least that was the case the last time I played with macros in Word.) Double- :doh:

                            The forgotten roots of science | C++ Programming | DWinLib

                            D Offline
                            D Offline
                            Dirk Bahle
                            wrote on last edited by
                            #13

                            Here is another page with more then 20 Sample code links that do not work: [Shell SDK Samples (Windows)](https://msdn.microsoft.com/en-us/library/windows/desktop/dd940376(v=vs.85).aspx#sample\_list) -> you have to click (for example):Automatic Jump List Sample -> Downloading the Sample -> You'll either end up with page not found or just the SDK Link I don't think its funny and certainly not helpful

                            1 Reply Last reply
                            0
                            • D David ONeil

                              Please do, and I'll see if I can pound it into C++. :thumbsup:

                              The forgotten roots of science | C++ Programming | DWinLib

                              R Offline
                              R Offline
                              RickZeeland
                              wrote on last edited by
                              #14

                              Here's my code, as you can see it's quite simple:

                              this.SaveSettings(Application.ExecutablePath + ".config");

                                  /// /// Save the application settings in .exe.config.
                                  /// 
                                  private void SaveSettings(string fileName)
                                  {
                                      string oldHostname = Properties.Settings.Default.HostnameUrl;
                                      string oldSipClients = Properties.Settings.Default.SipClients;
                                      string oldVersion = Properties.Settings.Default.LastExeVersion;
                              
                                      if (this.textBoxHostname.Text != oldHostname)
                                      {
                                          this.ConfigFileUpdate(fileName, "HostnameUrl", oldHostname, this.textBoxHostname.Text);
                                      }
                              
                                      if (this.textBoxSipClients.Text != oldSipClients)
                                      {
                                          this.ConfigFileUpdate(fileName, "SipClients", oldSipClients, this.textBoxSipClients.Text);
                                      }
                              
                                      if (string.Compare(this.newExeVersion, oldVersion) > 0)
                                      {
                                          this.ConfigFileUpdate(fileName, "LastExeVersion", oldVersion, this.newExeVersion);
                                      }
                                  }
                              
                                  /// /// Application config file can not be written to with Properties.Settings.Default, so do a file based replace.
                                  /// 
                                  private void ConfigFileUpdate(string fileName, string keyName, string searchstring, string replacestring)
                                  {
                                      try
                                      {
                                          if (string.IsNullOrEmpty(searchstring) || string.IsNullOrEmpty(replacestring))
                                          {
                                              return;
                                          }
                              
                                          searchstring = ">" + searchstring + "<";
                                          replacestring = ">" + replacestring + "<";
                                          string\[\] configLines = File.ReadAllLines(fileName);
                              
                                          for (int i = 10; i < configLines.Length; i++)
                                          {
                                              string linePrevious = configLines\[i - 1\];
                                              string line = configLines\[i\];
                              
                                              if (linePrevious.Contains(keyName) && line.Contains(searchstring))
                                              {
                                                  // Only replace the first line found
                                                  configLines\[i\] = line.Replace(searchstring, replacestring);
                                                  break;
                                              }
                                          }
                              
                                          File.WriteAllLines(fileName, configLines);
                                      }
                                      catch (Exception ex)
                                      {
                                          Debug.Print(ex.Message);
                                      }
                                  }
                              
                              D 1 Reply Last reply
                              0
                              • R RickZeeland

                                Here's my code, as you can see it's quite simple:

                                this.SaveSettings(Application.ExecutablePath + ".config");

                                    /// /// Save the application settings in .exe.config.
                                    /// 
                                    private void SaveSettings(string fileName)
                                    {
                                        string oldHostname = Properties.Settings.Default.HostnameUrl;
                                        string oldSipClients = Properties.Settings.Default.SipClients;
                                        string oldVersion = Properties.Settings.Default.LastExeVersion;
                                
                                        if (this.textBoxHostname.Text != oldHostname)
                                        {
                                            this.ConfigFileUpdate(fileName, "HostnameUrl", oldHostname, this.textBoxHostname.Text);
                                        }
                                
                                        if (this.textBoxSipClients.Text != oldSipClients)
                                        {
                                            this.ConfigFileUpdate(fileName, "SipClients", oldSipClients, this.textBoxSipClients.Text);
                                        }
                                
                                        if (string.Compare(this.newExeVersion, oldVersion) > 0)
                                        {
                                            this.ConfigFileUpdate(fileName, "LastExeVersion", oldVersion, this.newExeVersion);
                                        }
                                    }
                                
                                    /// /// Application config file can not be written to with Properties.Settings.Default, so do a file based replace.
                                    /// 
                                    private void ConfigFileUpdate(string fileName, string keyName, string searchstring, string replacestring)
                                    {
                                        try
                                        {
                                            if (string.IsNullOrEmpty(searchstring) || string.IsNullOrEmpty(replacestring))
                                            {
                                                return;
                                            }
                                
                                            searchstring = ">" + searchstring + "<";
                                            replacestring = ">" + replacestring + "<";
                                            string\[\] configLines = File.ReadAllLines(fileName);
                                
                                            for (int i = 10; i < configLines.Length; i++)
                                            {
                                                string linePrevious = configLines\[i - 1\];
                                                string line = configLines\[i\];
                                
                                                if (linePrevious.Contains(keyName) && line.Contains(searchstring))
                                                {
                                                    // Only replace the first line found
                                                    configLines\[i\] = line.Replace(searchstring, replacestring);
                                                    break;
                                                }
                                            }
                                
                                            File.WriteAllLines(fileName, configLines);
                                        }
                                        catch (Exception ex)
                                        {
                                            Debug.Print(ex.Message);
                                        }
                                    }
                                
                                D Offline
                                D Offline
                                David ONeil
                                wrote on last edited by
                                #15

                                Thanks!

                                The forgotten roots of science | C++ Programming | DWinLib

                                1 Reply Last reply
                                0
                                • D David ONeil

                                  Poking around, MS doesn't want you to use GetSaveFileName anymore. Instead, they want you to use the 'Common Item Dialog'. So click on that page, and find a function with 11 indentation levels! Copy and paste it, to find that it is part of a sample code, and relies on other functions in that sample. Try to download the sample, and the page isn't found. But you can download an SDK which supposedly contains the sample? Try to run it, though, and you will get a 'Some components cannot be installed' error, and no indication that the samples are included in it. X| Oh MS, you funny! All this because I was trying to figure out a way to allow the user to save program configuration files in the user app work directory, and regular files wherever they wish, but MS, in their infinite non-wisdom, won't allow the directory to be changed using GetSaveFileName, because they believe you will only ever be dealing with one type of file for your application. :doh: (Of course, they have the same issue in MS Word, and other Office programs, because they store config files like macros in a special subdirectory until the user changes where they store them. Afterwards, the dialog will default to that special directory until after you change it once. At least that was the case the last time I played with macros in Word.) Double- :doh:

                                  The forgotten roots of science | C++ Programming | DWinLib

                                  B Offline
                                  B Offline
                                  Bernhard Hiller
                                  wrote on last edited by
                                  #16

                                  David O'Neil wrote:

                                  and find a function with 11 indentation levels!

                                  One more reason to change to .Net. Where do these many circles of hell levels of indentation come from? The lack of a proper exception implementation in old-style C/C++. Just look:

                                  HResult hr;
                                  hr = /* some function call */;
                                  if (SUCCEEDED(hr))
                                  {
                                  hr = /* next function call etc. */;

                                  And in case of error, ... it does nothing. Just the user wonders why it does not work, the service hotline people will be delighted by not having any indication of why things do not work. C# would prefer to throw an exception in case of failure, and no need to handle each place of potential failure separately. Of course, catching the exception and - more importantly - handling it usefully, are still things the developer has to take care of (but it's rather easy).

                                  Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups