Solved

how to display version information in the title bar?

Posted on 2001-07-24
4
268 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 128
Expand data scrubbing tool 13 35
conditional code and condition difference 9 84
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 102
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

790 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