langload.cpp

来自「在windows的资源文件中使用多语言从而实现多语言支持」· C++ 代码 · 共 58 行

CPP
58
字号
// sample showing how to use language IDs and LoadString
//
// (C) Copyright 1999 by Mike Blaszczak
// written on 18 October, 1999 for Visual C++ 6.0

// regular headers...

#include <windows.h>
#include <stdio.h>

// plus our own header to get the definition of the ID in our resource

#include "langload.h"

#if defined(_UNICODE) || defined(UNICODE)
#error I didn't write this sample to support Unicode.
#endif

void main()
{
   // save the old locale
   LCID oldLCID = GetThreadLocale();

   TCHAR sz[1024];

   // try to load the English string

   SetThreadLocale(
      MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));

   int nLoaded = LoadString(GetModuleHandle(NULL), IDS_COWS, sz, 1024);
   if (nLoaded > 0)
   {
      printf("LoadString worked!\n");
      printf("%s\n", sz);
   }
   else
      printf("LoadString failed: %d\n", GetLastError());

   // try to load the French string

   SetThreadLocale(
      MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH), SORT_DEFAULT));

   nLoaded = LoadString(GetModuleHandle(NULL), IDS_COWS, sz, 1024);
   
   if (nLoaded > 0)
   {
      printf("LoadString worked!\n");
      printf("%s\n", sz);
   }
   else
      printf("LoadString failed: %d\n", GetLastError());

   // set the old LCID one back
   SetThreadLocale(oldLCID);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?