wxGetOsDescription() in Windows 7. Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
scriptdaemon
Experienced Solver
Experienced Solver
Posts: 93
Joined: Sun Mar 15, 2009 10:28 pm

wxGetOsDescription() in Windows 7.

Post by scriptdaemon »

I don't have the Windows 7 release candidate, so all I'm asking is what would the string returned from wxGetOsDescription() look like under Windows 7? A friend of mine has it but is not currently on for me to ask.
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan »

Windows NT 6.1 (build 7xxx)
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

wxWidgets 2.8.9 doesn't know about Windows 7 yet, so it reports Windows NT 6.1.

But if you want to implement some OS specific code you should better use the OS version numbers from wxGetOsVersion() anyway.

6.0 = Vista
6.1 = Windows 7
Use the source, Luke!
scriptdaemon
Experienced Solver
Experienced Solver
Posts: 93
Joined: Sun Mar 15, 2009 10:28 pm

Post by scriptdaemon »

doublemax wrote:wxWidgets 2.8.9 doesn't know about Windows 7 yet, so it reports Windows NT 6.1.

But if you want to implement some OS specific code you should better use the OS version numbers from wxGetOsVersion() anyway.

6.0 = Vista
6.1 = Windows 7
I have three questions then:

1. What makes wxGetOsVersion() better than wxGetOsDescription() for this?

2. If it is instead recommended that I use wxGetOsVersion(), what version is XP? (5.0?)

3. On official release of 7, will it still remain 6.1 or will it be brought up to 7.0?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

1. What makes wxGetOsVersion() better than wxGetOsDescription() for this?
i think it's more reliable to compare integers than to compare strings
2. If it is instead recommended that I use wxGetOsVersion(), what version is XP? (5.0?)
5.0 = Windows 2000
5.1 = Windows XP
3. On official release of 7, will it still remain 6.1 or will it be brought up to 7.0?
i don't know, but i believe not

http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Use the source, Luke!
scriptdaemon
Experienced Solver
Experienced Solver
Posts: 93
Joined: Sun Mar 15, 2009 10:28 pm

Post by scriptdaemon »

Since they're the same version, how similar are Windows Server 2008 and Windows Vista (and the others that share the same version numbers)?

I doubt anyone would be running my program on a server, but I still want to make sure if I code something for Vista it'll act the exact same in Windows Server.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

in don't know Windows Server 2008, but if it has the same version number as Vista, i'd expect it to support the same API functions, and that's what probably matters.
Use the source, Luke!
scriptdaemon
Experienced Solver
Experienced Solver
Posts: 93
Joined: Sun Mar 15, 2009 10:28 pm

Post by scriptdaemon »

doublemax wrote:in don't know Windows Server 2008, but if it has the same version number as Vista, i'd expect it to support the same API functions, and that's what probably matters.
Actually, my program cycles through an image folder and displays the images as the background. I'm using this to determine the default pictures folder in each OS.

Code: Select all


/**
 * Returns the path to the default pictures directory for the current
 * operating system
 *
 * @return Returns the default pictures directory path
 */
/* static */ const wxString CWindowsApi::GetPicturesPath()
{
    wxString szPicturesPath = wxGetHomeDir();

    // Set the default pictures directory for Windows XP
    if (wxGetOsDescription().Contains(wxT("Windows XP"))) {
        szPicturesPath += wxT("\\My Documents\\My Pictures");
    }

    // Set the default pictures directory for Windows Vista and Windows 7
    else if (wxGetOsDescription().Contains(wxT("Windows Vista")) ||
             wxGetOsDescription().Contains(wxT("Windows NT 6.1")))
    {
        // The path in Windows 7 leads to the directory "Pictures," though
        // it displays as "My Pictures" to the user
        szPicturesPath += wxT("\\Pictures");
    }
    return szPicturesPath;
}

User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

while this may work in most cases, it's better to ask the OS for the specific path.

Win32 API has SHGetFolderLocation for that.

Here's a small snippet from wxStandardPaths::DoGetDirectory() (which is protected, so you can't use it directly):

Code: Select all

#include <wx/msw/wrapshl.h>
wxString winGetSpecialFolderLocation(int cidl)
{
  wxString dir;
  LPITEMIDLIST pidl;
  HRESULT hr = SHGetSpecialFolderLocation(NULL, cidl, &pidl);

  if ( SUCCEEDED(hr) ) {
    // creating this temp object has (nice) side effect of freeing pidl
    dir = wxItemIdList(pidl).GetPath();
  }
  return dir;
}
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
The cidl for your purpose is CSIDL_MYPICTURES.
Use the source, Luke!
scriptdaemon
Experienced Solver
Experienced Solver
Posts: 93
Joined: Sun Mar 15, 2009 10:28 pm

Post by scriptdaemon »

Well, that helps a lot. I didn't even think of that, thanks.
Post Reply