|
|
| version 1.2, 2007/01/10 14:43:36 | version 1.5, 2007/12/28 20:36:40 |
|---|---|
| Line 1 | Line 1 |
| #include "compiler.h" | #include "compiler.h" |
| #include "np2.h" | |
| void __msgbox(const char *title, const char *msg) { | void __msgbox(const char *title, const char *msg) { |
| Line 19 void __msgbox(const char *title, const c | Line 19 void __msgbox(const char *title, const c |
| // WinAPIだと Win95でバグあるの | // WinAPIだと Win95でバグあるの |
| int loadstring2(HINSTANCE hInstance, UINT uID, | int _loadstringresource(HINSTANCE hInstance, UINT uID, |
| LPTSTR lpBuffer, int nBufferMax) { | LPTSTR lpszBuffer, int nBufferMax) |
| { | |
| HMODULE hModule; | HMODULE hModule; |
| HRSRC hRsrc; | HRSRC hRsrc; |
| DWORD dwResSize; | DWORD dwResSize; |
| Line 32 int loadstring2(HINSTANCE hInstance, UIN | Line 32 int loadstring2(HINSTANCE hInstance, UIN |
| hModule = (HMODULE)hInstance; | hModule = (HMODULE)hInstance; |
| hRsrc = FindResource(hModule, MAKEINTRESOURCE((uID >> 4) + 1), RT_STRING); | hRsrc = FindResource(hModule, MAKEINTRESOURCE((uID >> 4) + 1), RT_STRING); |
| if (hRsrc == NULL) { | if (hRsrc == NULL) |
| return(0); | { |
| return 0; | |
| } | } |
| dwResSize = SizeofResource(hModule, hRsrc); | dwResSize = SizeofResource(hModule, hRsrc); |
| hGlobal = LoadResource(hModule, hRsrc); | hGlobal = LoadResource(hModule, hRsrc); |
| if (hGlobal == NULL) { | if (hGlobal == NULL) |
| return(0); | { |
| return 0; | |
| } | } |
| pRes = (UINT16 *)LockResource(hRsrc); | pRes = (UINT16 *)LockResource(hGlobal); |
| dwPos = 0; | dwPos = 0; |
| uID = uID & 15; | uID = uID & 15; |
| while((uID) && (dwPos < dwResSize)) { | while((uID) && (dwPos < dwResSize)) |
| { | |
| dwPos += pRes[dwPos] + 1; | dwPos += pRes[dwPos] + 1; |
| uID--; | uID--; |
| } | } |
| if (dwPos >= dwResSize) { | if (dwPos >= dwResSize) |
| return(0); | { |
| return 0; | |
| } | } |
| nLength = pRes[dwPos]; | nLength = pRes[dwPos]; |
| dwPos++; | dwPos++; |
| nLength = min(nLength, (int)(dwResSize - dwPos)); | nLength = min(nLength, (int)(dwResSize - dwPos)); |
| #if defined(_UNICODE) | #if defined(_UNICODE) |
| if ((lpBuffer != NULL) && (nBufferMax > 0)) { | if ((lpszBuffer != NULL) && (nBufferMax > 0)) |
| { | |
| nBufferMax--; | nBufferMax--; |
| nLength = min(nLength, nBufferMax); | nLength = min(nLength, nBufferMax); |
| if (nLength) { | if (nLength) |
| CopyMemory(lpBuffer, pRes + dwPos, nLength * sizeof(UINT16)); | { |
| CopyMemory(lpszBuffer, pRes + dwPos, nLength * sizeof(UINT16)); | |
| } | } |
| lpBuffer[nLength] = '\0'; | lpszBuffer[nLength] = '\0'; |
| } | } |
| #else | #else |
| if ((lpBuffer != NULL) && (nBufferMax > 0)) { | if ((lpszBuffer != NULL) && (nBufferMax > 0)) |
| { | |
| nBufferMax--; | nBufferMax--; |
| if (nBufferMax == 0) { | if (nBufferMax == 0) |
| { | |
| nLength = 0; | nLength = 0; |
| } | } |
| } | } |
| else { | else |
| lpBuffer = NULL; | { |
| lpszBuffer = NULL; | |
| nBufferMax = 0; | nBufferMax = 0; |
| } | } |
| nLength = WideCharToMultiByte(CP_ACP, 0, pRes + dwPos, nLength, | nLength = WideCharToMultiByte(CP_ACP, 0, (WCHAR *)(pRes + dwPos), nLength, |
| lpBuffer, nBufferMax, NULL, NULL); | lpszBuffer, nBufferMax, NULL, NULL); |
| if (lpBuffer) { | if (lpszBuffer) |
| lpBuffer[nLength] = '\0'; | { |
| lpszBuffer[nLength] = '\0'; | |
| } | } |
| #endif | #endif |
| return(nLength); | return(nLength); |
| } | } |
| // WinAPIだと Win95でバグあるの | |
| LPTSTR _lockstringresource(HINSTANCE hInstance, LPCTSTR lpcszString) | |
| { | |
| LPTSTR lpszRet; | |
| int nSize; | |
| lpszRet = NULL; | |
| if (HIWORD(lpcszString)) | |
| { | |
| nSize = (lstrlen(lpcszString) + 1) * sizeof(TCHAR); | |
| lpszRet = (LPTSTR)_MALLOC(nSize, ""); | |
| if (lpszRet) | |
| { | |
| CopyMemory(lpszRet, lpcszString, nSize); | |
| } | |
| } | |
| else if (LOWORD(lpcszString)) | |
| { | |
| nSize = loadstringresource((UINT)lpcszString, NULL, 0); | |
| if (nSize) | |
| { | |
| lpszRet = (LPTSTR)_MALLOC((nSize + 1) * sizeof(TCHAR), ""); | |
| if (lpszRet) | |
| { | |
| loadstringresource((UINT)lpcszString, lpszRet, nSize + 1); | |
| } | |
| } | |
| } | |
| return lpszRet; | |
| } | |
| // ---- | |
| int loadstringresource(UINT uID, LPTSTR lpszBuffer, int nBufferMax) | |
| { | |
| return _loadstringresource(g_hInstance, uID, lpszBuffer, nBufferMax); | |
| } | |
| LPTSTR lockstringresource(LPCTSTR lpcszString) | |
| { | |
| return _lockstringresource(g_hInstance, lpcszString); | |
| } | |
| void unlockstringresource(LPTSTR lpszString) | |
| { | |
| if (lpszString) | |
| { | |
| _MFREE(lpszString); | |
| } | |
| } | |