📄 window.cpp
字号:
#include "Window.h"
#include <mbstring.h>
void SetWndPosition(HWND hWnd)
{
RECT rect;
int iScreenX;
int iScreenY;
GetWindowRect(hWnd, &rect);
iScreenX = GetSystemMetrics(SM_CXSCREEN);
iScreenY = GetSystemMetrics(SM_CYSCREEN);
SetWindowPos(hWnd, NULL, (iScreenX-rect.right+rect.left)>>1,
(iScreenY-rect.bottom+rect.top)/2+100,
rect.right-rect.left, rect.bottom-rect.top, SWP_SHOWWINDOW);
}
void DrawBmpButton(LPDRAWITEMSTRUCT lpDIS, HBITMAP hbmpUnselected, HBITMAP hbmpSelected)
{
HDC hdcMem;
BITMAP bmp;
hdcMem = CreateCompatibleDC(lpDIS->hDC);
if (lpDIS->itemState & ODS_SELECTED)
{
SelectObject(hdcMem, hbmpSelected);
GetObject(hbmpSelected, sizeof(BITMAP), &bmp);
}
else
{
SelectObject(hdcMem, hbmpUnselected);
GetObject(hbmpUnselected, sizeof(BITMAP), &bmp);
}
StretchBlt(lpDIS->hDC, lpDIS->rcItem.left, lpDIS->rcItem.top,
lpDIS->rcItem.right - lpDIS->rcItem.left,
lpDIS->rcItem.bottom - lpDIS->rcItem.top,
hdcMem, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
DeleteDC(hdcMem);
}
void DrawBmptoRect(RECT rectDest, const HDC hdcDest, HBITMAP hbmpOrigin)
{
BITMAP bmp;
HDC hdcMem;
HBITMAP hOldBmp;
hdcMem = CreateCompatibleDC(hdcDest);
GetObject(hbmpOrigin, sizeof(BITMAP), &bmp);
hOldBmp = (HBITMAP)SelectObject(hdcMem, hbmpOrigin);
StretchBlt(hdcDest, rectDest.left, rectDest.top,
rectDest.right-rectDest.left, rectDest.bottom-rectDest.top,
hdcMem, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
SelectObject(hdcDest, hOldBmp);
DeleteDC(hdcMem);
}
void InitVersionTable(HWND hwndVersionTable)
{
LVCOLUMN lvCol;
ListView_SetTextColor(hwndVersionTable, RGB(153, 51, 0));
ListView_SetExtendedListViewStyleEx(hwndVersionTable, NULL,
LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
lvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
#ifdef versionKR
unsigned short cha1[3] = {0xbc84,0xc804,0};
unsigned short cha2[3] = {0xc7a5,0xc18c,0};
#endif
lvCol.iSubItem = 0;
lvCol.cx = 349;
lvCol.pszText = NULL;
#ifdef versionKR
lvCol.pszText = cha1;
#else
lvCol.pszText = TEXT("版 本");
#endif
ListView_InsertColumn(hwndVersionTable, 0, &lvCol);
lvCol.iSubItem = 1;
lvCol.cx = 179;
#ifdef versionKR
lvCol.pszText = cha2;
#else
lvCol.pszText = TEXT("藏 所");
#endif
ListView_InsertColumn(hwndVersionTable, 1, &lvCol);
}
bool InitFonts(HFONT hFonts[])
{
LOGFONT lf;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = 0;
lf.lfItalic = 0;
lf.lfUnderline = 0;
lf.lfStrikeOut = 0;
lf.lfCharSet = GB2312_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
lf.lfHeight = 16;
_tcscpy(lf.lfFaceName, TEXT("simsun"));
hFonts[fontBookName] = CreateFontIndirect(&lf);
lf.lfHeight = 12;
_tcscpy(lf.lfFaceName, TEXT("simsun"));
hFonts[fontVersionTable] = CreateFontIndirect(&lf);
lf.lfHeight = 15;
_tcscpy(lf.lfFaceName, TEXT("simsun"));
hFonts[fontDetail] = CreateFontIndirect(&lf);
return(hFonts[fontBookName] && hFonts[fontVersionTable] && hFonts[fontDetail]);
}
void DeleteFonts(HFONT hFonts[])
{
int i = 0;
while(hFonts[i])
{
DeleteObject(hFonts[i]);
i++;
}
}
//--------------------------------详细信息的排列对齐--------------------------------------------
#ifdef UNICODE
void FormatTextW(unsigned short *szSrc, unsigned short *szDest, HWND hWnd, int iWordWidth)
{
int i;
RECT rect;
int iWordNumb;
int iOffSet = 0;
int iWordPerLine;
GetClientRect(hWnd, &rect);
iWordPerLine = rect.right/iWordWidth - 4;
iWordNumb = wcslen(szSrc);
if(iWordNumb > iWordPerLine)
{
for(i = 1; i < iWordNumb + 1; i++)
{
szDest[i-1+iOffSet] = szSrc[i-1];
if(!(i % iWordPerLine))
{
if(i != iWordNumb)
{
_tcscat(szDest, L" ");
iOffSet += 5;
}
}
}
szDest[i-1+iOffSet] = 0;
}
else
{
wcscpy(szDest, szSrc);
}
}
#else
void FormatText(char *szSrc, char *szDest, HWND hWnd, int iWordWidth)
{
int i;
RECT rect;
int iWordNumb;
int iOffSet = 0;
int iWordPerLine;
GetClientRect(hWnd, &rect);
iWordPerLine = rect.right/iWordWidth - 4;
iWordNumb = _tcslen(szSrc)/2;
if(iWordNumb > iWordPerLine)
{
for(i = 1; i < iWordNumb + 1; i++)
{
szDest[2*(i-1)+iOffSet] = szSrc[2*(i-1)];
szDest[2*(i-1)+iOffSet+1] = szSrc[2*(i-1)+1];
if(!(i % iWordPerLine))
{
_tcscat(szDest, TEXT(" "));
iOffSet += 10;
}
}
szDest[2*(i-1)+iOffSet+1] = '\0';
}
else
{
_tcscpy(szDest, szSrc);
}
}
#endif
//--------------------------------简体到繁体的转换----------------------------------------------
bool WINAPI GB2BIG(char *pszSrc)
{
int i = 0;
int iSrcLen;
unsigned char *ptrSrc;
int iPosition;
unsigned char szWord[3];
unsigned char *ptrPosition;
if((iSrcLen = strlen(pszSrc)) == 0)
{
return false;
}
ptrSrc = (unsigned char *)pszSrc;
while(i < iSrcLen)
{
if(!IsDBCSLeadByte((unsigned char)*ptrSrc))
{
ptrSrc++;
i++;
continue;
}
szWord[0] = (unsigned char)*ptrSrc;
szWord[1] = (unsigned char)*(ptrSrc+1);
szWord[2] = '\0';
if(ptrPosition = _mbsstr(GBKSimplified, szWord))
{
iPosition = ptrPosition - GBKSimplified;
*ptrSrc = GBKTraditional[iPosition];
*(ptrSrc+1) = GBKTraditional[iPosition+1];
}
ptrSrc += 2;
i += 2;
}
return true;
}
bool __stdcall GB2BIGW(unsigned short *szSrc)
{
int i = 0;
unsigned short *pSrc;
int iSrcLen;
unsigned short *pSubStr;
unsigned short szWord[2];
if(!szSrc || !(iSrcLen = wcslen(szSrc)))
{
return false;
}
pSrc = szSrc;
while(i < iSrcLen)
{
szWord[0] = *pSrc;
szWord[1] = 0;
if(pSubStr = (unsigned short *)wcsstr(Chinese_SimplifiedW, szWord))
{
*pSrc = Chinese_TraditionalW[pSubStr-Chinese_SimplifiedW];
}
pSrc++;
i++;
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -