📄 doiview.cpp
字号:
SelectObject (hdc, hFontWnd);
ReleaseDC (hWnd, hdc);
InvalidateRect (hWnd, NULL, TRUE);
return 0;
}
//----------------------------------------------------------------------
// DoCommandMain - Process WM_COMMAND message for window.
//
//
LRESULT DoCommandMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
WORD idItem, wNotifyCode;
HWND hwndCtl;
int i;
// Parse the parameters.
idItem = (WORD) LOWORD (wParam);
wNotifyCode = (WORD) HIWORD(wParam);
hwndCtl = (HWND) lParam;
// Call routine to handle control message.
for (i = 0; i < dim(MainCommandItems); i++) {
if (idItem == MainCommandItems[i].Code)
return (*MainCommandItems[i].Fxn)(hWnd, idItem, hwndCtl,
wNotifyCode);
}
return 0;
}
//----------------------------------------------------------------------
// DoLButtonDownMain - Process WM_LBUTTONDOWN message for window.
//
LRESULT DoLButtonDownMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
HMENU hMenuMain, hMenu;
POINT pt;
int rc;
// Display the menu at the point of the tap
pt.x = LOWORD (lParam);
pt.y = HIWORD (lParam);
SHRGINFO sri;
sri.cbSize = sizeof (sri);
sri.dwFlags = 1;
sri.hwndClient = hWnd;
sri.ptDown = pt;
// See if tap and hold
rc = SHRecognizeGesture (&sri);
if (rc == 0) return 0;
// Display the menu at the point of the tap
MapWindowPoints (hWnd, HWND_DESKTOP, &pt, 1);
pt.x += 5;
hMenuMain = LoadMenu (hInst, MAKEINTRESOURCE (ID_MENU));
hMenu = GetSubMenu (hMenuMain, 0);
TPMPARAMS tpm;
tpm.cbSize = sizeof (tpm);
GetClientRect (hWnd, &tpm.rcExclude);
TrackPopupMenuEx (hMenu, TPM_LEFTALIGN | TPM_TOPALIGN,
pt.x, pt.y, hWnd, &tpm);
DestroyMenu (hMenuMain);
DestroyMenu (hMenu);
return 0;
}
//----------------------------------------------------------------------
// DoVScrollMain - Process WM_VSCROLL message for window.
//
LRESULT DoVScrollMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
RECT rect;
SCROLLINFO si;
int sOldPos = nVPos;
GetClientRect (hWnd, &rect);
switch (LOWORD (wParam)) {
case SB_LINEUP:
nVPos -= 1;
break;
case SB_LINEDOWN:
nVPos += 1;
break;
case SB_PAGEUP:
nVPos -= nLinesPerPage;
break;
case SB_PAGEDOWN:
nVPos += nLinesPerPage;
break;
case SB_THUMBTRACK: //只有当LOWORD (wParam)是SB_THUMBTRACK或
case SB_THUMBPOSITION: //SB_THUMBPOSITION时,HIWORD (wParam)才是有效的
nVPos = HIWORD (wParam);
break;
}
// Check range.
if (nVPos < 0)
nVPos = 0;
if (nVPos > nNumLines-1)
nVPos = nNumLines-1;
// If scroll position changed, update scrollbar and
// force redraw of window.
if (nVPos != sOldPos) {
si.cbSize = sizeof (si);
si.nPos = nVPos;
si.fMask = SIF_POS;
SetScrollInfo (hWnd, SB_VERT, &si, TRUE);
InvalidateRect (hWnd, NULL, TRUE);
}
return 0;
}
//----------------------------------------------------------------------
// DoPaintMain - Process WM_PAINT message for window.
//
LRESULT DoPaintMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
PAINTSTRUCT ps;
HFONT hFontWnd;
RECT rect;
HDC hdc;
int i, y = 5;
hdc = BeginPaint (hWnd, &ps);
GetClientRect (hWnd, &rect);
hFontWnd = (HFONT)SelectObject (hdc, hFont);
// Draw the text
for (i = nVPos; i < nNumLines; i++) {
if (y > rect.bottom - nFontHeight - 10) //如果一行都显示不下,可能是字体太大
break;
if (laText[i].nLen)
ExtTextOut (hdc, 5, y, TRANSPARENT, NULL, laText[i].pszLine,
laText[i].nLen, NULL);
y += nFontHeight;
}
SelectObject (hdc, hFontWnd);
EndPaint (hWnd, &ps);
return 0;
}
//----------------------------------------------------------------------
// DoDestroyMain - Process WM_DESTROY message for window.
//
LRESULT DoDestroyMain (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
PostQuitMessage (0);
return 0;
}
//======================================================================
// Command handler routines
//
//----------------------------------------------------------------------
// DoMainCommandHome - Process Program Home command.
//
LPARAM DoMainCommandHome (HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
SCROLLINFO si;
if (nVPos != 0) {
nVPos = 0;
si.cbSize = sizeof (si);
si.nPos = nVPos;
si.fMask = SIF_POS;
SetScrollInfo (hWnd, SB_VERT, &si, TRUE);
InvalidateRect (hWnd, NULL, TRUE);
}
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandEnd - Process End command.
//
LPARAM DoMainCommandEnd (HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
SCROLLINFO si;
int nEndPos = nNumLines - nLinesPerPage + 1; //最后一页要有显示,也要有空白,表明文档已完
if (nVPos != nEndPos) {
nVPos = nEndPos;
si.cbSize = sizeof (si);
si.nPos = nVPos;
si.fMask = SIF_POS;
SetScrollInfo (hWnd, SB_VERT, &si, TRUE);
InvalidateRect (hWnd, NULL, TRUE);
}
return 0;
}
//----------------------------------------------------------------------
// DoMainCommandExit - Process Program Exit command.
//
LPARAM DoMainCommandExit (HWND hWnd, WORD idItem, HWND hwndCtl,
WORD wNotifyCode) {
SendMessage (hWnd, WM_CLOSE, 0, 0);
return 0;
}
//----------------------------------------------------------------------
// WrapString - Determine a length that will fit with a width
//
LPTSTR WrapString (HDC hdc, LPTSTR pszText, int *pnLen, int nWidth,
BOOL *fEOL) {
LPTSTR pszStr, pszStart;
SIZE Size;
*fEOL = FALSE;
*pnLen = 0;
// Skip to first non-space char
for (; (*pszText!=TEXT('\0')) && (*pszText<=TEXT (' ')); pszText++);
pszStart = pszText;
if (*pszText == 0) //pszText一上来就指向一个空字符串
return 0;
while (1) {
pszStr = pszText; //如果pszText多读了个单词,超过了行宽,则新读的单词作废,该行的结尾还在上一单词结尾处,即pszStr处
// Find end of the next word
for (; (*pszText!=TEXT('\0')) && *pszText>TEXT (' ');pszText++); //一个词一个词地读
// Get length of the string
GetTextExtentPoint (hdc, pszStart, pszText - pszStart, &Size);
if (Size.cx > nWidth)
break;
if ((*pszText == TEXT ('\0')) || (*pszText == TEXT ('\r')) ||
(*pszText == TEXT ('\n'))) {
*fEOL = TRUE;
pszStr = pszText;
break;
}
// slip past space
pszText++; //只有读到空格字符才会执行到这里
}
*pnLen = pszStr - pszStart;
return pszStart;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -