⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doiview.cpp

📁 《Windows CE 6.0开发者参考》(《Programming Windows Embedded CE 6.0 Developer Reference》)第四版书中的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    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) {
    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
	ShowContextMenu (hWnd, pt);
    return 0;
}
//----------------------------------------------------------------------
// DoRButtonDownMain - Process WM_RBUTTONDOWN message for window.
//
LRESULT DoRButtonDownMain (HWND hWnd, UINT wMsg, WPARAM wParam, 
                           LPARAM lParam) {
    POINT pt;

    // Display the menu at the point of the tap
    pt.x = LOWORD (lParam);
    pt.y = HIWORD (lParam);
	ShowContextMenu (hWnd, pt);
    return 0;
}
//----------------------------------------------------------------------
// DoMouseWheelMain - Process WM_MOUSEWHEEL message for window.
//
LRESULT DoMouseWheelMain (HWND hWnd, UINT wMsg, WPARAM wParam,
                          LPARAM lParam) {
	// Get the number of clicks the wheel turned
	int nScrollLines = GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA;

	// Compute the new position
	int nNewPos = nVPos - nScrollLines;
	// Set the scroll bar and invalidate the window
	MyScrollWnd (hWnd, nNewPos);
	return 0;
}
//----------------------------------------------------------------------
// DoVScrollMain - Process WM_VSCROLL message for window.
//
LRESULT DoVScrollMain (HWND hWnd, UINT wMsg, WPARAM wParam,
                       LPARAM lParam) {
    int nNewPos = nVPos;

    switch (LOWORD (wParam)) {
    case SB_LINEUP:
        nNewPos -= 1;
        break;

    case SB_LINEDOWN:
        nNewPos += 1;
        break;

    case SB_PAGEUP:
        nNewPos -= nLinesPerPage;
        break;

    case SB_PAGEDOWN:
        nNewPos += nLinesPerPage;
        break;

    case SB_THUMBTRACK:
    case SB_THUMBPOSITION:
        nNewPos = HIWORD (wParam);
        break;
    }
	MyScrollWnd (hWnd, nNewPos);
    return 0;
}
//----------------------------------------------------------------------
// DoPaintMain - Process WM_PAINT message for window.
//
LRESULT DoPaintMain (HWND hWnd, UINT wMsg, WPARAM wParam, 
                     LPARAM lParam) {
    PAINTSTRUCT ps;
    HFONT hFontOld;
    RECT rect;
    HDC hdc;
    int i, y = 5;

    GetClientRect (hWnd, &rect);

    hdc = BeginPaint (hWnd, &ps);

	// Select our font
	hFontOld = (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, hFontOld);
    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;
}
//----------------------------------------------------------------------
// MyScrollWnd - Adjust the scroll bar and invalidate the window to
// force a repaint at the new top line.
//
int MyScrollWnd (HWND hWnd, int nNewPos) {
    SCROLLINFO si;
 
	// Check range.
    if (nNewPos < 0)
        nNewPos = 0;
    if (nNewPos > nNumLines-nLinesPerPage+1)
        nNewPos = nNumLines-nLinesPerPage+1;

    // If scroll position changed, update scrollbar and
    // force redraw of window.
    if (nVPos != nNewPos) {
		nVPos = nNewPos;
        si.cbSize = sizeof (si);
        si.nPos = nVPos;
        si.fMask = SIF_POS;
        SetScrollInfo (hWnd, SB_VERT, &si, TRUE);

		// The scrolling is actually done by redrawing the wnd at
		// the new position.  Not very fast but fine in this case.
        InvalidateRect (hWnd, NULL, TRUE);
    }
	return 0;
}
//----------------------------------------------------------------------
// ShowContextMenu - Display a context menu
//
int ShowContextMenu (HWND hWnd, POINT pt) {
    HMENU hMenuMain, hMenu;

    // 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;
}
//----------------------------------------------------------------------
// 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)
        return 0;

    while (1) {
        pszStr = pszText;
        // 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 + -