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

📄 tttt.cpp

📁 贷款计算器(smartphone版)MFC/C++/.net/smartphone四版本合一
💻 CPP
字号:
// tttt.cpp : Defines the entry point for the application.
//

#include <windows.h>
#include <windowsx.h>
#include <aygshell.h>
#include <tpcshell.h>
#include "resource.h"

HINSTANCE g_hInst = NULL;  // Local copy of hInstance

#define ARRAY_LENGTH(a)   (sizeof(a)/sizeof(*a))
#define EINITFAILED		(-1)

//const TCHAR* g_szAppWndClass = TEXT("HelloApp");

//TCHAR g_szMessage[30];
const TCHAR* g_tszTitle = TEXT("贷款计算器(等额本息)");


/**************************************************************************************

   InitDialog

 **************************************************************************************/
BOOL InitDialog(
    const HWND hDlg, 
    UINT nToolBarId
    )
{
	// Specify that the dialog box should stretch full screen
	SHINITDLGINFO shidi;
	ZeroMemory(&shidi, sizeof(shidi));
	shidi.dwMask = SHIDIM_FLAGS;
	shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
	shidi.hDlg = hDlg;

	// set up Soft Keys menu
	SHMENUBARINFO mbi;
	ZeroMemory(&mbi, sizeof(SHMENUBARINFO));
	mbi.cbSize = sizeof(SHMENUBARINFO);
	mbi.hwndParent = hDlg;
	mbi.nToolBarId = nToolBarId;
	mbi.hInstRes = g_hInst;

	// If we could not initialize the dialog box, return an error
	if (FALSE == (SHInitDialog(&shidi) && SHCreateMenuBar(&mbi))) {
		return FALSE;
	}

	// set the title bar
	VERIFY(SetWindowText(hDlg, g_tszTitle));

	// In order to make Back work properly, it's necessary to 
	// override it and then call the appropriate SH API
	(void)SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK, 
					  MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, 
								 SHMBOF_NODEFAULT | SHMBOF_NOTIFY));

	return TRUE;
}
/**************************************************************************************

BOOL   ChangeChar(cTemp);

 **************************************************************************************/
char * ChangeChar(char *cTemp)
{
					cTemp[1] = cTemp[2];
					cTemp[2] = cTemp[4];
					cTemp[3] = cTemp[6];
					cTemp[4] = cTemp[8];
					cTemp[5] = cTemp[10];
					cTemp[6] = cTemp[12];
					cTemp[7] = cTemp[14];
					cTemp[8] = cTemp[16];
					return cTemp;
}
/**************************************************************************************

   DlgProc

 **************************************************************************************/

BOOL CALLBACK DlgProc(
    const HWND hDlg, 
    const UINT uiMessage, 
    const WPARAM wParam, 
    const LPARAM lParam
    )
{
	BOOL	bProcessedMsg = TRUE;
	HWND	hwnd1;
	HWND	hwnd2;
	HWND	hwnd3;
	HWND	hwnd4;
	int		iResult;
	TCHAR tszTemp[32];
	char cTemp[16];
//	LPTSTR cTemp = TEXT("");

	switch(uiMessage)
	{
		case WM_INITDIALOG:
			if (!InitDialog(hDlg, IDR_MENUBAR1)) 
            {
				EndDialog(hDlg, EINITFAILED);
			}

			// get handles to the listboxen
			VERIFY(hwnd1 = GetDlgItem(hDlg, IDC_EDIT1));
			VERIFY(hwnd2 = GetDlgItem(hDlg, IDC_EDIT2));
			VERIFY(hwnd3 = GetDlgItem(hDlg, IDC_EDIT3));
			VERIFY(hwnd4 = GetDlgItem(hDlg, IDC_EDIT11));

			// populate the listboxen
			_sntprintf(tszTemp, ARRAY_LENGTH(tszTemp), TEXT("250000"));
			iResult = SendMessage(hwnd1, WM_SETTEXT, 0, (LPARAM) tszTemp);
			_sntprintf(tszTemp, ARRAY_LENGTH(tszTemp), TEXT("5.5"));
			iResult = SendMessage(hwnd2, WM_SETTEXT, 0, (LPARAM) tszTemp);
			_sntprintf(tszTemp, ARRAY_LENGTH(tszTemp), TEXT("5"));
			iResult = SendMessage(hwnd3, WM_SETTEXT, 0, (LPARAM) tszTemp);
			_sntprintf(tszTemp, ARRAY_LENGTH(tszTemp), TEXT("0"));
			iResult = SendMessage(hwnd4, WM_SETTEXT, 0, (LPARAM) tszTemp);


			break;

		case WM_COMMAND:
			switch (wParam) 
            {			
				case ID_MENUEXIT:
                    {
						EndDialog(hDlg, 0);
					}
					break;

				case ID_MENUOUT:
					{
//	CString sEdit1,sEdit2,sEdit3,fEdit4,strTemp;
	double fEdit1,fEdit2,fEdit3,n,avePay,total,allAccrual,leaveCorpus,aveInterest,aveCorpus;
					VERIFY(hwnd1 = GetDlgItem(hDlg, IDC_EDIT1));
					VERIFY(hwnd2 = GetDlgItem(hDlg, IDC_EDIT2));
					VERIFY(hwnd3 = GetDlgItem(hDlg, IDC_EDIT3));
					VERIFY(hwnd4 = GetDlgItem(hDlg, IDC_EDIT11));
					SendMessage(hwnd1, WM_GETTEXT, sizeof(cTemp), (LPARAM) cTemp);
					fEdit1 = atof(ChangeChar(cTemp));
					SendMessage(hwnd2, WM_GETTEXT, sizeof(cTemp), (LPARAM) cTemp);
					fEdit2 = atof(ChangeChar(cTemp)) / 1200.0;
					SendMessage(hwnd3, WM_GETTEXT, sizeof(cTemp), (LPARAM) cTemp);
					fEdit3 = atof(ChangeChar(cTemp)) * 12.0;
					SendMessage(hwnd4, WM_GETTEXT, sizeof(cTemp), (LPARAM) cTemp);
					n = atof(ChangeChar(cTemp));
					
//每月还款
	avePay = ( fEdit1 * fEdit2 * pow(1+fEdit2,fEdit3))  /  (pow(1+fEdit2,fEdit3)-1);
//还款总额
//	total = fEdit1 * fEdit2 * fEdit3 * pow(1+fEdit2,fEdit3)  /  (pow(1+fEdit2,fEdit3)-1);
	total = avePay * fEdit3;
//利息总额
//	allAccrual = fEdit1 * ((fEdit2 * fEdit3-1) * pow(1+fEdit2,fEdit3)+1)  /  (pow(1+fEdit2,fEdit3)-1);
	allAccrual = total - fEdit1;
//剩余本金
	leaveCorpus = fEdit1 * (pow(1+fEdit2,fEdit3) - pow(1+fEdit2,n))  /  (pow(1+fEdit2,fEdit3)-1);
//本月本金
	aveCorpus = fEdit1 * fEdit2 * pow(1+fEdit2,n) /(pow(1+fEdit2,fEdit3)-1);
//本月利息
//	aveInterest = fEdit1 * fEdit2 * (pow(1+fEdit2,fEdit3) - pow(1+fEdit2,n)) / (pow(1+fEdit2,fEdit3)-1);
	aveInterest = avePay - aveCorpus;
	
					VERIFY(hwnd4 = GetDlgItem(hDlg, IDC_EDIT4));
			_sntprintf(tszTemp, ARRAY_LENGTH(tszTemp), TEXT("%f"),avePay);
			iResult = SendMessage(hwnd4, WM_SETTEXT, 0, (LPARAM) tszTemp);

					VERIFY(hwnd4 = GetDlgItem(hDlg, IDC_EDIT5));
			_sntprintf(tszTemp, ARRAY_LENGTH(tszTemp), TEXT("%f"),total);
			iResult = SendMessage(hwnd4, WM_SETTEXT, 0, (LPARAM) tszTemp);

					VERIFY(hwnd4 = GetDlgItem(hDlg, IDC_EDIT6));
			_sntprintf(tszTemp, ARRAY_LENGTH(tszTemp), TEXT("%f"),allAccrual);
			iResult = SendMessage(hwnd4, WM_SETTEXT, 0, (LPARAM) tszTemp);

					VERIFY(hwnd4 = GetDlgItem(hDlg, IDC_EDIT7));
			_sntprintf(tszTemp, ARRAY_LENGTH(tszTemp), TEXT("%f"),leaveCorpus);
			iResult = SendMessage(hwnd4, WM_SETTEXT, 0, (LPARAM) tszTemp);

					VERIFY(hwnd4 = GetDlgItem(hDlg, IDC_EDIT8));
			_sntprintf(tszTemp, ARRAY_LENGTH(tszTemp), TEXT("%f"),aveInterest);
			iResult = SendMessage(hwnd4, WM_SETTEXT, 0, (LPARAM) tszTemp);

					VERIFY(hwnd4 = GetDlgItem(hDlg, IDC_EDIT9));
			_sntprintf(tszTemp, ARRAY_LENGTH(tszTemp), TEXT("%f"),aveCorpus);
			iResult = SendMessage(hwnd4, WM_SETTEXT, 0, (LPARAM) tszTemp);
					}
					break;

				default:
					bProcessedMsg = FALSE;
					break;
			}
			break;
		case WM_HOTKEY:
		if (VK_TBACK == HIWORD(lParam) )//&& (0 != (MOD_KEYUP & LOWORD(lParam)))
		{
			SHSendBackToFocusWindow(uiMessage, wParam, lParam);
		}
		break;
		
		default:
			bProcessedMsg = FALSE;
			break;
	}

	return bProcessedMsg;
}
/**************************************************************************************

   OnCreate

 **************************************************************************************/
/*LRESULT OnCreate(
    HWND hwnd,
    CREATESTRUCT* lParam
    )
{
    // create the menu bar
    SHMENUBARINFO mbi;
    ZeroMemory(&mbi, sizeof(SHMENUBARINFO));
    mbi.cbSize = sizeof(SHMENUBARINFO);
    mbi.hwndParent = hwnd;
    mbi.nToolBarId = IDR_HELLO_MENUBAR;
    mbi.hInstRes = g_hInst;
    if(!SHCreateMenuBar(&mbi))
    {
        // Couldn't create the menu bar.  Fail creation of the window.
        return(-1);
    }

    // Get our message text.
    if(0 == LoadString(g_hInst, IDS_HELLO_MESSAGE, g_szMessage, ARRAY_LENGTH(g_szMessage)))
    {
        // Couldn't load the string.  Fail creation of the window.
        return(-1);
    }

    // Do other window creation related things here.

    return(0); // continue creation of the window
}*/

/**************************************************************************************

   WndProc

 **************************************************************************************/
/*LRESULT CALLBACK WndProc(
    HWND hwnd,
    UINT msg,
    WPARAM wp,
    LPARAM lp
    )
{
    LRESULT lResult = TRUE;

    switch(msg)
    {
        case WM_CREATE:
            lResult = OnCreate(hwnd, (CREATESTRUCT*)lp);
            break;

        case WM_COMMAND:
            switch (wp)
            {
                case IDOK:
                    DestroyWindow(hwnd);
                    break;
                default:
                    goto DoDefault;
            }
            break;

        case WM_PAINT:
            {
                HDC hdc;
                PAINTSTRUCT ps;
                RECT rect;

                hdc = BeginPaint(hwnd, &ps);
                GetClientRect(hwnd, &rect);

                DrawText(hdc, g_szMessage, -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
                EndPaint (hwnd, &ps);
            }
            break;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;

        DoDefault:
        default:
            lResult = DefWindowProc(hwnd, msg, wp, lp);
            break;
    }

    return(lResult);
}*/

/****************************************************************************

   ActivatePreviousInstance

  ****************************************************************************/
/*HRESULT ActivatePreviousInstance(
    const TCHAR* pszClass,
    const TCHAR* pszTitle,
    BOOL* pfActivated
    )
{
    HRESULT hr = S_OK;
    int cTries;
    HANDLE hMutex = NULL;

    *pfActivated = FALSE;
    cTries = 5;
    while(cTries > 0)
    {
        hMutex = CreateMutex(NULL, FALSE, pszClass); // NOTE: We don't want to own the object.
        if(NULL == hMutex)
        {
            // Something bad happened, fail.
            hr = E_FAIL;
            goto Exit;
        }

        if(GetLastError() == ERROR_ALREADY_EXISTS)
        {
            HWND hwnd;

            CloseHandle(hMutex);
            hMutex = NULL;

            // There is already an instance of this app
            // running.  Try to bring it to the foreground.

            hwnd = FindWindow(pszClass, pszTitle);
            if(NULL == hwnd)
            {
                // It's possible that the other window is in the process of being created...
                Sleep(500);
                hwnd = FindWindow(pszClass, pszTitle);
            }

            if(NULL != hwnd) 
            {
                // Set the previous instance as the foreground window

                // The "| 0x01" in the code below activates
                // the correct owned window of the
                // previous instance's main window.
                SetForegroundWindow((HWND) (((ULONG) hwnd) | 0x01));

                // We are done.
                *pfActivated = TRUE;
                break;
            }

            // It's possible that the instance we found isn't coming up,
            // but rather is going down.  Try again.
            cTries--;
        }
        else
        {
            // We were the first one to create the mutex
            // so that makes us the main instance.  'leak'
            // the mutex in this function so it gets cleaned
            // up by the OS when this instance exits.
            break;
        }
    }

    if(cTries <= 0)
    {
        // Someone else owns the mutex but we cannot find
        // their main window to activate.
        hr = E_FAIL;
        goto Exit;
    }

Exit:
    return(hr);
}*/


/*****************************************************************************

  WinMain

  ***************************************************************************/

int WINAPI WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPWSTR lpCmdLine,
    int nCmdShow
    )
{
    g_hInst = hInstance;
/*    MSG msg;
    HWND hwnd = NULL;
    BOOL fActivated;
    HWND hwndMain;
    TCHAR szAppTitle[20];

    WNDCLASS wc;

    // Register our main window's class.
    ZeroMemory(&wc, sizeof(wc));
    wc.style = CS_HREDRAW | CS_VREDRAW ;
    wc.lpfnWndProc = (WNDPROC)WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hIcon = NULL;
    wc.hInstance = g_hInst;
    wc.hCursor = NULL;
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = g_szAppWndClass;
    if(!RegisterClass(&wc))
    {
        return(0);
    }

    if(0 == LoadString(g_hInst, IDS_HELLO_TITLE, szAppTitle, ARRAY_LENGTH(szAppTitle)))
    {
        return(0);
    }

    if(FAILED(ActivatePreviousInstance(g_szAppWndClass, szAppTitle, &fActivated)) ||
            fActivated)
    {
        return(0);
    }
	
    // Create the main window.    
    hwndMain = CreateWindow(g_szAppWndClass, szAppTitle,
            WS_CLIPCHILDREN, // Setting this to 0 gives a default style we don't want.  Use a benign style bit instead.
            CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
            NULL, NULL, g_hInst, NULL );
    if(!hwndMain)
    {
        return(0);
    }

    ShowWindow(hwndMain, nCmdShow);
    UpdateWindow(hwndMain);*/
	DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_MAIN), NULL, (DLGPROC) DlgProc);
	return 0;
//						DestroyWindow(hwndMain);
//MessageBox(hwndMain,TEXT("Already connected to specified resource."), TEXT("Info"), MB_OK);

    // Pump messages until a PostQuitMessage.
/*    while(GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage (&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;*/
}

// end tttt.cpp

⌨️ 快捷键说明

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