?? bitfont.c
字號:
}
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = szBuf;
ofn.nMaxFile = MAX_PATH;
ofn.nMaxFileTitle = MAX_PATH;
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szName;
ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn)) {
HANDLE f;
LONG ret;
LONG skip, width, bytewidth, height;
LONG pagenum, pages;
LONG size, size1, size2;
unsigned char *font;
/* 轉(zhuǎn)換字庫名稱 */
while (*chg)
chg++;
while (*chg != TEXT('\\') && chg != szFonName)
chg--;
if (*chg == TEXT('\\'))
chg++;
/* 根據(jù)字庫名稱讀取字庫信息 */
size1 = GetPrivateProfileInt(chg, TEXT("Size"), 0, szFonName);
/* 檢查一下返回值 */
if (size1 == 0)
return FALSE;
width = GetPrivateProfileInt(chg, TEXT("Width"), 0, szFonName);
bytewidth = width / Byte;
if (width % Byte)
bytewidth++;
height = GetPrivateProfileInt(chg, TEXT("Height"), 0, szFonName);
pagenum = GetPrivateProfileInt(chg, TEXT("PageNum"), 0, szFonName);
pages = GetPrivateProfileInt(chg, TEXT("Pages"), 0, szFonName); //???
/* 這里需要改進(jìn),還是…… */
if (height * bytewidth * pagenum * pages > size1) {
MessageBox(hwnd, TEXT("字體配置文件大小設(shè)置不對!"), NULL, MB_ICONSTOP);
return FALSE;
}
f = CreateFile(szName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (f == INVALID_HANDLE_VALUE) {
MessageBox(hwnd, TEXT("內(nèi)部錯誤!"), NULL, MB_ICONSTOP);
CloseHandle(f);
return FALSE;
}
size2 = GetFileSize(f, NULL);
if (size1 > size2) {
MessageBox(hwnd, TEXT("字體文件大小不對!"), NULL, MB_ICONSTOP);
CloseHandle(f);
return FALSE;
}
skip = GetPrivateProfileInt(chg, TEXT("Skip"), 0, szFonName);
size = size1 - skip;
font = malloc(size);
if (font == NULL) {
MessageBox(hwnd, TEXT("動態(tài)分配內(nèi)存錯誤!"), 0, MB_ICONSTOP);
CloseHandle(f);
return FALSE;
}
ret = 0;
SetFilePointer(f, skip, &ret, FILE_BEGIN);
ret = 0;
ReadFile(f, font, size, &ret, NULL);
CloseHandle(f);
if (size != ret) {
MessageBox(hwnd, TEXT("讀取字體文件錯誤!"), 0, MB_ICONSTOP);
return FALSE;
}
/* 讀取成功,設(shè)置所有信息參數(shù) */
if (BitFont)
free(BitFont);
BitFont = font;
lstrcpy(szFileName, chg);
Bit = GetPrivateProfileInt(szFileName, TEXT("Bit"), 0, szFonName);
Print = GetPrivateProfileInt(szFileName, TEXT("Print"), 0, szFonName);
ByteWidth = bytewidth;
Height = height;
LineNum = GetPrivateProfileInt(szFileName, TEXT("LineNum"), 0, szFonName);
PageNum = pagenum;
Pages = pages;
Count = PageNum * Pages;
cWidth = width + Spacing;
cHeight = Height + Spacing;
return TRUE;
}
return FALSE;
}
/*------------------------------------------------------------------------
Procedure: WndProc ID:1
Purpose: 主處理函數(shù)
Input: Win32 默認(rèn)
Output: Win32 默認(rèn)
Errors:
------------------------------------------------------------------------*/
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rc1, rc2;
int Lines, cX, cY;
LONG uPage;
ULONG ulScrollLines;
SCROLLINFO si;
static int iPage = 1;
static int iDeltaPerLine, iAccumDelta;
switch (msg) {
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDM_OPEN:
if (OpenBitFontFile(hwnd)) {
/* 打開字庫成功后,設(shè)置相應(yīng)程序內(nèi)部信息 */
iPage = 1;
si.cbSize = sizeof(si);
si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE;
si.nMin = 1;
si.nPage = 1;
si.nMax = Pages;
si.nPos = iPage;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
Lines = PageNum / LineNum;
if (PageNum % LineNum)
Lines++;
cX = Spacing + LineNum * cWidth;
if (Pages > 1)
cX += GetSystemMetrics(SM_CXVSCROLL);
cY = Spacing + Lines * cHeight;
SetRect(&rc1, 0, 0, cX, cY);
AdjustWindowRectEx(&rc1, GetWindowStyle(hwnd), GetMenu(hwnd) != NULL, GetWindowExStyle(hwnd));
GetWindowRect(hwnd, &rc2);
MoveWindow(hwnd, rc2.left, rc2.top, rc1.right - rc1.left, rc1.bottom - rc1.top, TRUE);
InvalidateRect(hwnd, NULL, TRUE);
}
return 0;
case IDM_ABOUT:
MessageBox(hwnd, TEXT("點陣字庫查看器\n\nLarry Li[Wuhan], 2003.1.10\n"), TEXT("關(guān)于..."), MB_ICONINFORMATION);
return 0;
case IDM_EXIT:
SendMessage(hwnd, WM_CLOSE, 0, 0);
return 0;
}
return 0;
case WM_CREATE:
/* 初始化 */
si.cbSize = sizeof(si);
si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE;
si.nMin = 1;
si.nPage = 1;
si.nMax = Pages;
si.nPos = iPage;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
SendMessage(hwnd, WM_SETTINGCHANGE, 0, 0);
return 0;
case WM_SETTINGCHANGE:
/* 設(shè)置您的滾輪鼠標(biāo) */
#define WHEEL_DELTA 120
ulScrollLines = GetSystemMetrics(SM_MOUSEWHEELPRESENT);
if (ulScrollLines)
iDeltaPerLine = WHEEL_DELTA / ulScrollLines;
else
iDeltaPerLine = 0 ;
return 0;
case WM_MOUSEWHEEL:
/* 開始滾動吧! */
if (iDeltaPerLine == 0)
break ;
iAccumDelta += (short) HIWORD (wParam); // 120 or -120
while (iAccumDelta >= iDeltaPerLine) {
SendMessage(hwnd, WM_VSCROLL, SB_LINEUP, 0);
iAccumDelta -= iDeltaPerLine;
}
while (iAccumDelta <= -iDeltaPerLine) {
SendMessage(hwnd, WM_VSCROLL, SB_LINEDOWN, 0);
iAccumDelta += iDeltaPerLine;
}
return 0;
case WM_KEYDOWN:
/* 鍵盤控制接口 */
switch(wParam){
#define Key2Msg(k, b) case VK_##k: SendMessage(hwnd, WM_VSCROLL, SB_##b, 0); break
Key2Msg(HOME, TOP);
Key2Msg(END, BOTTOM);
Key2Msg(PRIOR, PAGEUP);
Key2Msg(NEXT, PAGEDOWN);
Key2Msg(UP, LINEUP);
Key2Msg(DOWN, LINEDOWN);
#undef Key2Msg
}
/* 這是很早以前寫的東西,被我用在不少地方;宏用的好時就真的是很好用! */
break;
case WM_VSCROLL:
/* 處理滾動條的操作 */
switch (LOWORD(wParam)) {
case SB_TOP: uPage = 1; break;
case SB_BOTTOM: uPage = Pages; break;
case SB_LINEUP: uPage = iPage - 1; break;
case SB_LINEDOWN: uPage = iPage + 1; break;
case SB_PAGEUP: uPage = iPage - 10; break;
case SB_PAGEDOWN: uPage = iPage + 10; break;
case SB_THUMBPOSITION: uPage = HIWORD(wParam); break;
default: return 0;
}
uPage = max(1, min(uPage, Pages));
if (uPage != iPage) {
/* 沒有改變時就不需要操作 */
#if 0
si.fMask = SIF_POS;
si.nPos = uPage;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
#else
SetScrollPos(hwnd, SB_VERT, uPage, TRUE);
#endif
InvalidateRect(hwnd, NULL, TRUE);
iPage = uPage;
}
return 0;
case WM_PAINT:
/* 標(biāo)準(zhǔn)的 Win32 繪圖實例 */
hdc = BeginPaint(hwnd, &ps);
if (BitFont)
DrawFont(hdc, BitFont, iPage - 1);
else {
RECT rc;
GetClientRect(hwnd, &rc);
DrawText(hdc, TEXT("Larry Li[Wuhan], 2003.1.25"), -1, &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
/* 沒什么好寫的了 */
FreeFont(BitFont);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -