#include "StdAfx.h" #define ATOI_KLUDGE #include "T2FilePreview.h" #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif T2FilePreview::T2FilePreview() { mStr40 = ""; mStr44 = ""; } /*virtual*/ T2FilePreview::~T2FilePreview() { } BEGIN_MESSAGE_MAP(T2FilePreview, CWnd) //{{AFX_MSG_MAP(T2FilePreview) ON_WM_PAINT() //}}AFX_MSG_MAP END_MESSAGE_MAP() void T2FilePreview::SetFile(const char *path) { mStr40 = path; int fd = _open(mStr40, 0); if (fd != -1) { char magic[4]; _read(fd, magic, 4); if (!memcmp(magic, "T200", 4) || !memcmp(magic, "002T", 4)) { mStr44 = "READY"; unsigned char len; _read(fd, &len, 1); char *str = (char *) malloc(len + 1); _read(fd, str, len); str[len] = 0; mStr44 += str; free(str); } else { // "ERRORThe Tower2.0のファイルではありません" mStr44 = "ERROR\x01The Tower2.0\x82\xCC\x83\x74\x83\x40\x83\x43\x83\x8B\x82\xC5\x82\xCD\x82\xA0\x82\xE8\x82\xDC\x82\xB9\x82\xF1\x01"; } _close(fd); } else { // "ERRORファイルがありません" mStr44 = "ERROR\x01\x83\x74\x83\x40\x83\x43\x83\x8B\x82\xAA\x82\xA0\x82\xE8\x82\xDC\x82\xB9\x82\xF1\x01"; } InvalidateRect(NULL); } void T2FilePreview::OnPaint() { #pragma var_order(clr2, clr3, innerRect, clr1, font2, font1, save, pen1, pen2, paintDC, clientRect, logFont) CPaintDC paintDC(this); int save = paintDC.SaveDC(); paintDC.SetBkMode(TRANSPARENT); CFont font1, font2; LOGFONT logFont; GetParent()->GetFont()->GetLogFont(&logFont); font1.CreateFontIndirect(&logFont); logFont.lfWeight = FW_BOLD; font2.CreateFontIndirect(&logFont); COLORREF clr1 = GetSysColor(COLOR_BTNTEXT); COLORREF clr2 = GetSysColor(COLOR_BTNHIGHLIGHT); COLORREF clr3 = GetSysColor(COLOR_BTNSHADOW); CPen pen1, pen2; pen1.CreatePen(PS_SOLID, 0, clr1); pen2.CreatePen(PS_SOLID, 0, clr2); CRect clientRect; GetClientRect(clientRect); paintDC.DrawEdge(clientRect, EDGE_SUNKEN, BF_RECT); CRect innerRect = clientRect; innerRect.DeflateRect(3, 3, 3, 3); if (mStr44 != "") { #pragma var_order(tok, str) char *str = (char *) malloc(mStr44.GetLength() + 1); strcpy(str, mStr44); char *tok = strtok(str, "\x01"); if (!strcmp(tok, "READY")) { #pragma var_order(line2, height, pt, line1) int height = abs(logFont.lfHeight); CPoint pt = innerRect.TopLeft(); paintDC.SelectObject(&font2); paintDC.SetTextColor(clr2); paintDC.TextOut(pt.x + 1, pt.y + 1, "\x8C\x9A\x90\xDD\x92\x6E"); paintDC.SetTextColor(clr1); paintDC.TextOut(pt.x, pt.y, "\x8C\x9A\x90\xDD\x92\x6E"); pt.y += height; paintDC.SelectObject(&font1); tok = strtok(NULL, "\x01"); paintDC.TextOut(pt.x + height, pt.y, tok); pt.y += height + 1; paintDC.SelectObject(&pen2); paintDC.MoveTo(pt.x + height + 1, pt.y + 1); paintDC.LineTo(innerRect.right - height + 1, pt.y + 1); paintDC.SelectObject(&pen1); paintDC.MoveTo(pt.x + height, pt.y); paintDC.LineTo(innerRect.right - height, pt.y); pt.y += 6; paintDC.SelectObject(&font2); paintDC.SetTextColor(clr2); paintDC.TextOut(pt.x + 1, pt.y + 1, "\x83\x4F\x83\x8C\x81\x5B\x83\x68"); paintDC.SetTextColor(clr1); paintDC.TextOut(pt.x, pt.y, "\x83\x4F\x83\x8C\x81\x5B\x83\x68"); pt.y += height; paintDC.SelectObject(&font1); tok = strtok(NULL, "\x01"); CString line1, line2; if (tok) { #pragma var_order(i, count) int count = atoi(tok); for (int i = 0; i < count; i++) { // ☆ line1 += "\x81\x99"; // ★ line2 += "\x81\x9A"; } } paintDC.SetTextColor(RGB(255, 255, 0)); paintDC.TextOut(pt.x + height, pt.y, line2); paintDC.SetTextColor(RGB(0, 0, 0)); paintDC.TextOut(pt.x + height, pt.y, line1); pt.y += height + 1; paintDC.SelectObject(&pen2); paintDC.MoveTo(pt.x + height + 1, pt.y + 1); paintDC.LineTo(innerRect.right - height + 1, pt.y + 1); paintDC.SelectObject(&pen1); paintDC.MoveTo(pt.x + height, pt.y); paintDC.LineTo(innerRect.right - height, pt.y); pt.y += 6; paintDC.SelectObject(&font2); paintDC.SetTextColor(clr2); paintDC.TextOut(pt.x + 1, pt.y + 1, "\x8E\x91\x8B\xE0"); paintDC.SetTextColor(clr1); paintDC.TextOut(pt.x, pt.y, "\x8E\x91\x8B\xE0"); pt.y += height; paintDC.SelectObject(&font1); tok = strtok(NULL, "\x01"); paintDC.TextOut(pt.x + height, pt.y, tok); pt.y += height + 1; paintDC.SelectObject(&pen2); paintDC.MoveTo(pt.x + height + 1, pt.y + 1); paintDC.LineTo(innerRect.right - height + 1, pt.y + 1); paintDC.SelectObject(&pen1); paintDC.MoveTo(pt.x + height, pt.y); paintDC.LineTo(innerRect.right - height, pt.y); pt.y += 6; paintDC.SelectObject(&font2); paintDC.SetTextColor(clr2); paintDC.TextOut(pt.x + 1, pt.y + 1, "\x90\x6C\x8C\xFB"); paintDC.SetTextColor(clr1); paintDC.TextOut(pt.x, pt.y, "\x90\x6C\x8C\xFB"); pt.y += height; paintDC.SelectObject(&font1); tok = strtok(NULL, "\x01"); paintDC.TextOut(pt.x + height, pt.y, tok); pt.y += height + 1; paintDC.SelectObject(&pen2); paintDC.MoveTo(pt.x + height + 1, pt.y + 1); paintDC.LineTo(innerRect.right - height + 1, pt.y + 1); paintDC.SelectObject(&pen1); paintDC.MoveTo(pt.x + height, pt.y); paintDC.LineTo(innerRect.right - height, pt.y); } else if (!strcmp(tok, "ERROR")) { tok = strtok(NULL, "\x01"); paintDC.SelectObject(&font1); innerRect.OffsetRect(1, 1); paintDC.SetTextColor(clr2); paintDC.DrawText(tok, innerRect, DT_WORDBREAK); innerRect.OffsetRect(-1, -1); paintDC.SetTextColor(clr3); paintDC.DrawText(tok, innerRect, DT_WORDBREAK); } free(str); } paintDC.RestoreDC(save); }