Solved

how to display version information in the title bar?

Posted on 2001-07-24
4
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

724 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