mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-06 09:14:58 -06:00
9.34
This commit is contained in:
committed by
Kornel Lesiński
parent
83f8ddcc5b
commit
f08f4dcc3c
109
CPP/Windows/ResourceString.cpp
Executable file → Normal file
109
CPP/Windows/ResourceString.cpp
Executable file → Normal file
@@ -2,11 +2,12 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Windows/ResourceString.h"
|
||||
#ifndef _UNICODE
|
||||
#include "Common/StringConvert.h"
|
||||
#include "../Common/StringConvert.h"
|
||||
#endif
|
||||
|
||||
#include "ResourceString.h"
|
||||
|
||||
extern HINSTANCE g_hInstance;
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
@@ -14,14 +15,16 @@ extern bool g_IsNT;
|
||||
|
||||
namespace NWindows {
|
||||
|
||||
CSysString MyLoadString(HINSTANCE hInstance, UINT resourceID)
|
||||
#ifndef _UNICODE
|
||||
|
||||
static CSysString MyLoadStringA(HINSTANCE hInstance, UINT resourceID)
|
||||
{
|
||||
CSysString s;
|
||||
int size = 256;
|
||||
int size = 128;
|
||||
int len;
|
||||
do
|
||||
{
|
||||
size += 256;
|
||||
size <<= 1;
|
||||
len = ::LoadString(hInstance, resourceID, s.GetBuffer(size - 1), size);
|
||||
}
|
||||
while (size - len <= 1);
|
||||
@@ -29,36 +32,72 @@ CSysString MyLoadString(HINSTANCE hInstance, UINT resourceID)
|
||||
return s;
|
||||
}
|
||||
|
||||
CSysString MyLoadString(UINT resourceID)
|
||||
{
|
||||
return MyLoadString(g_hInstance, resourceID);
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
UString MyLoadStringW(HINSTANCE hInstance, UINT resourceID)
|
||||
{
|
||||
if (g_IsNT)
|
||||
{
|
||||
UString s;
|
||||
int size = 256;
|
||||
int len;
|
||||
do
|
||||
{
|
||||
size += 256;
|
||||
len = ::LoadStringW(hInstance, resourceID, s.GetBuffer(size - 1), size);
|
||||
}
|
||||
while (size - len <= 1);
|
||||
s.ReleaseBuffer();
|
||||
return s;
|
||||
}
|
||||
return GetUnicodeString(MyLoadString(hInstance, resourceID));
|
||||
}
|
||||
|
||||
UString MyLoadStringW(UINT resourceID)
|
||||
{
|
||||
return MyLoadStringW(g_hInstance, resourceID);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static const int kStartSize = 256;
|
||||
|
||||
static void MyLoadString2(HINSTANCE hInstance, UINT resourceID, UString &s)
|
||||
{
|
||||
int size = kStartSize;
|
||||
int len;
|
||||
do
|
||||
{
|
||||
size <<= 1;
|
||||
len = ::LoadStringW(hInstance, resourceID, s.GetBuffer(size - 1), size);
|
||||
}
|
||||
while (size - len <= 1);
|
||||
s.ReleaseBuffer();
|
||||
}
|
||||
|
||||
// NT4 doesn't support LoadStringW(,,, 0) to get pointer to resource string. So we don't use it.
|
||||
|
||||
UString MyLoadString(UINT resourceID)
|
||||
{
|
||||
#ifndef _UNICODE
|
||||
if (!g_IsNT)
|
||||
return GetUnicodeString(MyLoadStringA(g_hInstance, resourceID));
|
||||
else
|
||||
#endif
|
||||
{
|
||||
{
|
||||
wchar_t s[kStartSize];
|
||||
s[0] = 0;
|
||||
int len = ::LoadStringW(g_hInstance, resourceID, s, kStartSize);
|
||||
if (kStartSize - len > 1)
|
||||
return s;
|
||||
}
|
||||
UString dest;
|
||||
MyLoadString2(g_hInstance, resourceID, dest);
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
void MyLoadString(HINSTANCE hInstance, UINT resourceID, UString &dest)
|
||||
{
|
||||
dest.Empty();
|
||||
#ifndef _UNICODE
|
||||
if (!g_IsNT)
|
||||
MultiByteToUnicodeString2(dest, MyLoadStringA(hInstance, resourceID));
|
||||
else
|
||||
#endif
|
||||
{
|
||||
{
|
||||
wchar_t s[kStartSize];
|
||||
s[0] = 0;
|
||||
int len = ::LoadStringW(hInstance, resourceID, s, kStartSize);
|
||||
if (kStartSize - len > 1)
|
||||
{
|
||||
dest = s;
|
||||
return;
|
||||
}
|
||||
}
|
||||
MyLoadString2(hInstance, resourceID, dest);
|
||||
}
|
||||
}
|
||||
|
||||
void MyLoadString(UINT resourceID, UString &dest)
|
||||
{
|
||||
MyLoadString(g_hInstance, resourceID, dest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user