// repentDlg.cpp : implementation file // //jtp #include #include #include "stdafx.h" #include "repent.h" #include "repentDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRepentDlg dialog //jtp long myFunction(CWnd*, CWnd*, CWnd*, CWnd*); CRepentDlg::CRepentDlg(CWnd* pParent /*=NULL*/) : CDialog(CRepentDlg::IDD, pParent) { //{{AFX_DATA_INIT(CRepentDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1); } void CRepentDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CRepentDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CRepentDlg, CDialog) //{{AFX_MSG_MAP(CRepentDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(BRoll, OnBRoll) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRepentDlg message handlers BOOL CRepentDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here //jtp /* Seed the random-number generator with current time so that * the numbers will be different every time we run. */ srand( (unsigned)time( NULL ) ); return TRUE; // return TRUE unless you set the focus to a control } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CRepentDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CRepentDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CRepentDlg::OnBRoll() { long result; char textToAppend[100000]; CWnd* nameWnd; CWnd* rankWnd; CWnd* rollWnd; CWnd* outWnd; char buffer [33]; //set up our structure struct maxRoller{CString name;long maxRoll;}; //create a array of structures maxRoller MR; MR.maxRoll=0; UpdateData(); rankWnd = GetDlgItem(rank1); nameWnd = GetDlgItem(name1); rollWnd = GetDlgItem(roll1); outWnd = GetDlgItem(myOutput); //tell the range before starting all our calculations strcpy(textToAppend,"rolling from 1 to 32000"); strcat(textToAppend,"\r\n"); outWnd->SetWindowText(textToAppend); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank2); nameWnd = GetDlgItem(name2); rollWnd = GetDlgItem(roll2); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank3); nameWnd = GetDlgItem(name3); rollWnd = GetDlgItem(roll3); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank4); nameWnd = GetDlgItem(name4); rollWnd = GetDlgItem(roll4); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank5); nameWnd = GetDlgItem(name5); rollWnd = GetDlgItem(roll5); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank6); nameWnd = GetDlgItem(name6); rollWnd = GetDlgItem(roll6); outWnd = GetDlgItem(myOutput); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank7); nameWnd = GetDlgItem(name7); rollWnd = GetDlgItem(roll7); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank8); nameWnd = GetDlgItem(name8); rollWnd = GetDlgItem(roll8); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank9); nameWnd = GetDlgItem(name9); rollWnd = GetDlgItem(roll9); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank10); nameWnd = GetDlgItem(name10); rollWnd = GetDlgItem(roll10); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank11); nameWnd = GetDlgItem(name11); rollWnd = GetDlgItem(roll11); outWnd = GetDlgItem(myOutput); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank12); nameWnd = GetDlgItem(name12); rollWnd = GetDlgItem(roll12); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank13); nameWnd = GetDlgItem(name13); rollWnd = GetDlgItem(roll13); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank14); nameWnd = GetDlgItem(name14); rollWnd = GetDlgItem(roll14); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank15); nameWnd = GetDlgItem(name15); rollWnd = GetDlgItem(roll15); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank16); nameWnd = GetDlgItem(name16); rollWnd = GetDlgItem(roll16); outWnd = GetDlgItem(myOutput); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank17); nameWnd = GetDlgItem(name17); rollWnd = GetDlgItem(roll17); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank18); nameWnd = GetDlgItem(name18); rollWnd = GetDlgItem(roll18); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank19); nameWnd = GetDlgItem(name19); rollWnd = GetDlgItem(roll19); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank20); nameWnd = GetDlgItem(name20); rollWnd = GetDlgItem(roll20); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank21); nameWnd = GetDlgItem(name21); rollWnd = GetDlgItem(roll21); outWnd = GetDlgItem(myOutput); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank22); nameWnd = GetDlgItem(name22); rollWnd = GetDlgItem(roll22); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank23); nameWnd = GetDlgItem(name23); rollWnd = GetDlgItem(roll23); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank24); nameWnd = GetDlgItem(name24); rollWnd = GetDlgItem(roll24); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } rankWnd = GetDlgItem(rank25); nameWnd = GetDlgItem(name25); rollWnd = GetDlgItem(roll25); result = myFunction(nameWnd,rankWnd,rollWnd,outWnd); if(result > MR.maxRoll){ MR.maxRoll=result; nameWnd->GetWindowText(MR.name); } //UpdateData(FALSE); strcat(textToAppend,MR.name); strcat(textToAppend," wins with "); strcat(textToAppend, itoa(MR.maxRoll,buffer,10)); strcat(textToAppend,"\r\n"); outWnd->SetWindowText(textToAppend); } long myFunction(CWnd* nameWnd,CWnd* rankWnd, CWnd* rollWnd, CWnd* outWnd){ long i; long range; long maxRoll; char buffer [33]; long roll; long rank; CString name; range=32000; maxRoll=0; CString str; //get the rank rankWnd->GetWindowText(str); rank=atoi(str); //get the guys name nameWnd->GetWindowText(name); // //output 'names' rank is 'rank' // strcat(textToAppend,name); // strcat(textToAppend, "'s rank: "); // strcat(textToAppend,itoa(rank,buffer,10)); // strcat(textToAppend,"\r\n"); // outWnd->SetWindowText(textToAppend); //roll rank # of times for(i=1;i<=rank;i++){ //make the roll using rand and the modulo operator roll=(rand()%(range))+1; // //output each roll // strcat(textToAppend,itoa(roll,buffer,10)); // strcat(textToAppend,","); // outWnd->SetWindowText(textToAppend); //store the best roll if(roll > maxRoll){ maxRoll=roll; } } // //output resultstrcat(textToAppend,name); // strcat(textToAppend, "The best roll was "); // strcat(textToAppend,itoa(maxRoll,buffer,10)); // strcat(textToAppend,"\r\n"); // outWnd->SetWindowText(textToAppend); rollWnd->SetWindowText(itoa(maxRoll,buffer,10)); return maxRoll; }