📄 w32win32.cpp
字号:
fEMFDC = TRUE;
}
return fEMFDC;
}
UINT WINAPI CW32System::GetTextAlign(HDC hdc)
{
return ::GetTextAlign(hdc);
}
UINT WINAPI CW32System::SetTextAlign(HDC hdc, UINT uAlign)
{
return ::SetTextAlign(hdc, uAlign);
}
UINT WINAPI CW32System::InvertRect(HDC hdc, CONST RECT *lprc)
{
return ::InvertRect(hdc, lprc);
}
HPALETTE WINAPI CW32System::ManagePalette(
HDC hdc,
CONST LOGPALETTE *plogpal,
HPALETTE &hpalOld,
HPALETTE &hpalNew
)
{
if (hpalNew == NULL)
{
hpalNew = ::CreatePalette(plogpal);
if (hpalNew != NULL)
{
hpalOld = ::SelectPalette(hdc, hpalNew, TRUE);
::RealizePalette(hdc);
}
}
else
{
// A new palette was created previously and we are restoring the old one
::SelectPalette(hdc, hpalOld, TRUE);
::RealizePalette(hdc);
DeleteObject(hpalNew);
hpalNew = NULL;
}
return hpalNew;
}
int WINAPI CW32System::GetMapMode(HDC hdc)
{
return ::GetMapMode(hdc);
}
BOOL WINAPI CW32System::WinLPtoDP(HDC hdc, LPPOINT lppoints, int nCount)
{
return ::LPtoDP(hdc, lppoints, nCount);
}
BOOL WINAPI CW32System::WinDPtoLP(HDC hdc, LPPOINT lppoints, int nCount)
{
return ::DPtoLP(hdc, lppoints, nCount);
}
long WINAPI CW32System::WvsprintfA( LONG cbBuf, LPSTR szBuf, LPCSTR szFmt, va_list arglist )
{
LONG cb;
cb = ::wvsprintfA( szBuf, szFmt, arglist );
Assert(cb < cbBuf);
return cb;
}
int WINAPI CW32System::MulDiv(int nNumber, int nNumerator, int nDenominator)
{
return ::MulDiv(nNumber, nNumerator, nDenominator);
}
//+---------------------------------------------------------------------------
//
// Member: CStrIn::CStrIn
//
// Synopsis: Inits the class.
//
// NOTE: Don't inline these functions or you'll increase code size
// by pushing -1 on the stack for each call.
//
//----------------------------------------------------------------------------
CStrIn::CStrIn(LPCWSTR pwstr)
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrIn::CStrIn");
Init(pwstr, -1);
}
CStrIn::CStrIn(LPCWSTR pwstr, int cwch)
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrIn::CStrIn");
Init(pwstr, cwch);
}
//+---------------------------------------------------------------------------
//
// Member: CStrIn::Init
//
// Synopsis: Converts a LPWSTR function argument to a LPSTR.
//
// Arguments: [pwstr] -- The function argument. May be NULL or an atom
// (HIWORD(pwstr) == 0).
//
// [cwch] -- The number of characters in the string to
// convert. If -1, the string is assumed to be
// NULL terminated and its length is calculated.
//
// Modifies: [this]
//
//----------------------------------------------------------------------------
void
CStrIn::Init(LPCWSTR pwstr, int cwch)
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrIn::Init");
int cchBufReq;
_cchLen = 0;
// Check if string is NULL or an atom.
if (HIWORD(pwstr) == 0)
{
_pstr = (LPSTR) pwstr;
return;
}
Assert(cwch == -1 || cwch > 0);
//
// Convert string to preallocated buffer, and return if successful.
//
_cchLen = W32->MbcsFromUnicode(_ach, ARRAY_SIZE(_ach), pwstr, cwch);
if (_cchLen > 0)
{
if(_ach[_cchLen-1] == 0)
_cchLen--; // account for terminator
_pstr = _ach;
return;
}
//
// Alloc space on heap for buffer.
//
TRACEINFOSZ("CStrIn: Allocating buffer for wrapped function argument.");
cchBufReq = WideCharToMultiByte(
CP_ACP, 0, pwstr, cwch, NULL, 0, NULL, NULL);
Assert(cchBufReq > 0);
_pstr = new char[cchBufReq];
if (!_pstr)
{
// On failure, the argument will point to the empty string.
TRACEINFOSZ("CStrIn: No heap space for wrapped function argument.");
_ach[0] = 0;
_pstr = _ach;
return;
}
Assert(HIWORD(_pstr));
_cchLen = -1 + W32->MbcsFromUnicode(_pstr, cchBufReq, pwstr, cwch);
Assert(_cchLen >= 0);
}
//+---------------------------------------------------------------------------
//
// Class: CStrInMulti (CStrIM)
//
// Purpose: Converts multiple strings which are terminated by two NULLs,
// e.g. "Foo\0Bar\0\0"
//
//----------------------------------------------------------------------------
class CStrInMulti : public CStrIn
{
public:
CStrInMulti(LPCWSTR pwstr);
};
//+---------------------------------------------------------------------------
//
// Member: CStrInMulti::CStrInMulti
//
// Synopsis: Converts mulitple LPWSTRs to a multiple LPSTRs.
//
// Arguments: [pwstr] -- The strings to convert.
//
// Modifies: [this]
//
//----------------------------------------------------------------------------
CStrInMulti::CStrInMulti(LPCWSTR pwstr)
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrInMulti::CStrInMulti");
LPCWSTR pwstrT;
// We don't handle atoms because we don't need to.
Assert(HIWORD(pwstr));
//
// Count number of characters to convert.
//
pwstrT = pwstr;
if (pwstr)
{
do {
while (*pwstrT++)
;
} while (*pwstrT++);
}
Init(pwstr, pwstrT - pwstr);
}
//+---------------------------------------------------------------------------
//
// Member: CStrOut::CStrOut
//
// Synopsis: Allocates enough space for an out buffer.
//
// Arguments: [pwstr] -- The Unicode buffer to convert to when destroyed.
// May be NULL.
//
// [cwchBuf] -- The size of the buffer in characters.
//
// Modifies: [this].
//
//----------------------------------------------------------------------------
CStrOut::CStrOut(LPWSTR pwstr, int cwchBuf)
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrOut::CStrOut");
Assert(cwchBuf >= 0);
_pwstr = pwstr;
_cwchBuf = cwchBuf;
if (!pwstr)
{
Assert(cwchBuf == 0);
_pstr = NULL;
return;
}
Assert(HIWORD(pwstr));
// Initialize buffer in case Windows API returns an error.
_ach[0] = 0;
// Use preallocated buffer if big enough.
if (cwchBuf * 2 <= ARRAY_SIZE(_ach))
{
_pstr = _ach;
return;
}
// Allocate buffer.
TRACEINFOSZ("CStrOut: Allocating buffer for wrapped function argument.");
_pstr = new char[cwchBuf * 2];
if (!_pstr)
{
//
// On failure, the argument will point to a zero-sized buffer initialized
// to the empty string. This should cause the Windows API to fail.
//
TRACEINFOSZ("CStrOut: No heap space for wrapped function argument.");
Assert(cwchBuf > 0);
_pwstr[0] = 0;
_cwchBuf = 0;
_pstr = _ach;
return;
}
Assert(HIWORD(_pstr));
_pstr[0] = 0;
}
//+---------------------------------------------------------------------------
//
// Member: CStrOut::Convert
//
// Synopsis: Converts the buffer from MBCS to Unicode.
//
//----------------------------------------------------------------------------
int
CStrOut::Convert()
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrOut::Convert");
int cch;
if (!_pstr)
return 0;
cch = MultiByteToWideChar(CP_ACP, 0, _pstr, -1, _pwstr, _cwchBuf);
Assert(cch > 0 || _cwchBuf == 0);
Free();
return cch - 1;
}
//+---------------------------------------------------------------------------
//
// Member: CStrOut::~CStrOut
//
// Synopsis: Converts the buffer from MBCS to Unicode.
//
// Note: Don't inline this function, or you'll increase code size as
// both Convert() and CConvertStr::~CConvertStr will be called
// inline.
//
//----------------------------------------------------------------------------
CStrOut::~CStrOut()
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrOut::~CStrOut");
Convert();
}
//
// MultiByte --> UNICODE routins
//
//+---------------------------------------------------------------------------
//
// Member: CConvertStr::Free
//
// Synopsis: Frees string if alloc'd and initializes to NULL.
//
//----------------------------------------------------------------------------
void
CConvertStr::Free()
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CConvertStr::Free");
if (_pstr != _ach && HIWORD(_pstr) != 0)
{
delete [] _pstr;
}
_pstr = NULL;
}
//+---------------------------------------------------------------------------
//
// Member: CConvertStrW::Free
//
// Synopsis: Frees string if alloc'd and initializes to NULL.
//
//----------------------------------------------------------------------------
void
CConvertStrW::Free()
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CConvertStrW::Free");
if (_pwstr != _awch && HIWORD(_pwstr) != 0 )
{
delete [] _pwstr;
}
_pwstr = NULL;
}
//+---------------------------------------------------------------------------
//
// Member: CStrInW::CStrInW
//
// Synopsis: Inits the class.
//
// NOTE: Don't inline these functions or you'll increase code size
// by pushing -1 on the stack for each call.
//
//----------------------------------------------------------------------------
CStrInW::CStrInW(LPCSTR pstr)
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrInW::CStrInW");
Init(pstr, -1, CP_ACP);
}
CStrInW::CStrInW(LPCSTR pstr, UINT uiCodePage)
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrInW::CStrInW");
Init(pstr, -1, uiCodePage);
}
CStrInW::CStrInW(LPCSTR pstr, int cch, UINT uiCodePage)
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrInW::CStrInW");
Init(pstr, cch, uiCodePage);
}
//+---------------------------------------------------------------------------
//
// Member: CStrInW::Init
//
// Synopsis: Converts a LPSTR function argument to a LPWSTR.
//
// Arguments: [pstr] -- The function argument. May be NULL or an atom
// (HIWORD(pwstr) == 0).
//
// [cch] -- The number of characters in the string to
// convert. If -1, the string is assumed to be
// NULL terminated and its length is calculated.
//
// Modifies: [this]
//
//----------------------------------------------------------------------------
void
CStrInW::Init(LPCSTR pstr, int cch, UINT uiCodePage)
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrInW::Init");
int cchBufReq;
_cwchLen = 0;
// Check if string is NULL or an atom.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -