现在的位置: 首页 > 综合 > 正文

获取当前运行(。。。。.exe)程序的路径

2013年05月06日 ⁄ 综合 ⁄ 共 1173字 ⁄ 字号 评论关闭

     char buf[MAX_PATH];

1. GetModuleFileName(NULL, buf, MAX_PATH);

2. LPTSTR的数据类型是(char *)(const char *);

3. 获取程序的版本信息

CString GetFileVersion(LPCTSTR szFileName)
{
  CString szVer;
 DWORD dwLen = GetFileVersionInfoSize((char*)(const char*)szFileName, 0);
 char * buf = new char[dwLen + 1];
 if(GetFileVersionInfo((LPTSTR)szFileName,0, dwLen, buf))
 {
  VS_FIXEDFILEINFO * lpInfo = NULL;
  try
  {
   VerQueryValue(buf,TEXT("\\"), (void**)&lpInfo, NULL);
   if(lpInfo)
   {
    szVer.Format(("%d.%d.%d.%d"),
     HIWORD(lpInfo->dwFileVersionMS),
     LOWORD(lpInfo->dwFileVersionMS),
     HIWORD(lpInfo->dwFileVersionLS),
     LOWORD(lpInfo->dwFileVersionLS));
   }  
  }
  catch(...){}
 }
 delete [] buf;

 return szVer;
}

4. 从左边截取多少个字符

CString::Left

// example for CString::Left
CString s( _T("abcdef") );
ASSERT( s.Left(2) == _T("ab") );

CString OverviewClass Members

5

CString::ReverseFind

int ReverseFind( TCHAR ch ) const;

Return Value

The index of the last character in this CString object that matches the requested character; –1 if the character is not found.

// Example for CString::ReverseFind
CString s( "abcabc" );
ASSERT( s.ReverseFind( 'b' ) == 4 );

 

6 获取系统(自定义)语言

 if(GetSystemDefaultLangID() == 0x0804)
 {
  SetThreadLocale(MAKELCID(LANGID_ZH_CN,SORT_DEFAULT));
  m_sysparam.m_nLanguageID=0;
 }

抱歉!评论已关闭.