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

📄 icontact.cpp

📁 This code is Address book code for Windows Mobile. This source code support windows mobile 5.0 over.
💻 CPP
📖 第 1 页 / 共 5 页
字号:

            // Time
            dt = t - tEndTime;

            // Velocity
            if (Scrolled < minScrolled)
                Velocity = (double)(Scrolled - minScrolled) / 2 / dt;
            else if (Scrolled > maxScrolled)
                Velocity = (double)(Scrolled - maxScrolled) / 2 / dt;
            else {
                double dv = Velocity * FRICTION_COEFF * dt;
                if (fabs(dv) > fabs(Velocity)) 
                    Velocity = 0;
                else 
			        Velocity = Velocity - dv;
            }

            // Displacement
            s = Velocity * dt;
            if (s < 0 && s > -1 && Scrolled < minScrolled)
                s = -1;
            else if (s > 0 && s < 1 && Scrolled > maxScrolled)
                s = 1;
            
            // We're done scrolling
            if ((int)s == 0) {
                KillTimer(hWnd, IDT_TIMER_SCROLL);
		        bScrolling = false;
		        Velocity = 0;
            }

            Scrolled = Scrolled - (int)s;
            tEndTime = t;
            if (stScreenType == stList)
                InvalidateRect(hWnd, &rList, false);
            else
                InvalidateRect(hWnd, &rContent, false);
		    break;

        ///// TIMER for scroll to
        case IDT_TIMER_SCROLL_TO:
            KillTimer(hWnd, IDT_TIMER_SCROLL);
            Scroll_TimeCounter = (double)(t - Scroll_StartTime);
            if (Scroll_TimeCounter < Scroll_Duration) {
                bScrolling = true;

                // Cubic
                double amount = Scroll_Change
                    * (pow(Scroll_TimeCounter/Scroll_Duration - 1, 3) + 1);
                Velocity = (amount - Scroll_StartPosition) / Scroll_TimeCounter;
                Scrolled = Scroll_StartPosition + (int)amount;
            }
            else {
                bScrolling = false;
                Velocity = 0;
                KillTimer(hWnd, IDT_TIMER_SCROLL_TO);
                Scrolled = Scroll_Change + Scroll_StartPosition;
            }
            if (stScreenType == stList)
                InvalidateRect(hWnd, &rList, false);
            else
                InvalidateRect(hWnd, &rContent, false);
            break;

        case IDT_TIMER_TRANSITION:
            // The list could be loading right now... wait till it's done
            if (!pListData) {
                break;
            }

            dTransitionPct = (double)(t - dwTransitionStart) 
                / nTransitionDuration;

            if (dTransitionPct >= 1.0) {
                dTransitionPct = 1.0;
                bTransitioning = false;

                if (trTransitionType == ttSlideRight) {
                    stScreenType = stList;
                    Scrolled = ListScrolled;
                    pListData->UnselectItem();
                    CalculateHeights();
                }
                else if (trTransitionType == ttSlideLeft) {
                    stScreenType = stDetails;
                    CalculateHeights();
                }
                else if (trTransitionType == ttKeyboardExpand) {
                    bDisplayingPopup = true;
                }
                else if (trTransitionType == ttKeyboardShrink) {
                    bDisplayingPopup = false;
                }

                KillTimer(hWnd, IDT_TIMER_TRANSITION);
            }
            InvalidateRect(hWnd, &rScreen, false);
            break;

        case IDT_TIMER_LOADLIST:
            SetCursor(LoadCursor(NULL, IDC_WAIT));

            pListData = 
                // Favorites
                nCurrentTab == 0 ? (ListData *)new ListDataPoom(pSettings, true)

                // Call Log
                : nCurrentTab == 1 ? (ListData *)new ListDataCallLog(pSettings)

                // Contacts
                : (ListData *)new ListDataPoom(pSettings);

            CalculateHeights();

            SetCursor(NULL);

            InvalidateRect(hWnd, &rHeader, false);
            KillTimer(hWnd, IDT_TIMER_LOADLIST);
            Scrolled = -rListHeight;
            ScrollTo(hWnd, 0);
            if (bTransitioning)
                dwTransitionStart = ::GetTickCount();
            break;
	} 

	UpdateWindow(hWnd);
	return 0;
}

//-----------------------------------------------------------------------------
// DoKeyDown - Process WM_KEYDOWN message for window
//
LRESULT DoKeyDown (HWND hWnd, UINT wMsg, WPARAM wParam,
                       LPARAM lParam) {
    int top = 0;
    int bot = 0;
    bool bRepeating = (lParam & (1 << 30)) != 0;
    int index;

    if (bTransitioning) {
        return 0;
    }

	switch (stScreenType) {

		case stList:
            if (bScrolling) {
                KillTimer(hWnd, IDT_TIMER_SCROLL);
			    bScrolling = false;
			    Velocity = 0;
            }

            if (bRepeating) {
                nKeyRepeatCount++;
                if (nKeyRepeatCount < 10)
                    bRepeating = false;
                else if (nKeyRepeatCount % 5 != 0)
                    return 0;
            }
            else {
                nKeyRepeatCount = 0;
            }

			switch (wParam) {
				case VK_UP:
                    pListData->SelectPreviousItem(
                        GetPixelToItem(Scrolled + rListHeight), bRepeating);

					// make sure the selected item is visible
                    index = pListData->GetCurrentItemIndex();
					top = StartPosition[index];
					bot = StartPosition[index + 1];

                    if (bScrolling) {
                        Scrolled = max(0, min(StartPosition[index], 
                            ListHeight - rListHeight));
                    }
					else if (!bScrolling && (top < Scrolled 
                        || bot > Scrolled + rListHeight)) {

                        Scrolled = max(0, bot - rListHeight);
                    }
    
					break;

			    case VK_DOWN:
                    pListData->SelectNextItem(
                        GetPixelToItem(Scrolled), bRepeating);

					// make sure the selected item is visible
                    index = pListData->GetCurrentItemIndex();
					top = StartPosition[index];
					bot = StartPosition[index + 1];

                    if (bScrolling) {
                        Scrolled = max(0, min(StartPosition[index], 
                            ListHeight - rListHeight));
                    }
                    else if (!bScrolling && (top < Scrolled 
                        || bot > Scrolled + rListHeight)) {
                            Scrolled = min(top, ListHeight - rListHeight);
                    }
    
					break;

                case VK_LEFT:
                    if (nCurrentTab > 0)
                        SwitchTab(hWnd, nCurrentTab - 1);
                    break;

                case VK_RIGHT:
                    if (nCurrentTab < 2)
                        SwitchTab(hWnd, nCurrentTab + 1);
                    break;

			    case VK_TACTION:
					if (pListData->GetCurrentItemIndex() >= 0)
                        StartTransition(hWnd, ttSlideLeft, 
                            EXPAND_DETAILS_PERIOD);
					break;

			}
            InvalidateRect(hWnd, &rList, FALSE);
			break;


		case stDetails:
			switch (wParam) {
                case VK_BACK:
				case VK_LEFT:
					pListData->SelectDetail(-1);
                    StartTransition(hWnd, ttSlideRight);
					break;

				case VK_UP:
					pListData->IncrementDetailIndex(-1);
					pListData->IncrementDetailIndex(-1);
                    // there's no "break" here on purpose, code optimization
				case VK_DOWN:
					pListData->IncrementDetailIndex(1);
                    top = DefaultItemHeight 
                        * pListData->GetCurrentDetailIndex();
                    bot = top + DefaultItemHeight;
                    if (top - Scrolled < 0)
                        ScrollTo(hWnd, max(0, 
                            rContent.top - rContent.bottom + bot));
                    if (bot - Scrolled > rContent.bottom - rContent.top)
                        ScrollTo(hWnd, max(
                            ListHeight - rContent.bottom + rContent.top, 
                            top));
					break;

                case VK_RIGHT:
			    case VK_TACTION:
                    HRESULT hr = pListData->PerformCurrentDetailAction(
                        wParam == VK_RIGHT ? 2 : 1);
                    
                    if (SUCCEEDED(hr)) {
                        if (pSettings->doExitOnAction)
                            DestroyWindow(hWnd);
                    }
                    else {
                        SwitchTab(hWnd, nCurrentTab);
                    }
					break;

			}
            InvalidateRect(hWnd, &rContent, FALSE);
			break;
	}
	UpdateWindow(hWnd);

    return DefWindowProc (hWnd, wMsg, wParam, lParam);
}

//-----------------------------------------------------------------------------
// DoCommand - Process WM_COMMAND message for window
//
LRESULT DoCommand (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {

    switch (wParam) {
        case CMD_GOTO_FAVORITES:
            SwitchTab(hWnd, 0);
            break;
        case CMD_GOTO_RECENTS:
            SwitchTab(hWnd, 1);
            break;
        case CMD_GOTO_CONTACTS:
            SwitchTab(hWnd, 2);
            break;
        case CMD_GOTO_DIALER:
            RunDialer();
            if (pSettings->doExitOnAction)
                DestroyWindow(hWnd);
            break;
        case CMD_GOTO_SEARCH:
            if (nCurrentTab != 2)
                SwitchTab(hWnd, 2);

            StartTransition(hWnd, ttKeyboardExpand, EXPAND_KEYBOARD_PERIOD);
            break;
    }

    InvalidateRect(hWnd, &rMenubar, FALSE);
    UpdateWindow(hWnd);

    return DefWindowProc (hWnd, wMsg, wParam, lParam);
}

//-----------------------------------------------------------------------------
// DoDestroyMain - Process WM_DESTROY message for window
//
LRESULT DoDestroyMain (HWND hWnd, UINT wMsg, WPARAM wParam, 
                       LPARAM lParam) {
   
    // Uninitialize the COM classes
    CoUninitialize();

    // Quit
    PostQuitMessage (0);
    return 0;
}

//-----------------------------------------------------------------------------
// Screen Drawing Functions
//
void DrawScreenOn(HDC hdc, ScreenType st, HDC hdcTmp, 
    RECT rClip, int yListOffset) {

    // MAIN CONTENT
    switch (st) {
        case stList:
            if (rClip.bottom > rList.top || rClip.top < rList.bottom)
                DrawListOn(hdc, hdcTmp, rList, yListOffset);

            // MENU BAR
            if (rClip.bottom > rMenubar.top) {
                int rMenubarWidth = rMenubar.right - rMenubar.left;

                // draw the background of the menu bar
                // This will stretch the first column of the menu bar
                // fully across the screen
                StretchBlt(hdc, rMenubar.left, rMenubar.top, 
                    rMenubarWidth, rMenubar.bottom - rMenubar.top,
                    hdcSkin, 0, SKIN_MENU_BAR_Y_OFFSET, 1, SKIN_MENU_BAR_HEIGHT, SRCCOPY);

                // draw buttons
                for (int i = 0; i < 5; i++) {
                    int xdest = rMenubar.left 
                        + rMenubarWidth / 10 * (2 * i + 1) - MenuBarIconWidth / 2;
                    int ydest = rMenubar.top;
                    int xsrc = i * SKIN_MENU_BAR_ICON_WIDTH;
                    int ysrc = i == nCurrentTab 
                        ? SKIN_MENU_BAR_SEL_Y_OFFSET 
                        : SKIN_MENU_BAR_Y_OFFSET;
                    StretchBlt(hdc, xdest, ydest, MenuBarIconWidth, MenuBarHeight, 
                        hdcSkin, xsrc, ysrc, SKIN_MENU_BAR_ICON_WIDTH, SKIN_MENU_BAR_HEIGHT,
                        SRCCOPY);
                }
            }
            break;
        case stDetails:
            DrawItemDetailsOn(hdc, pListData->GetCurrentItem(), yListOffset);
            break;
    }

    // TITLE BAR
    if (rClip.top < rTitlebar.bottom)
	    DrawTitlebarOn(hdc, rTitlebar, hdcSkin, TitlebarFont,
            pSettings->rgbTitlebarBackground, pSettings->rgbTitlebarText,
            pSettings->rgbTitlebarSignal, pSettings->rgbTitlebarBattery,
            pSettings->rgbTitlebarBatteryCharge);

    // HEADER BAR
    DrawHeaderOn(hdc, st, rHeader, hdcSkin);
}

void DrawListOn(HDC hdc, HDC hdcTmp, RECT rList, int yOffset) {
	int nFirstItem, nItem;
    Data dItemTmp;
    TCHAR buffer[16];
    int count = NULL == pListData ? 0 : pListData->GetItemCount();

    nFirstItem = nItem = yOffset < 0 ? 0 : GetPixelToItem(yOffset);

    RECT rItem;
    rItem = rList;

    rItem.bottom = rList.top + StartPosition[nItem] - yOffset;

	// ******* DRAW LIST BACKGROUND
	FillRect(hdc, &rList, pSettings->hbrListBackground);
	SetBkMode(hdc, TRANSPARENT);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -