📄 tools.c
字号:
/**************************************************************************
File:
Tools.c
Module:
WSENGINE.DLL
Date:
Sep. 1993 - Jan. 1995
Created By:
Wang Zhidong
Imports:
CsmSetDefaultCode
CsmGetDefaultCode
CsmSetSystemCode
EnableMLR
Exports:
WseGetVersion
WseGetVersionEx
WseGetEngineMetrics
WseSetEngineMetrics
WseShowMsgBar
WseGetProfileInt
WseGetprofileString
WseWriteProfileString
WseGetModuleFilepath
WseCenterWindow
WseDrawButtonBox
WseDrawgrayFrame
WseShowBmpresource
WseShowBitmap
WseGetSystemTime
WseRepMovsb
WseDeleteFile
WseHexToLong
**************************************************************************/
#include <Windows.h>
#include <Mate.h>
#include "engine.h"
//////////////////////////////////////////////////////////////////////////
// BUILDVERSION List:
// 100 Support GetVersionEx
// DialogCard
// 101 Support E-Mail Remote Client 3.2
#define BUILDVERSION 101
//////////////////////////////////////////////////////////////////////////
#ifdef DEMO
#ifndef NOEXPAND
#define NOEXPAND
#endif
#endif
#ifdef VEROEM
#ifndef NOEXPAND
#define NOEXPAND
#endif
#endif
HCODE WINAPI CsmSetDefaultCode (HCODE hCode);
HCODE WINAPI CsmGetDefaultCode ();
HCODE WINAPI CsmGetSystemCode ();
extern WORD wSegF000;
extern HANDLE hInst;
extern char szSysProfile[];
extern int bCWinVer;
extern UINT wGlyphDeep;
extern UINT wSendStrTag;
extern UINT ColorBits;
extern UINT wPenTag;
extern HTASK hMainTask;
extern char szDisplay[];
extern NPSTR pFotReg, pFotBd, pFotBi, pFotI;
extern HGLOBAL hStrCache;
extern UINT pStrCache;
extern UINT wStrCacheTag;
extern UINT wStrCacheSize;
extern char szSystem[];
extern char szMlrMap[];
extern char szDefaultCode[];
BOOL FAR EnableMLR (int);
DWORD WINAPI WseGetVersion ()
{
return MAKELONG (GetVersion (), 0x120);
}
WORD WINAPI WseGetVersionEx (UINT wSys)
{
return wSys == NULL ? 0x0110 :
wSys == -1 ? BUILDVERSION :
NULL;
}
UINT WINAPI WseGetEngineMetrics (UINT wTag)
{
switch (wTag)
{
case GEM_SENDSTRINGTAG:
return wSendStrTag;
case GEM_COLORBITS:
return ColorBits;
case GEM_DEFAULTCODE:
return CsmGetDefaultCode ();
case GEM_ENABLEMLR:
return WseGetProfileInt (szSystem, szMlrMap, 1);
case GEM_SYSTEMCODE:
return CsmGetSystemCode ();
case GEM_SENDSTRCACHE:
return wStrCacheTag;
case GEM_CWINVERSION:
return bCWinVer;
}
return NULL;
}
UINT WINAPI WseSetEngineMetrics (UINT wTag, UINT wVal)
{
switch (wTag)
{
case GEM_SENDSTRINGTAG:
wTag = wSendStrTag;
wSendStrTag = wVal;
return wTag;
break;
case GEM_SENDSTRCACHE:
wTag = wStrCacheTag;
wStrCacheTag = wVal;
if (wStrCacheTag && !hStrCache)
{
hStrCache = GlobalAlloc (GHND | GMEM_SHARE, wStrCacheSize);
pStrCache = 0;
}
else if (!wStrCacheTag && hStrCache)
GlobalFree (hStrCache);
return wTag;
break;
case GEM_DEFAULTCODE:
{
NPSTR pStr = (NPSTR)LocalAlloc (LPTR, 64);
wsprintf (pStr, "%d", wVal);
WseWriteProfileString (szSystem, szDefaultCode, pStr);
LocalFree ((HANDLE)pStr);
}
return (UINT)CsmSetDefaultCode ((HCODE)wVal);
break;
#ifndef DEMO
case GEM_GLYPHDEEP:
if (wVal < 10)
{
wTag = wGlyphDeep;
wGlyphDeep = wVal;
return wTag;
}
return NULL;
#ifndef ATTNCR
case GEM_PENTAG:
wTag = wPenTag;
wPenTag = wVal;
return wTag;
break;
#endif
#endif
case GEM_ENABLEMLR:
wTag = WseGetProfileInt (szSystem, szMlrMap, 1);
WseWriteProfileString (szSystem, szMlrMap, wVal ? "1" : "0");
EnableMLR (wVal);
return wTag;
break;
case GEM_MAINTASK:
wTag = (UINT)hMainTask;
hMainTask = (HTASK)wVal;
return wTag;
break;
}
return NULL;
}
int WINAPI WseShowMsgBox (hInstance, hWnd, iIDS, idCap, nType)
HANDLE hInstance;
HWND hWnd;
int iIDS, idCap;
unsigned nType;
{
NPSTR str1, str2;
int i;
str1 = (NPSTR)LocalAlloc (LPTR, 256);
str2 = (NPSTR)LocalAlloc (LPTR, 256);
LoadString (hInstance, iIDS, str1, 250);
LoadString (hInstance, idCap, str2, 250);
i = MessageBox (hWnd, str1, str2, nType);
LocalFree ((HANDLE)str1);
LocalFree ((HANDLE)str2);
return i;
}
UINT WINAPI WseGetProfileInt (lpItem, lpName, wVal)
LPSTR lpItem, lpName;
int wVal;
{
return GetPrivateProfileInt (lpItem, lpName, wVal, szSysProfile);
}
int WINAPI WseGetProfileString (lpItem, lpName, lpDefault, lpBuff, wLen)
LPSTR lpItem, lpName, lpDefault, lpBuff;
int wLen;
{
#ifdef NOEXPAND
if (lstrcmpi (lpItem, "Font Driver") == 0 ||
lstrcmpi (lpItem, "Font File") == 0 ||
// lstrcmpi (lpItem, "Input Method Drivers") == 0 ||
lstrcmpi (lpItem, "Boot") == 0)
{
if (lpName == NULL || lpDefault == NULL);
return NULL;
if (wLen > lstrlen (lpDefault)+1)
wLen = lstrlen (lpDefault)+1;
wLen --;
WseRepMovsb (lpBuff, lpDefault, wLen);
lpBuff[wLen] = 0;
return wLen;
}
#endif
return GetPrivateProfileString (lpItem, lpName, lpDefault,
lpBuff, wLen,
szSysProfile);
}
BOOL WINAPI WseWriteProfileString (lpItem, lpName, lpStr)
LPSTR lpItem, lpName, lpStr;
{
// HTRANS hTrans = WseMakeTranslateTag (wDefaultCode, HCODE_GB, NULL);
// if (hTrans == HTRANS_NULL || hTrans == HTRANS_ERROR)
return WritePrivateProfileString (lpItem, lpName, lpStr, szSysProfile);
/*
{
int i;
NPSTR pItem, pName, pStr;
i = lstrlen (lpItem);
pItem = (NPSTR)LocalAlloc (LPTR, i+2);
WseTranslateString (hTrans, lpItem, i, pItem, i);
i = lstrlen (lpName);
pName = (NPSTR)LocalAlloc (LPTR, i+2);
WseTranslateString (hTrans, lpName, i, pName, i);
i = lstrlen (lpStr);
pStr = (NPSTR)LocalAlloc (LPTR, i+2);
WseTranslateString (hTrans, lpStr, i, pStr, i);
i = WritePrivateProfileString (pItem, pName, pStr, szSysProfile);
LocalFree ((HANDLE)pStr);
LocalFree ((HANDLE)pItem);
LocalFree ((HANDLE)pName);
return i;
}
*/
}
int WINAPI WseGetModuleFilePath (hModule, szFile, nLen)
HANDLE hModule;
LPSTR szFile;
int nLen;
{
nLen = GetModuleFileName (hModule ? hModule : hInst, szFile, nLen);
while (nLen)
{
nLen--;
if (szFile[nLen] == '\\' || szFile[nLen] == ':')
{
szFile[nLen+1] = '\0';
break;
}
}
return nLen+1;
}
void WINAPI WseCenterWindow (HWND hWnd)
{
RECT rect;
GetWindowRect (hWnd, &rect);
rect.right -= rect.left;
rect.bottom -= rect.top;
rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right)/2;
rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom)/2;
MoveWindow (hWnd, rect.left, rect.top,
rect.right, rect.bottom, TRUE);
}
void WINAPI WseDrawButtonBox (hDC, x1, y1, x2, y2, bDown)
HDC hDC;
int x1, x2, y1, y2;
BOOL bDown;
{
HPEN hpWhite, hpGray, hpPrev;
if (x2 - x1 < 3)
return;
if (ColorBits > 2)
{
hpGray = CreatePen (PS_SOLID, 1, RGB(128,128,128));
hpWhite = GetStockObject (WHITE_PEN);
}
else
{
hpGray =
hpWhite = GetStockObject (BLACK_PEN);
}
hpPrev = SelectObject (hDC, bDown ? hpGray : hpWhite);
MoveTo (hDC, x1, y2);
LineTo (hDC, x1, y1);
LineTo (hDC, x2, y1);
SelectObject (hDC, bDown ? hpWhite : hpGray);
LineTo (hDC, x2, y2);
LineTo (hDC, x1, y2);
SelectObject (hDC, hpPrev);
if (ColorBits > 2)
DeleteObject (hpGray);
}
void WINAPI WseDrawGrayFrame (hDC, rect, iWidth, hbLeftTop, hbRightBottom)
HDC hDC;
RECT FAR * rect;
int iWidth;
HBRUSH hbLeftTop, hbRightBottom;
{
RECT rc;
rc.left = rect->left;
rc.top = rect->top;
rc.right = rect->right;
rc.bottom = rect->top+iWidth;
FillRect (hDC, &rc, hbLeftTop);
rc.right = rect->left+iWidth;
rc.bottom = rect->bottom;
FillRect (hDC, &rc, hbLeftTop);
rc.left = rect->left;
rc.top = rect->bottom - iWidth;
rc.right = rect->right;
FillRect (hDC, &rc, hbRightBottom);
rc.left = rect->right - iWidth;
rc.top = rect->top;
FillRect (hDC, &rc, hbRightBottom);
}
BOOL WINAPI WseShowBmpResource (hDC, lpBmpName, ix, iy, iw, ih, hInstance)
HDC hDC;
LPSTR lpBmpName;
int ix, iy, iw, ih;
HANDLE hInstance;
{
HDC hMemDC;
HANDLE hBmp, hOldBmp;
BITMAP bmp;
hMemDC = CreateCompatibleDC (hDC);
hBmp = LoadBitmap (hInstance, lpBmpName);
GetObject (hBmp, sizeof(BITMAP), (LPBITMAP)&bmp);
hOldBmp = SelectObject (hMemDC, hBmp);
StretchBlt (hDC, ix, iy, iw, ih,
hMemDC, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
SelectObject (hMemDC, hOldBmp);
DeleteObject (hBmp);
DeleteDC (hMemDC);
return TRUE;
}
BOOL WINAPI WseShowBitmap (hDC, hBmp, ix, iy, iw, ih)
HDC hDC;
HANDLE hBmp;
int ix, iy, iw, ih;
{
HDC hMemDC;
HANDLE hOldBmp;
BITMAP bmp;
hMemDC = CreateCompatibleDC (hDC);
GetObject (hBmp, sizeof(BITMAP), (LPBITMAP)&bmp);
hOldBmp = SelectObject (hMemDC, hBmp);
if (iw == 0 && ih == 0)
{
iw = bmp.bmWidth;
ih = bmp.bmHeight;
}
if (iw >= bmp.bmWidth && ih >= bmp.bmHeight)
BitBlt (hDC,
ix+(iw-bmp.bmWidth)/2, iy+(ih-bmp.bmHeight)/2,
bmp.bmWidth, bmp.bmHeight,
hMemDC, 0, 0, SRCCOPY);
else // if (iw > 1 && ih > 1)
{
SetStretchBltMode (hDC, COLORONCOLOR);
StretchBlt (hDC, ix, iy, iw, ih,
hMemDC, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
}
SelectObject (hMemDC, hOldBmp);
DeleteDC (hMemDC);
return TRUE;
}
DWORD WINAPI WseGetSystemTime (LPSTR lpDate)
{
BYTE TmpDate[8];
if (!lpDate)
lpDate = TmpDate;
_asm {
push di
les di,lpDate
mov ax,2C00H
int 21H ;; Get System Time Info
mov al,dh
stosb
xchg ax,cx
stosw
mov ax,2A00H
int 21H
stosb
xchg ax,dx
stosw
xchg ax,cx
stosw
pop di
}
return *(DWORD FAR *)lpDate;
}
LPSTR WINAPI WseRepMovsb (LPSTR lpObj, LPSTR lpSrc, UINT nCnt)
{
if (!nCnt)
return lpObj;
if (HIWORD(lpSrc) == HIWORD(lpObj) &&
LOWORD(lpObj) > LOWORD(lpSrc) &&
LOWORD(lpObj) < LOWORD(lpSrc) + nCnt)
{
_asm {
push esi
push edi
push ds
pop es
mov ecx,nCnt
mov edi,lpObj
mov esi,lpSrc
add edi,ecx
add esi,ecx
dec edi
dec esi
std
rep movsb
cld
pop edi
pop esi
}
}
else
{
_asm {
push esi
push edi
push ds
pop es
mov ecx,nCnt
mov edi,lpObj
mov esi,lpSrc
rep movsb
pop edi
pop esi
}
}
return lpObj;
}
BOOL WINAPI WseDeleteFile (LPSTR lpFile)
{
BOOL bRet = 0;
_asm {
push ds
lds dx,lpFile
mov ah,41H
int 21H
sbb dx,dx
and ax,dx
mov WORD PTR bRet,ax
pop ds
}
return bRet;
}
DWORD WINAPI WseHexToLong (LPSTR pStr)
{
DWORD Val;
for (Val = 0; *pStr; pStr++)
{
if (*pStr >= '0' && *pStr <= '9')
Val = Val * 16L + (*pStr - '0');
else if (*pStr >= 'a' && *pStr <= 'f')
Val = Val * 16L + (*pStr - 'a') + 10;
else if (*pStr >= 'A' && *pStr <= 'F')
Val = Val * 16L + (*pStr - 'A') + 10;
}
return Val;
}
DWORD WINAPI MoveTo (HDC hDC, int x, int y)
{
POINT pnt;
MoveToEx (hDC, x, y, &pnt);
return MAKELONG(pnt.x,pnt.y);
}
DWORD WINAPI GetTextExtent (
HDC hDC,
LPCSTR lpStr,
int cbStr )
{
SIZE dwSize;
if (GetTextExtentPoint32 (hDC, lpStr, cbStr, &dwSize))
return MAKELONG(dwSize.cx,dwSize.cy);
return 0L;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -