Solved

how to display version information in the title bar?

Posted on 2001-07-24
4
235 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
Comment Utility
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
Comment Utility
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 30

Expert Comment

by:Zoppo
Comment Utility
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
Comment Utility
very neat. other experts also provide very good solution. thanks all!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now