Changeset 21544 for trunk/src


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.

Location:
trunk/src/user32
Files:
2 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//******************************************************************************
  • trunk/src/user32/win32wbase.cpp

    r21529 r21544  
    528528//******************************************************************************
    529529//******************************************************************************
    530 static BOOL OSLibWinSetTitleBarTextA(HWND hwnd, LPSTR lpsz)
    531 {
    532     LPSTR psz = NULL;
    533     if(lpsz) {
    534         psz = (LPSTR)_smalloc(strlen(lpsz) + 1);
    535         CharToOemA(lpsz, psz);
    536     }
    537     BOOL rc = OSLibWinSetTitleBarText(hwnd, psz);
    538     if (psz) {
    539         _sfree(psz);
    540     }
    541     return rc;
    542 }
    543 //******************************************************************************
    544 //******************************************************************************
    545530BOOL Win32BaseWindow::MsgCreate(HWND hwndOS2)
    546531{
     
    635620
    636621        if(fOS2Look) {
    637             OSLibWinSetTitleBarTextA(OS2HwndFrame, windowNameA);
     622            OSLibWinSetTitleBarText(OS2HwndFrame, windowNameA);
    638623        }
    639624    }
     
    16641649            }
    16651650            if(fOS2Look) {
    1666                 OSLibWinSetTitleBarTextA(OS2HwndFrame, getWindowNameA());
     1651                OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
    16671652            }
    16681653        }
     
    22402225            }
    22412226            if(fOS2Look) {
    2242                 OSLibWinSetTitleBarTextA(OS2HwndFrame, getWindowNameA());
     2227                OSLibWinSetTitleBarText(OS2HwndFrame, getWindowNameA());
    22432228            }
    22442229        }
Note: See TracChangeset for help on using the changeset viewer.