thnks for ur response, i am still kind of confused though b/c i am new to api programming. here is my code could u tell me a little more info plz..
PHP Code:
// cMortMain.cpp -- main file for mortgage calculator
#include <fstream.h>
#include <iomanip.h>
#include "cMortgage.h"
#include <cstdlib>
#include <afxwin.h>
#include "resource.h"
#include <commdlg.h> // for color dialog
// - - - prototype - - -
LRESULT CALLBACK MyWndProc (HWND handle, UINT msg,
WPARAM wP, LPARAM lP) ;
BOOL CALLBACK DialogProc ( HWND handle, UINT msg,
WPARAM wP, LPARAM lP) ;
HINSTANCE hInst;
cMort Mortgage1;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR sCmdLine, int iCmdShow)
{
HWND hWnd ;
MSG msg ;
WNDCLASS wc ; // This is just a struct
TCHAR wcName[] = TEXT("Mortgage Calculator") ;
hInst = hInstance;
// Step 1: Register a window 'class'
wc.lpszClassName = wcName ;
wc.lpfnWndProc = MyWndProc; // Name of function that handles messages
// to windows based on this 'class'
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wc.hCursor = LoadCursor (NULL, IDC_ARROW) ;
// Option 1 for specifying a white window background
// wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
// Option 2 for specifying a nice window background color
HBRUSH hBrush;
hBrush = CreateSolidBrush (RGB(25,5,150));
wc.hbrBackground = hBrush;
// End window background options
wc.lpszMenuName = MAKEINTRESOURCE (IDR_MENU1);
wc.hInstance = hInstance ;
wc.cbClsExtra = 0 ;
wc.cbWndExtra = 0 ;
if (!RegisterClass (&wc)) return 0;
// Step 2: Create window based on above registered 'class'
hWnd = CreateWindow
(
wcName, // The name specifying the registed class
TEXT ("Mortgage Calculator"), // The window caption
WS_OVERLAPPEDWINDOW, // window style
20, // window position, left edge
30, // window position, top edge
500, // initial window width
300, // initial window height
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL // creation parameters
) ;
// Step 3: Show and update the window
ShowWindow (hWnd, iCmdShow) ;
UpdateWindow (hWnd) ;
// Step 4: Retrieve messages from message queue.
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;// Give message back to OS.
// Sends to appro 'WndProc'
}
DeleteObject (hBrush); // Comment out
// if use background option 1
return msg.wParam ;
}
// Note: Variables global so both
// MyWndProc() and DialogProc() can access them.
#define IDC_MYLISTBOX 764
LRESULT CALLBACK MyWndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
static COLORREF mTextColor = RGB(255,0,0);
static HFONT hFont;
static LOGFONT lf; // struct hold font details
static HWND hListBox1;
// - - - - - - - - -
UINT NotificationCode;
int idx;
CString tS; // temp string
HDC hDC ; //
PAINTSTRUCT ps ; // Invalid window info
double pay1 = 0, IntAmt = 0, Owe = 0, Balance = 0;
int t = 1;
char s[100], tSv[100];
ofstream fout;
switch (message)
{
case WM_CREATE:
hListBox1 = CreateWindow (TEXT("listbox"), NULL,
WS_CHILD | WS_VISIBLE |WS_BORDER |WS_VSCROLL |LBS_NOTIFY,
40,30, 400, 200,
hWnd, (HMENU)IDC_MYLISTBOX, hInst, NULL);
return 0 ;
case WM_PAINT: // Code must update the window COMPLETELY
hDC = BeginPaint (hWnd, &ps) ; // Get the device context handle
TextOut (hDC,40,10,"Payment Schedule",16);
SelectObject (hDC, hFont);
SetTextColor (hDC, mTextColor);
SetBkMode (hDC,TRANSPARENT) ;
EndPaint (hWnd, &ps) ;
return 0 ;
case WM_CHAR:
InvalidateRect (hWnd, NULL, TRUE); // send WM_PAINT msg
return 0;
case WM_KEYDOWN:
return 0;
case WM_LBUTTONDOWN :
return 0;
case WM_COMMAND:
// LOWORD(wParam) is id of menu option
switch (LOWORD (wParam))
{
case ID_EXIT:
SendMessage(hWnd, WM_DESTROY, 0,0);
return 0;
case ID_OPTIONS_ENTER:
DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1),
hWnd, DialogProc);
InvalidateRect(hWnd, NULL,TRUE);
pay1 = Mortgage1.calcPayment();
sprintf(s,"%-10s %-12s %-10s %-12s %-14s", "Pay #", "Interest($)", "Owe($)", "Payment($)",
"New Balance($)");
tS = s;
SendMessage (hListBox1, LB_ADDSTRING, 0,(LPARAM)(LPCTSTR)tS);
tS = "--------------------------------------------------------------------------------------------------";
SendMessage (hListBox1, LB_ADDSTRING, 0,(LPARAM)(LPCTSTR)tS);
Balance = Mortgage1.getBorrowed();
for (t; t <= (Mortgage1.getNumPayments()*Mortgage1.getYears()); t++)
{
IntAmt = (1.0/(Mortgage1.getNumPayments())*Mortgage1.getRate()*Balance);
Owe = Balance + IntAmt;
Balance = Owe - pay1;
sprintf(s,"%10i %12.2f %10.2f %12.2f %14.2f", t, IntAmt, Owe, pay1, Balance);
tS = s;
SendMessage (hListBox1, LB_ADDSTRING, 0,(LPARAM)(LPCTSTR)tS);
}
return 0;
case ID_CLEAR:
SendMessage (hListBox1, LB_RESETCONTENT, 0,0);
return 0;
case ID_OPTIONS_SAVE: //*****RIGHT HERE IS WHERE FILE IS SAVED***********************
fout << setprecision(2)<< setiosflags(ios::fixed);
fout.open ("LoanSchedule.txt");
fout << " Loan Repayment Schedule\n";
fout << "\n Amount borrowed ? " << Mortgage1.getBorrowed();
fout << "\n Annual interest rate ? " << Mortgage1.getRate();
fout << "\nNumber of payments per year ? " << Mortgage1.getNumPayments();
fout << "\n Number of years ? " << Mortgage1.getYears();
fout << "\n\n Each payment is : " << Mortgage1.getPayment() << "\n";
Balance = Mortgage1.getBorrowed();
fout << "\nPay # Interest Owe Payment New balance\n";
fout << setprecision(2)<< setiosflags(ios::fixed);
for ( t = 1; t <= (Mortgage1.getNumPayments()*Mortgage1.getYears()); t++)
{
IntAmt = (1.0/(Mortgage1.getNumPayments())*Mortgage1.getRate()*Balance);
Owe = Balance + IntAmt;
Balance = Owe - pay1;
fout << "\n" << setw(4) << t
<< setw(10) << IntAmt
<< setw(12) << Owe
<< setw(10) << Mortgage1.getPayment()
<< setw(12) << Balance;
}
MessageBox(hWnd,"File has been saved", "Message",MB_OK);
return 0;
case IDC_MYLISTBOX:
NotificationCode = HIWORD(wParam);
if (NotificationCode ==LBN_SELCHANGE )
{
idx = SendMessage (hListBox1, LB_GETCURSEL,0,0);
SendMessage (hListBox1, LB_GETTEXT, idx, (LPARAM)tSv);
}
return 0;
}
case WM_DESTROY:
PostQuitMessage (0);
fout.close();
return 0 ;
}
return DefWindowProc (hWnd, message, wParam, lParam) ;
}
BOOL CALLBACK DialogProc ( HWND hDlg, UINT msg,
WPARAM wP, LPARAM lP)
{
char tmpStr[100]; //temp string
const int Z = 0; //zero constant
char *dPointer = NULL; //pointer for atof()
double tempDub = 0; //temp variables for utility
int tempInt = 0;
switch (msg)
{
case WM_INITDIALOG: //zero all edit boxes
SetDlgItemInt (hDlg, IDC_MBORROWED, Z, TRUE);
SetDlgItemInt (hDlg, IDC_MRATE, Z, TRUE );
SetDlgItemInt (hDlg, IDC_MPAYMENTS, Z, TRUE);
SetDlgItemInt (hDlg, IDC_MYEARS, Z, TRUE );
return TRUE;
case WM_COMMAND:
switch(LOWORD(wP))
{
case IDOK : //extract values from edit boxes to mortgage class variables
GetDlgItemText (hDlg,IDC_MBORROWED, tmpStr, 100);
dPointer = tmpStr;
tempDub = atof(dPointer);
Mortgage1.setBorrowed(tempDub);
GetDlgItemText (hDlg,IDC_MRATE, tmpStr, 100);
dPointer = tmpStr;
tempDub = atof(dPointer);
Mortgage1.setRate(tempDub);
tempInt = GetDlgItemInt (hDlg,IDC_MPAYMENTS, NULL, 100);
Mortgage1.setNumPayments(tempInt);
tempInt = GetDlgItemInt (hDlg,IDC_MYEARS, NULL, 100);
Mortgage1.setYears(tempInt);
EndDialog (hDlg,TRUE);
return TRUE;
case IDCANCEL:
EndDialog (hDlg,FALSE);
return TRUE;
}
break;
}
return FALSE;
}
|