Ignore:
Timestamp:
Jan 7, 2011, 1:51:26 AM (15 years ago)
Author:
dmik
Message:

user32: Fixed incorrect code page translation of window title text (seen if the target window PM thread is already switched to the Windows ANSI code page as in case of windows created on threads other than main, like in Java). See #24.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/oslibwin.cpp

    r21463 r21544  
    3030#include "pmwindow.h"
    3131#include "initterm.h"
     32#include "codepage.h"
    3233
    3334#define DBG_LOCALLOG    DBG_oslibwin
     
    574575BOOL OSLibWinSetTitleBarText(HWND hwnd, LPSTR lpsz)
    575576{
    576   return WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), lpsz);
     577    // convert character code if needed (normally, only on the main
     578    // thread since Win32ThreadProc() sets the HMQ code page to the
     579    // Windows ANSI code page so that all threads created by Win32 API
     580    // will be already in the ANSI code page)
     581    ULONG cpFrom, cpTo;
     582    cpFrom = cpTo = GetDisplayCodepage();
     583    HMQ hmq = (HMQ)WinQueryWindowULong(hwnd, QWL_HMQ);
     584    if (hmq)
     585        cpTo = WinQueryCp(hmq);
     586
     587    LPSTR psz = NULL;
     588    if(lpsz && cpFrom != cpTo) {
     589        int size = (strlen(lpsz) + 1) * 2; // count for DBCS just in case
     590        psz = (LPSTR)_smalloc(size);
     591        if (WinCpTranslateString(GetThreadHAB(), cpFrom, lpsz, cpTo, size, psz)) {
     592            dprintf(("OSLibWinSetTitleBarTextCp: cp%d->cp%d", cpFrom, cpTo));
     593            lpsz = psz;
     594        } else {
     595            dprintf(("OSLibWinSetTitleBarTextCp: ERROR: cp%d->cp%d failed!", cpFrom, cpTo));
     596        }
     597    }
     598    BOOL rc = WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), lpsz);
     599    if (psz) {
     600        _sfree(psz);
     601    }
     602    return rc;
    577603}
    578604//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.