Added X-SAMPA table.

Also:
1. Cleaned up text handling by storing them in resource.
2. Added useful methods to make code look better.
3. Allowed PreviewWindow to be used for general text displaying.

Signed-off-by: Xiaomao Chen <xiaomao5@live.com>
This commit is contained in:
Quantum 2013-08-26 16:52:47 -04:00
parent 738ed0f7ea
commit 7da74dbbf1
12 changed files with 229 additions and 153 deletions

View file

@ -52,8 +52,8 @@ $(SRCDIR)\Window.cpp: $(INCDIR)\Window.hpp
$(SRCDIR)\NLSWrap.cpp: $(INCDIR)\NLSWrap.hpp
$(SRCDIR)\MainLogic.cpp: $(INCDIR)\MainWindow.hpp $(INCDIR)\NLSWrap.hpp $(INCDIR)\ConversionData.inc
$(OUTDIR)\Zalgo.res: Zalgo.rc
$(RC) $(RCFLAGS) /fo$@ $**
$(OUTDIR)\Zalgo.res: Zalgo.rc res\x-sampa.txt res\init.txt
$(RC) $(RCFLAGS) /fo$@ Zalgo.rc
{$(SRCDIR)}.cpp{$(OUTDIR)}.obj::
$(CXX) $(CXXFLAGS) /Fo$(OUTDIR)\ /Fd$(OUTDIR)\ $<

View file

@ -1,3 +1,6 @@
#include <resource.h>
RID_ICON ICON Zalgo.ico
RID_XSAMPA ZALGO_TEXT "res\\x-sampa.txt"
RID_INIT ZALGO_TEXT "res\\init.txt"
RID_LOOSE ZALGO_TEXT "res\\loose.txt"

View file

@ -27,10 +27,11 @@
#define ZALGO_CYRILLIC 0xA555
#define ZALGO_GREEK 0xA556
#define ZALGO_XSAMPA 0xA557
#define ZALGO_XSAMPA_TABLE 0xA558
class MainWindow : public Window {
public:
virtual LPCTSTR ClassName() { return TEXT("Zalgo_Main"); }
virtual LPCTSTR ClassName() { return L"Zalgo_Main"; }
static MainWindow *Create(LPCTSTR szTitle);
protected:
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
@ -55,11 +56,11 @@ protected:
HWND m_messLevel, m_messUpDown;
HWND m_mess, m_unmess, m_previewShow;
HWND m_nfc, m_nfd;
HWND m_latin, m_cyrillic, m_greek, m_xsampa;
HWND m_latin, m_cyrillic, m_greek, m_xsampa, m_xsampa_table;
MyDropTarget m_dropTarget;
PreviewWindow *m_preview;
PreviewWindow *m_preview, *m_data_display;
private:
HFONT hFont, hFontMono;
HFONT hFont;
HBRUSH hBrush;
UDACCEL *udaSecondAccel;
};

View file

@ -12,9 +12,13 @@
class PreviewWindow : public Window {
public:
virtual LPCTSTR ClassName() { return TEXT("Zalgo_Preview"); }
virtual LPCTSTR ClassName() { return L"Zalgo_Preview"; }
static PreviewWindow *Create(LPCTSTR szTitle);
void Destroy() { DestroyWindow(m_hwnd); }
void ChangeText(LPWSTR text, bool padding = true);
void SetFont(HFONT hFont);
void SetFont(const LOGFONT &lf);
protected:
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT OnCreate();
@ -24,6 +28,7 @@ protected:
virtual HICON GetIcon();
private:
HFONT hFont;
bool used_logfont;
HBRUSH hBrush;
int xChar, yChar, xUpper, xClient, yClient, xClientMax, xPos, yPos;
LPTSTR *lpLines;

View file

@ -32,8 +32,10 @@ inline void MakeRectBottomRight(RECT &rect, int x, int y, int cx, int cy)
class Window {
public:
HWND GetHWND() { return m_hwnd; }
HWND GetHWND() const { return m_hwnd; }
bool ShowWindow(int nCmdShow) { return ::ShowWindow(m_hwnd, nCmdShow) != 0; }
static HINSTANCE GetInstance() { return (HINSTANCE) GetModuleHandle(NULL); }
operator HWND() const { return m_hwnd; }
protected:
virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
virtual void PaintContent(PAINTSTRUCT *pps) {}
@ -52,9 +54,8 @@ private:
void OnPaint();
void OnPrintClient(HDC hdc);
static LRESULT CALLBACK
s_WndProc(HWND hwnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK s_WndProc(HWND hwnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);
protected:
HWND m_hwnd;
};

View file

@ -1 +1,10 @@
#define RID_ICON 1
#define RID_XSAMPA 2
#define RID_INIT 3
#define RID_LOOSE 4
inline void GetMessageFont(LOGFONT &lf) {
NONCLIENTMETRICS ncmMetrics = { sizeof(NONCLIENTMETRICS) };
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncmMetrics, 0);
memcpy(&lf, &ncmMetrics.lfMessageFont, sizeof lf);
}

BIN
res/init.txt Normal file

Binary file not shown.

BIN
res/loose.txt Normal file

Binary file not shown.

BIN
res/x-sampa.txt Normal file

Binary file not shown.

View file

@ -14,24 +14,6 @@
#define BOTTOM(x, y, cx, cy) x, (y - cy), cx, cy
#define BOTTOMRIGHT(x, y, cx, cy) (x - cx), (y - cy), cx, cy
#define ZALGO_INITIAL (L"To invoke the hive-mind representing chaos.\r\n"\
L"Invoking the feeling of chaos.\r\n"\
L"With out order.\r\n"\
L"The Nezperdian hive-mind of chaos. Zalgo.\r\n"\
L"He who Waits Behind The Wall.\r\n"\
L"ZALGO!\r\n\r\n"\
L"WARNING: Resulting text size is roughly original "\
L"* (1 + fuck up level). Thou hast been warned.\r\n"\
L"\r\n"\
L"NOTE: If this program crashes on thee, blame "\
L"thyself for fucking up a piece of text that is too "\
L"big with a very high fuck up level.\r\n\r\n"\
L"Do blame Windows for not able to show proper text "\
L"in the edit control, for now, use the preview "\
L"button.\r\n\r\n"\
L"Bonus Geek Info: NFD text will lose all "\
L"diacritics. Thou hast been warned.\r\n")
UINT ZALGO_MESS_LEVEL_[3] = {6, 10, 14};
#define ZALGO_MESS_LEVEL_OF(type) (ZALGO_MESS_LEVEL_[type-0xDEAD])
@ -47,6 +29,23 @@ UINT ZALGO_MESS_LEVEL_[3] = {6, 10, 14};
WNDPROC wpOrigEditProc;
DWORD rgbWindowBackground;
wchar_t *GetResourceString(int id, HMODULE module = NULL) {
HRSRC hRC;
DWORD size;
HGLOBAL hRes;
wchar_t *data;
hRC = FindResource(module, MAKEINTRESOURCE(id), L"ZALGO_TEXT");
if (!hRC)
return NULL;
size = SizeofResource(module, hRC);
hRes = LoadResource(module, hRC);
data = new wchar_t[size / sizeof(wchar_t) + 1];
memcpy(data, LockResource(hRes), size);
data[size / sizeof(wchar_t)] = 0;
return data;
}
LRESULT APIENTRY EditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_KEYDOWN) {
@ -67,24 +66,26 @@ BOOL MainWindow::WinRegisterClass(WNDCLASS *pwc)
LRESULT MainWindow::OnCreate()
{
NONCLIENTMETRICS ncmMetrics = { sizeof(NONCLIENTMETRICS) };
LOGFONT lf;
RECT client;
LPWSTR initial = NULL;
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncmMetrics, 0);
GetClientRect(m_hwnd, &client);
hFont = CreateFontIndirect(&ncmMetrics.lfMessageFont);
GetMessageFont(lf);
hFont = CreateFontIndirect(&lf);
hBrush = GetSysColorBrush(COLOR_WINDOW);
rgbWindowBackground = GetSysColor(COLOR_WINDOW);
hFontMono = CreateFont(0, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
CLEARTYPE_QUALITY, FF_MODERN, TEXT("Consolas"));
initial = GetResourceString(RID_INIT);
if (!initial)
MessageBox(m_hwnd, L"Zalgo initial not found", L"Zalgo Error", MB_ICONERROR);
// Children
m_message = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT,
ZALGO_INITIAL, WS_CHILDWINDOW | WS_VISIBLE | ES_LEFT |
initial, WS_CHILDWINDOW | WS_VISIBLE | ES_LEFT |
ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL,
0, 0, 0, 0, m_hwnd, (HMENU) ZALGO_MESSAGE, GetInstance(), NULL);
if (initial)
delete [] initial;
m_goUp = CreateWindow(WC_BUTTON, L"fuck up going &up",
WS_CHILDWINDOW | WS_VISIBLE | BS_CHECKBOX, 0, 0, 0, 0,
@ -146,6 +147,9 @@ LRESULT MainWindow::OnCreate()
m_xsampa = CreateWindow(WC_BUTTON, L"&X-SAMPA to IPA",
WS_CHILDWINDOW | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 0, 0,
m_hwnd, (HMENU) ZALGO_XSAMPA, GetInstance(), NULL);
m_xsampa_table = CreateWindow(WC_BUTTON, L"X-&SAMPA Table",
WS_CHILDWINDOW | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 0, 0,
m_hwnd, (HMENU) ZALGO_XSAMPA_TABLE, GetInstance(), NULL);
PostMessage(m_messUpDown, UDM_SETRANGE32, 1, ZALGO_MESS_LEVEL_OF(ZALGO_MAX_MESS));
PostMessage(m_messUpDown, UDM_SETPOS32, 0, ZALGO_MESS_LEVEL_OF(ZALGO_NORMAL_MESS));
@ -168,6 +172,7 @@ LRESULT MainWindow::OnCreate()
SETFONT(m_cyrillic);
SETFONT(m_greek);
SETFONT(m_xsampa);
SETFONT(m_xsampa_table);
#undef SETFONT
Button_SetCheck(m_goUp, 1);
@ -177,10 +182,14 @@ LRESULT MainWindow::OnCreate()
Edit_Enable(m_messLevel, 0);
if (!m_dropTarget.DragDropRegister(m_hwnd))
MessageBox(m_hwnd, TEXT("Failed to register Drag and Drop handler"),
TEXT("Zalgo has COME!!!"), MB_ICONERROR);
MessageBox(m_hwnd, L"Failed to register Drag and Drop handler",
L"Zalgo has COME!!!", MB_ICONERROR);
m_preview = PreviewWindow::Create(L"Text Preview");
m_data_display = PreviewWindow::Create(L"X-SAMPA Table");
lf.lfHeight = (LONG) (lf.lfHeight * 1.3);
lf.lfWidth = (LONG) (lf.lfWidth * 1.3);
m_data_display->SetFont(lf);
// Subclassing
wpOrigEditProc = (WNDPROC) SetWindowLongPtr(m_message,
@ -212,7 +221,9 @@ LRESULT MainWindow::OnDestroy()
DestroyWindow(m_cyrillic);
DestroyWindow(m_greek);
DestroyWindow(m_xsampa);
DestroyWindow(m_xsampa_table);
delete m_preview;
delete m_data_display;
return 0;
}
@ -248,25 +259,26 @@ LRESULT MainWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
GetClientRect(m_hwnd, &client);
#define REPOS(hwnd, k) hdwp = DeferWindowPos(hdwp, hwnd, 0, k, SWP_NOACTIVATE|SWP_NOZORDER)
hdwp = BeginDeferWindowPos(14);
REPOS(m_message, LEFT(12, 12, client.right - 24, client.bottom - 124));
REPOS(m_goUp, BOTTOM(12, client.bottom - 59, 140, 20));
REPOS(m_goMiddle, BOTTOM(12, client.bottom - 34, 140, 20));
REPOS(m_goDown, BOTTOM(12, client.bottom - 9, 140, 20));
REPOS(m_messMini, BOTTOM(160, client.bottom - 59, 120, 20));
REPOS(m_messNormal, BOTTOM(160, client.bottom - 34, 120, 20));
REPOS(m_messMax, BOTTOM(160, client.bottom - 9, 120, 20));
REPOS(m_messCustom, BOTTOM(280, client.bottom - 59, 120, 20));
REPOS(m_messLevel, BOTTOM(280, client.bottom - 38, 84, 20));
REPOS(m_messUpDown, BOTTOM(362, client.bottom - 38, 18, 20));
REPOS(m_mess, BOTTOMRIGHT(client.right - 12, client.bottom - 41, 100, 25));
REPOS(m_unmess, BOTTOMRIGHT(client.right - 12, client.bottom - 12, 100, 25));
REPOS(m_nfc, BOTTOMRIGHT(client.right - 117, client.bottom - 41, 50, 25));
REPOS(m_nfd, BOTTOMRIGHT(client.right - 117, client.bottom - 12, 50, 25));
REPOS(m_previewShow,BOTTOMRIGHT(client.right - 172, client.bottom - 12, 100, 25));
REPOS(m_latin, BOTTOM(12, client.bottom - 84, 100, 25));
REPOS(m_cyrillic, BOTTOM(117, client.bottom - 84, 100, 25));
REPOS(m_greek, BOTTOM(222, client.bottom - 84, 100, 25));
REPOS(m_xsampa, BOTTOM(327, client.bottom - 84, 100, 25));
REPOS(m_message, LEFT(12, 12, client.right - 24, client.bottom - 124));
REPOS(m_goUp, BOTTOM(12, client.bottom - 59, 140, 20));
REPOS(m_goMiddle, BOTTOM(12, client.bottom - 34, 140, 20));
REPOS(m_goDown, BOTTOM(12, client.bottom - 9, 140, 20));
REPOS(m_messMini, BOTTOM(160, client.bottom - 59, 120, 20));
REPOS(m_messNormal, BOTTOM(160, client.bottom - 34, 120, 20));
REPOS(m_messMax, BOTTOM(160, client.bottom - 9, 120, 20));
REPOS(m_messCustom, BOTTOM(280, client.bottom - 59, 120, 20));
REPOS(m_messLevel, BOTTOM(280, client.bottom - 38, 84, 20));
REPOS(m_messUpDown, BOTTOM(362, client.bottom - 38, 18, 20));
REPOS(m_mess, BOTTOMRIGHT(client.right - 12, client.bottom - 41, 100, 25));
REPOS(m_unmess, BOTTOMRIGHT(client.right - 12, client.bottom - 12, 100, 25));
REPOS(m_nfc, BOTTOMRIGHT(client.right - 117, client.bottom - 41, 50, 25));
REPOS(m_nfd, BOTTOMRIGHT(client.right - 117, client.bottom - 12, 50, 25));
REPOS(m_previewShow, BOTTOMRIGHT(client.right - 172, client.bottom - 12, 100, 25));
REPOS(m_latin, BOTTOM(12, client.bottom - 84, 100, 25));
REPOS(m_cyrillic, BOTTOM(117, client.bottom - 84, 100, 25));
REPOS(m_greek, BOTTOM(222, client.bottom - 84, 100, 25));
REPOS(m_xsampa, BOTTOM(327, client.bottom - 84, 100, 25));
REPOS(m_xsampa_table, BOTTOM(432, client.bottom - 84, 100, 25));
EndDeferWindowPos(hdwp);
#undef REPOS
return 0;
@ -288,8 +300,9 @@ LRESULT MainWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
text = new wchar_t[textlen];
Edit_GetText(m_message, text, textlen);
SendMessage(m_preview->GetHWND(), WM_CHANGETEXT, 0, (LPARAM) text);
ShowWindow(m_preview->GetHWND(), SW_SHOW);
m_preview->ChangeText(text);
m_preview->ShowWindow(SW_SHOW);
break;
}
case TEXT_TO_NFC:
OnTextNFC();
@ -314,6 +327,21 @@ LRESULT MainWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
case ZALGO_GO_DOWN:
Button_SetCheck((HWND) lParam, !IsDlgButtonChecked(m_hwnd, LOWORD(wParam)));
break;
case ZALGO_XSAMPA_TABLE: {
wchar_t *text;
SetWindowText(m_data_display->GetHWND(), L"X-SAMPA Table");
text = GetResourceString(RID_XSAMPA);
if (!text) {
MessageBox(m_hwnd, L"X-SAMPA table not found", L"X-SAMPA Error", MB_ICONERROR);
break;
}
m_data_display->ChangeText(text, false);
m_data_display->ShowWindow(SW_SHOW);
SetForegroundWindow(*m_data_display);
delete [] text;
break;
}
default:
Button_SetCheck(GetDlgItem(m_hwnd, ZALGO_MINI_MESS), 0);
Button_SetCheck(GetDlgItem(m_hwnd, ZALGO_NORMAL_MESS), 0);
@ -348,19 +376,16 @@ LRESULT MainWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (wParam == 'K' && GetKeyState(VK_CONTROL) < 0 &&
GetKeyState(VK_SHIFT) < 0 && GetKeyState(VK_MENU) < 0) {
static bool unlocked = false;
// A user has tried to go beyond max, let is work
if (!unlocked && MessageBox(m_hwnd, L"\
Thou hast tried to loosen my limits, dost thou promise that:\r\n\
1. thou will be responsible to use the string generated\r\n\
2. thou will be careful to not enter a number too large that will crash me\r\n\
3. if thou dost crash me, blame thyself for entering a number too large\r\n\
\r\n\
Dost thou agree?", L"About to Unlock Secret", MB_YESNO | MB_ICONQUESTION) == IDYES) {
LPWSTR text = GetResourceString(RID_LOOSE);
// A user has tried to go beyond max, let it work
if (!unlocked && MessageBox(m_hwnd, text,L"About to Unlock Secret",
MB_YESNO | MB_ICONQUESTION) == IDYES) {
PostMessage(m_messUpDown, UDM_SETRANGE32, 1, LONG_MAX);
PostMessage(m_messLevel, EM_SETREADONLY, 0, 0);
unlocked = true;
}
delete [] text;
return 0;
}
break;

View file

@ -5,29 +5,14 @@
LRESULT PreviewWindow::OnCreate()
{
NONCLIENTMETRICS ncmMetrics = { sizeof(NONCLIENTMETRICS) };
LOGFONT lf;
RECT client;
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncmMetrics, 0);
GetClientRect(m_hwnd, &client);
hFont = CreateFontIndirect(&ncmMetrics.lfMessageFont);
// Get the handle to the client area's device context.
HDC hdc = GetDC(m_hwnd);
TEXTMETRIC tm;
// Extract font dimensions from the text metrics.
GetTextMetrics(hdc, &tm);
xChar = tm.tmAveCharWidth;
xUpper =(tm.tmPitchAndFamily & 1 ? 3 : 2) * xChar/2;
yChar = tm.tmHeight + tm.tmExternalLeading;
// Free the device context.
ReleaseDC(m_hwnd, hdc);
// Set an arbitrary maximum width for client area.
//(xClientMax is the sum of the widths of 48 average
// lowercase letters and 12 uppercase letters.)
xClientMax = 48 * xChar + 12 * xUpper;
GetMessageFont(lf);
hFont = CreateFontIndirect(&lf);
SendMessage(m_hwnd, WM_SETFONT, (WPARAM) hFont, FALSE);
lpLines = NULL;
return 0;
}
@ -60,7 +45,7 @@ void PreviewWindow::OnPaint()
yPos = si.nPos;
SelectObject(ps.hdc, hFont);
SetBkColor(ps.hdc, RGB(0xF0, 0xF0, 0xF0));
SetBkMode(ps.hdc, TRANSPARENT);
// Find painting limits.
int FirstLine = max(0, yPos + ps.rcPaint.top / yChar);
int LastLine = min(lines - 1, yPos + ps.rcPaint.bottom / yChar);
@ -69,16 +54,101 @@ void PreviewWindow::OnPaint()
GetScrollInfo(m_hwnd, SB_HORZ, &si);
xPos = si.nPos;
for (int i = FirstLine; i <= LastLine; i++) {
int x = xChar *(1 - xPos);
int y = yChar *(i - yPos);
int x = xChar * (1 - xPos);
int y = yChar * (i - yPos);
rect.top = y;
rect.left = x;
DrawText(ps.hdc, lpLines[i], -1, &rect, DT_NOCLIP);
DrawText(ps.hdc, lpLines[i], -1, &rect, DT_EXPANDTABS | DT_NOCLIP | DT_NOPREFIX);
}
done:
EndPaint(m_hwnd, &ps);
}
void PreviewWindow::ChangeText(LPWSTR text, bool padding)
{
if (lpLines) {
for (int i = 0; i < lines; ++i)
delete [] lpLines[i];
delete [] lpLines;
}
int l = 0, longest = 0, maxlen = 0;
LPWSTR str = text;
if (*str == L'\0') {
empty = true;
lpLines = NULL;
} else empty = false;
while (*str++)
if (*str == L'\n')
++l;
if (*(str-1) != L'\n')
++l;
lines = l;
if (padding)
lines += 8;
lpLines = new LPTSTR[lines];
if (padding) {
for (int i = 0; i < 4; ++i) {
lpLines[i] = new TCHAR[1];
lpLines[i][0] = L'\0';
}
}
for (int i = 0; i < l; ++i) {
LPTSTR start = text, end, buf;
int len;
while (*text++ != L'\n' && *(text-1) != L'\0');
end = text - 1;
len = end - start;
if (len > maxlen) {
longest = i + (padding ? 4 : 0);
maxlen = len;
}
buf = new TCHAR[len + 1];
memcpy(buf, start, len*sizeof(TCHAR));
buf[len] = L'\0';
lpLines[i + (padding ? 4 : 0)] = buf;
}
if (padding) {
for (int i = l + 4; i < lines; ++i) {
lpLines[i] = new TCHAR[1];
lpLines[i][0] = L'\0';
}
}
int upper = 0, lower = 0;
for (LPTSTR i = lpLines[longest]; *i; ++i) {
if (isupper(*i))
++upper;
else if (!(*i >= 0x0300 && *i < 0x0370 || *i == 0x489))
++lower;
}
xClientMax = lower * xChar + upper * xUpper;
PostMessage(m_hwnd, WM_SIZE, 0, 0);
}
void PreviewWindow::SetFont(HFONT hFont)
{
if (used_logfont)
DeleteFont(this->hFont);
used_logfont = false;
SendMessage(m_hwnd, WM_SETFONT, (WPARAM) hFont, TRUE);
}
void PreviewWindow::SetFont(const LOGFONT &lf)
{
if (used_logfont)
DeleteFont(this->hFont);
used_logfont = true;
hFont = CreateFontIndirect(&lf);
SendMessage(m_hwnd, WM_SETFONT, (WPARAM) hFont, TRUE);
}
LRESULT PreviewWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
@ -230,69 +300,31 @@ LRESULT PreviewWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
}
return 0;
}
case WM_CHANGETEXT: {
if (lpLines) {
for (int i = 0; i < lines; ++i)
delete [] lpLines[i];
delete [] lpLines;
}
LPTSTR str = (LPTSTR) lParam;
int l = 0, longest = 0, maxlen = 0;
if (*str == L'\0') {
empty = true;
lpLines = NULL;
} else empty = false;
while (*str++)
if (*str == L'\n')
++l;
if (*(str-1) != L'\n')
++l;
lines = l + 8;
lpLines = new LPTSTR[lines];
for (int i = 0; i < 4; ++i) {
lpLines[i] = new TCHAR[1];
lpLines[i][0] = L'\0';
}
str = (LPTSTR) lParam;
for (int i = 0; i < l; ++i) {
LPTSTR start = str, end, buf;
int len;
while (*str++ != L'\n' && *(str-1) != L'\0');
end = str - 1;
len = end - start;
if (len > maxlen) {
longest = i+4;
maxlen = len;
}
buf = new TCHAR[len + 1];
memcpy(buf, start, len*sizeof(TCHAR));
buf[len] = L'\0';
lpLines[i+4] = buf;
}
for (int i = l + 4; i < lines; ++i) {
lpLines[i] = new TCHAR[1];
lpLines[i][0] = L'\0';
}
int upper = 0, lower = 0;
for (LPTSTR i = lpLines[longest]; *i; ++i) {
if (isupper(*i))
++upper;
else if (!(*i >= 0x0300 && *i < 0x0370 || *i == 0x489))
++lower;
}
xClientMax = lower * xChar + upper * xUpper;
PostMessage(m_hwnd, WM_SIZE, 0, 0);
case WM_CHANGETEXT:
ChangeText((LPTSTR) lParam, (wParam & 1) == 0);
return 0;
case WM_SETFONT: {
HDC hdc = GetDC(m_hwnd);
hFont = (HFONT) wParam;
HFONT hOldFont = SelectFont(hdc, hFont);
TEXTMETRIC tm;
// Extract font dimensions from the text metrics.
GetTextMetrics(hdc, &tm);
xChar = tm.tmAveCharWidth;
xUpper =(tm.tmPitchAndFamily & 1 ? 3 : 2) * xChar/2;
yChar = tm.tmHeight + tm.tmExternalLeading;
// Set an arbitrary maximum width for client area.
//(xClientMax is the sum of the widths of 48 average
// lowercase letters and 12 uppercase letters.)
xClientMax = 48 * xChar + 12 * xUpper;
SelectFont(hdc, hOldFont);
ReleaseDC(m_hwnd, hdc);
break;
}
case WM_CLOSE:
ShowWindow(m_hwnd, SW_HIDE);
ShowWindow(SW_HIDE);
return 0;
}

View file

@ -19,7 +19,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
MainWindow *win = MainWindow::Create(L"U̬̩͔̐̿ṅ̨̤̬̽i̛̘̳̹ͤ̍c̠̳̬͛o̘̳͗̿̈́d̗̅̓͗͠ḛ͍͛ ̬̠̹̉ͭ͛D̨̤̰̀̂ͦì̛͇͂a͍͇͛ͨͤc̡̟͖͗̔ͤͅr͔͇ͮ̓̍͢i̴͇͇̇͋̽t̛̟̟͋i̲̘̿̊c̺͎ͬ͗-̴̤́̔P̋̍҉͎̹ö̲̯͈̋͞l͎͂l̻̖ͩ̂͜u̵͔̳̇̋t̳̪͐̎e͈̓͢ḓ̗̭̓ ̹̫͛Ṭͫe̙̝̦̊̊̑͢x̶͉ͦ̚t̞̔̈́̀ ̡̪̪̙͒͗G̘̜̋e͍̯̻͋ͬͦn̹̩̫̑̈́ẽ͔̳r̠͙͒̀̅ͅa̭ͫ̓́t̘̺̋̏̚o̰̙̦ͪṛͦͣ́ͅ");
if (win) {
ShowWindow(win->GetHWND(), nCmdShow);
win->ShowWindow(nCmdShow);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);