Get the version number of the program itself

zhaozj2021-02-16  66

Hello, Guys!

During your programing, you cald meet how to get your application's version of how to get the application's version from the vs_version_info resource.

First, You Should Make a Project Named Getversion from MFC AppWizard (Exe) Depends on Dialog!

Next, we create a butten control named idc_btn_getversion, it uss To get the application function.in this button, we add the function named getApplicationVersion (), IT Uses to get the application's version!

Before add the function, we shop add a library named version.lib, code just like:

#pragma comment (Lib, "Version.lib")

Now, we add the function named getApplicationVersion (), And no return value, Just Void Prefix.

This Function's Code, As Follows:

Tchar SzfullPath [MAX_PATH]; DWORD DWVERINFOSIZE = 0; DWORD DWVERHND; VS_FIXEDFILEINFO * PfileInfo;

GetModuleFileName (NULL, szFullPath, sizeof (szFullPath)); dwVerInfoSize = GetFileVersionInfoSize (szFullPath, & dwVerHnd); if (dwVerInfoSize) {// If we were able to get the information, process it: HANDLE hMem; LPVOID lpvMem; unsigned int uInfoSize = 0; HMEM = GLOBALLOC (GMEM_MOVEABLE, DWVERINFOSIZIZE); LPVMEM = Globalock (HMEM); GetFileVersionInfo (SzfullPath, DWverHnd, DWVERINFOSIZE, LPVMEM);

:: VerQueryValue (LPVMEM, (LPTSTSTSTR) _T ("//"), (void **) & pfileinfo, & uinfosize;

WORD m_nProdVersion [4]; // Product version from the FILEVERSION of the version info resource m_nProdVersion [0] = HIWORD (pFileInfo-> dwProductVersionMS); m_nProdVersion [1] = LOWORD (pFileInfo-> dwProductVersionMS); m_nProdVersion [2] = HIWORD (pfileinfo-> dwproductversionls); m_nprodversion [3] = loword (pfileinfo-> dwproductversionls); CString strVersion; strVersion.format (_T ("The file's version:% d.% d.% d.% d"), m_nprodversion [ 0], m_nprodversion [1], m_nprodversion [2], m_nprodversion [3]); GlobalUnlock (HMEM); GlobalFree (HMEM);

AfxMessageBox (STRVERSION);

}

IT's Very Easy, Do Not you think?

Compile:

VC6.0 VSP6 WinXP!

转载请注明原文地址:https://www.9cbs.com/read-19080.html

New Post(0)