using multiple-language resource script

From: alexander chupeev (someone_at_somewhere.com)
Date: 06/04/04


Date: Fri, 4 Jun 2004 20:19:00 +0600

Hi,

I wrote a resource script with menu resources duplicated on several
languages. MSDN states that I can control loading appropriate version of
resource using SetThreadLocale() call, but this way doesn't work. Operating
system always loads English version of menus in spite of what thread locale
I'm using. Can you tell me what's wrong? I'm working with Windows XP SP1.

------------- sh ./eg.sh ------------------
#!/bin/sh
cat > generic.c << EOF
#include <windows.h>
#include <tchar.h>
#include <windowsx.h>

#define NAMESTART 16

WNDPROC Listbox_WindowProc;

BOOL CALLBACK Enumres_EnumProc(HMODULE hModule, \
  LPCTSTR lpszType, LPCTSTR lpszName, LANGID wIDLanguage, LPARAM lParam)
{
  TCHAR szItemText[NAMESTART + MAX_PATH];
  HWND* hwnd = (HWND*) lParam;
  wsprintf(szItemText, TEXT("%#03x %#03x - "), PRIMARYLANGID(wIDLanguage),
SUBLANGID(wIDLanguage));
  if (0 < GetModuleFileName(hModule, &szItemText[lstrlen(szItemText)],
MAX_PATH))
  {
    ListBox_AddString(*hwnd, szItemText);
  }
  return (GetLastError() == ERROR_SUCCESS? TRUE: FALSE);
}

void Enumres_OnDestroy(HWND hwnd)
{
  SetWindowLong(hwnd, GWL_WNDPROC, (LONG) Listbox_WindowProc);
  PostQuitMessage(0);
}

LRESULT CALLBACK Enumres_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
  switch (uMsg)
  {
  case WM_DESTROY:
    HANDLE_WM_DESTROY(hwnd, wParam, lParam, Enumres_OnDestroy);
    break;
  default:
    return Listbox_WindowProc(hwnd, uMsg, wParam, lParam);
  }
  return 0;
}

BOOL InitInstance(int nCmdShow)
{
 LCID dwCurrLocale = MAKELCID(MAKELANGID(LANG_RUSSIAN, SUBLANG_DEFAULT),
SORT_DEFAULT);
  if (SetThreadLocale(dwCurrLocale))
  {
    HMENU menu = LoadMenu(NULL, TEXT("GENERIC"));
    if (menu)
    {
      HWND hwnd = CreateWindow(
        TEXT("LISTBOX"), // name of window class
        TEXT("Enumres"), // title-bar string
        WS_OVERLAPPEDWINDOW, // top-level window
        CW_USEDEFAULT, // default horizontal position
        CW_USEDEFAULT, // default vertical position
        CW_USEDEFAULT, // default width
        CW_USEDEFAULT, // default height
        NULL, // no owner window
        menu, // required menu
        NULL, // handle to application instance
        (LPVOID) NULL); // no window-creation data
      if (hwnd)
      {
        Listbox_WindowProc = (WNDPROC) SetWindowLong(hwnd, GWL_WNDPROC,
(LONG) Enumres_WindowProc);
        if (EnumResourceLanguages(NULL, RT_MENU, TEXT("GENERIC"),
Enumres_EnumProc, (LPARAM) &hwnd))
        {
          ShowWindow(hwnd, nCmdShow);
          UpdateWindow(hwnd);
          return TRUE;
        }
      }
    }
  }
  return FALSE;
}

int WINAPI _tWinMain(HINSTANCE hCurrInst, HINSTANCE hPrevInst, LPTSTR
lpCmdLine, int nCmdShow)
{
  if (InitInstance(nCmdShow))
  {
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
    return ((int) msg.wParam);
  }
  return 0;
  DBG_UNREFERENCED_PARAMETER(hPrevInst);
  DBG_UNREFERENCED_PARAMETER(lpCmdLine);
}
EOF
cat > resource.h << EOF
#define ID_FILE_NEW 100
#define ID_FILE_OPEN 101
#define ID_FILE_SAVE 102
#define ID_FILE_SAVE_AS 103
#define ID_FILE_PRINT 104
#define ID_FILE_PRINT_SETUP 105
#define ID_FILE_EXIT 106

#define ID_EDIT_UNDO 200
#define ID_EDIT_CUT 201
#define ID_EDIT_COPY 202
#define ID_EDIT_PASTE 203
#define ID_EDIT_LINK 204

#define ID_HELP_CONTENTS 300
#define ID_HELP_SEARCH 301
#define ID_HELP_HELP 302
#define ID_HELP_ABOUT 303
#define ID_HELPTOPICS 304
EOF
cat > generic.rc << EOF
#include "windows.h"
#include "winver.h"
#include "resource.h"

LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT

////////////////////////////////////////////////////////////////////////////
/
//
// Menu
//

GENERIC MENU
BEGIN
    POPUP "&Файл"
    BEGIN
        MENUITEM "Созд&ать\tCtrl+N", ID_FILE_NEW, GRAYED
        MENUITEM "&Открыть...\tCtrl+O", ID_FILE_OPEN, GRAYED
        MENUITEM "&Сохранить\tCtrl+S", ID_FILE_SAVE, GRAYED
        MENUITEM "Сохранить &как...", ID_FILE_SAVE_AS, GRAYED
        MENUITEM SEPARATOR
        MENUITEM "&Печать...\tCtrl+P", ID_FILE_PRINT, GRAYED
        MENUITEM "Пара&метры страницы...", ID_FILE_PRINT_SETUP, GRAYED
        MENUITEM SEPARATOR
        MENUITEM "В&ыход\tAlt+X", ID_FILE_EXIT
    END
    POPUP "&Правка"
    BEGIN
        MENUITEM "&Отменить\tCtrl+Z", ID_EDIT_UNDO, GRAYED
        MENUITEM SEPARATOR
        MENUITEM "&Вырезать\tCtrl+X", ID_EDIT_CUT, GRAYED
        MENUITEM "&Копировать\tCtrl+C", ID_EDIT_COPY, GRAYED
        MENUITEM "&Вставить\tCtrl+V", ID_EDIT_PASTE, GRAYED
        MENUITEM "Ссы&лка", ID_EDIT_LINK, GRAYED
    END
    POPUP "&Справка"
    BEGIN
        MENUITEM "&Содержание", ID_HELP_CONTENTS, HELP
        MENUITEM "&Предметный указатель...", ID_HELP_SEARCH, HELP
        MENUITEM "О сп&равочной системе", ID_HELP_HELP, HELP
        MENUITEM SEPARATOR
        MENUITEM "&О программе...", ID_HELP_ABOUT
    END
END

LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US

////////////////////////////////////////////////////////////////////////////
/
//
// Menu
//

GENERIC MENU
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "&New\tCtrl+N", ID_FILE_NEW, GRAYED
        MENUITEM "&Open...\tCtrl+O", ID_FILE_OPEN, GRAYED
        MENUITEM "&Save\tCtrl+S", ID_FILE_SAVE, GRAYED
        MENUITEM "Save &As...", ID_FILE_SAVE_AS, GRAYED
        MENUITEM SEPARATOR
        MENUITEM "&Print...\tCtrl+P", ID_FILE_PRINT, GRAYED
        MENUITEM "P&rint Setup...", ID_FILE_PRINT_SETUP, GRAYED
        MENUITEM SEPARATOR
        MENUITEM "E&xit\tAlt+X", ID_FILE_EXIT
    END
    POPUP "&Edit"
    BEGIN
        MENUITEM "&Undo\tCtrl+Z", ID_EDIT_UNDO, GRAYED
        MENUITEM SEPARATOR
        MENUITEM "Cu&t\tCtrl+X", ID_EDIT_CUT, GRAYED
        MENUITEM "&Copy\tCtrl+C", ID_EDIT_COPY, GRAYED
        MENUITEM "&Paste\tCtrl+V", ID_EDIT_PASTE, GRAYED
        MENUITEM "Paste &Link", ID_EDIT_LINK, GRAYED
    END
    POPUP "&Help"
    BEGIN
        MENUITEM "&Contents", ID_HELP_CONTENTS, HELP
        MENUITEM "&Search for Help On...", ID_HELP_SEARCH, HELP
        MENUITEM "&How to Use Help", ID_HELP_HELP, HELP
        MENUITEM SEPARATOR
        MENUITEM "&About Generic...", ID_HELP_ABOUT
    END
END
EOF
rc generic.rc
cl /nologo /MDd /Zi /D_UNICODE /DUNICODE generic.c generic.res user32.lib



Relevant Pages

  • Re: Multilangual : how to?
    ... I use Binary compatible resource dll's for each of my languages. ... > it should load, load it and then get the messages into ... > I could also use a database and have a language table, ... > recompile, but the matter of distribution is still an issue. ...
    (microsoft.public.vb.general.discussion)
  • Re: UNICODE Resourcen edieren
    ... system locale to the language you are trying to edit. ... wenn ich meinen deutschen WinXPproSP2 wie beschrieben auf japanisch stelle ... Immerhin bekommen die Resourcen beim auf Japanisch gestellten Rechner eine ... Eine richtige wird vom Visual Studio Resource ...
    (microsoft.public.de.vc)
  • Re: Anyone know what diff languages of resources makes?
    ... So the resource language is used to determine which resources are loaded, ... suspect you might see a different issue if you had French and English. ... Properties for any resource they all have a Language setting. ...
    (microsoft.public.vc.mfc)
  • Re: How to switch language on the runtime in asp.net2
    ... which means in order to switch the language, I have to put information somewhere, then resubmit ... The InitializeCulture method is called very early in the page life cycle, ... I just did a trace, actually the resource is retrieved even before the "Begin PreInit" event, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: internationalisation
    ... So, for dialogs, we keep all of a projects dialogs in the exe rather than ... separate copies in each language dll. ... It shows you how to build dialogs without resource files. ...
    (microsoft.public.vc.mfc)