📄 xuesheng.txt
字号:
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static char * pText ;
static HGLOBAL hResource ;
static HWND hScroll ;
static int iPosition, cxChar, cyChar, cyClient, iNumLines, xScroll ;
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
TEXTMETRIC tm ;
switch (message)
{
case WM_CREATE :
hdc = GetDC (hwnd) ;
GetTextMetrics (hdc, &tm) ;
cxChar = tm.tmAveCharWidth ;
cyChar = tm.tmHeight + tm.tmExternalLeading ;
ReleaseDC (hwnd, hdc) ;
xScroll = GetSystemMetrics (SM_CXVSCROLL) ;
hScroll = CreateWindow (TEXT ("scrollbar"), NULL,
WS_CHILD | WS_VISIBLE | SBS_VERT,
0, 0, 0, 0,
hwnd, (HMENU) 1, hInst, NULL) ;
hResource = LoadResource (hInst,
FindResource (hInst, TEXT ("AnnabelLee"),
TEXT ("TEXT"))) ;
pText = (char *) LockResource (hResource) ;
iNumLines = 0 ;
while (*pText != '\\' && *pText != '\0')
{
if (*pText == '\n')
iNumLines ++ ;
pText = AnsiNext (pText) ;
}
*pText = '\0' ;
SetScrollRange (hScroll, SB_CTL, 0, iNumLines, FALSE) ;
SetScrollPos (hScroll, SB_CTL, 0, FALSE) ;
return 0 ;
case WM_SIZE :
MoveWindow (hScroll, LOWORD (lParam) - xScroll, 0,
xScroll, cyClient = HIWORD (lParam), TRUE) ;
SetFocus (hwnd) ;
return 0 ;
case WM_SETFOCUS :
SetFocus (hScroll) ;
return 0 ;
case WM_VSCROLL :
switch (wParam)
{
case SB_TOP :
iPosition = 0 ;
break ;
case SB_BOTTOM :
iPosition = iNumLines ;
break ;
case SB_LINEUP :
iPosition -= 1 ;
break ;
case SB_LINEDOWN :
iPosition += 1 ;
break ;
case SB_PAGEUP :
iPosition -= cyClient / cyChar ;
break ;
case SB_PAGEDOWN :
iPosition += cyClient / cyChar ;
break ;
case SB_THUMBPOSITION :
iPosition = LOWORD (lParam) ;
break ;
}
iPosition = max (0, min (iPosition, iNumLines)) ;
if (iPosition != GetScrollPos (hScroll, SB_CTL))
{
SetScrollPos (hScroll, SB_CTL, iPosition, TRUE) ;
InvalidateRect (hwnd, NULL, TRUE) ;
}
return 0 ;
case WM_PAINT :
hdc = BeginPaint (hwnd, &ps) ;
pText = (char *) LockResource (hResource) ;
GetClientRect (hwnd, &rect) ;
rect.left += cxChar ;
rect.top += cyChar * (1 - iPosition) ;
DrawTextA (hdc, pText, -1, &rect, DT_EXTERNALLEADING) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY :
FreeResource (hResource) ;
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
POEPOEM.RC (摘录)
//Microsoft Developer Studio generated resource script.
#include "resource.h"
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
// TEXT
ANNABELLEE TEXT DISCARDABLE "poepoem.txt"
/////////////////////////////////////////////////////////////////////////////
// Icon
POEPOEM ICON DISCARDABLE "poepoem.ico"
/////////////////////////////////////////////////////////////////////////////
// String Table
STRINGTABLE DISCARDABLE
BEGIN
IDS_APPNAME "PoePoem"
IDS_CAPTION """Annabel Lee"" by Edgar Allan Poe"
IDS_ERRMSG "This program requires Windows NT!"
END
RESOURCE.H (摘录)
// Microsoft Developer Studio generated include file.
// Used by PoePoem.rc
#define IDS_APPNAME 1
#define IDS_CAPTION 2
#define IDS_ERRMSG 3
POEPOEM.TXT
It was many and many a year ago,
In a kingdom by the sea,
That a maiden there lived whom you may know
By the name of Annabel Lee;
And this maiden she lived with no other thought
Than to love and be loved by me.
I was a child and she was a child
In this kingdom by the sea,
But we loved with a love that was more than love --
I and my Annabel Lee --
With a love that the winged seraphs of Heaven
Coveted her and me.
And this was the reason that, long ago,
In this kingdom by the sea,
A wind blew out of a cloud, chilling
My beautiful Annabel Lee;
So that her highborn kinsmen came
And bore her away from me,
To shut her up in a sepulchre
In this kingdom by the sea.
The angels, not half so happy in Heaven,
Went envying her and me --
Yes! that was the reason (as all men know,
In this kingdom by the sea)
That the wind came out of the cloud by night,
Chilling and killing my Annabel Lee.
But our love it was stronger by far than the love Of those who were older than we -- Of many far wiser than we --
And neither the angels in Heaven above
Nor the demons down under the sea
Can ever dissever my soul from the soul
Of the beautiful Annabel Lee:
For the moon never beams, without bringing me dreams
Of the beautiful Annabel Lee;
And the stars never rise, but I feel the bright eyes
Of the beautiful Annabel Lee:
And so, all the night-tide, I lie down by the side
Of my darling -- my darling -- my life and my bride,
In her sepulchre there by the sea --
In her tomb by the sounding sea.
[May, 1849]
\
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -