Solved

how to display version information in the title bar?

Posted on 2001-07-24
4
259 Views
Last Modified: 2013-11-20
hi,

i have filled in version information in my rc file, how can i display the information at my application window's title bar?

i have search for a long while but still cannot find a direct way to do this.

thanks,

bun
0
Comment
Question by:bunwong
4 Comments
 

Expert Comment

by:abegnoche
ID: 6314646
here's the code that works for me. sorry I have no explanation for this, but looking at each api in msdn you should be able to understand what's going on.

    TCHAR szFilename[126] = "c:\\dev\\your_dll_here.dll";
    DWORD dwSize;
    DWORD dwZero;

     dwSize = ::GetFileVersionInfoSize(szFilename, &dwZero);

    // if version info exists
    if (dwSize)
    {
        char *pVersionInfo = new char[dwSize];
        char *pValue;
        UINT uValueLen;
        BOOL bRC;

        BOOL bRet = GetFileVersionInfo( szFilename, NULL, dwSize, pVersionInfo);
        if (!bRet)
            return;

        bRC = VerQueryValue(pVersionInfo,  
                            _TEXT("\\StringFileInfo\\040904B0\\FileVersion"),
                            (void  **) &pValue,
                            &uValueLen);

        if (bRC)
            MessageBox( pValue, "File Version", MB_OK|MB_ICONINFORMATION);

        delete [] pVersionInfo;
    }
0
 
LVL 3

Accepted Solution

by:
aphillips earned 100 total points
ID: 6315750
MFC should really provide this in it's templates, including displaying ti in the About box.

I use this function to get the version info as 4 strings.  You can then do with them as you wish including adding them to the mainframe window title.


#include <winver.h>

void GetExeVersion(CString &s1, CString &s2, CString &s3, CString &s4)
{
    // Get version of executable
    DWORD dummy;                                        // Version functions take parameters that do nothing?!
    size_t vi_size;                                     // Size of all version info
    void *buf;                                          // Buffer to hold all version info
    void *p_version;                                    // Holds ptr to product version string in buffer
    UINT len;                                           // Length of product version string

    if ((vi_size = ::GetFileVersionInfoSize(__argv[0], &dummy)) > 0 &&
        (buf = ::malloc(vi_size+1)) != NULL &&
        ::GetFileVersionInfo(__argv[0], dummy, vi_size, buf) &&
        ::VerQueryValue(buf, "\\StringFileInfo\\040904B0\\ProductVersion",
                        &p_version, &len) )
    {
        CString strProductVersion((LPCTSTR)p_version, len);
        ::free(buf);

        AfxExtractSubString(s1, strProductVersion, 0, ',');
        AfxExtractSubString(s2, strProductVersion, 1, ',');
        AfxExtractSubString(s3, strProductVersion, 2, ',');
        AfxExtractSubString(s4, strProductVersion, 3, ',');
        s1.TrimLeft();
        s2.TrimLeft();
        s3.TrimLeft();
        s4.TrimLeft();
    }
    else
    {
        s1.Empty();
        s2.Empty();
        s3.Empty();
        s4.Empty();
    }
}
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 6316270
Hi bunwong,

a friend of me once wrote a little hack to read version numbers from resources directly, maybe you want
to use this. Only problem I see is that the date-values are not set.

HRSRC      hRsrc = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);
if ( hRsrc != NULL )
{
 HGLOBAL hg = LoadResource(NULL, hRsrc);  
 if(hg != NULL)
 {
  char *pRes = (char *) LockResource(hg);
  VS_FIXEDFILEINFO *pVersion = (VS_FIXEDFILEINFO *) (pRes + 0x28); // this is a hack !!!

  // read infos from pVersion...

 }
}

hope that helps,

ZOPPO
0
 

Author Comment

by:bunwong
ID: 6317191
very neat. other experts also provide very good solution. thanks all!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 86
How to know only "File created" with EventLog 3 34
matchUp  challenge 9 108
sumHeights  challenge 17 70
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question