MFC课程设计报告彩票自动选号系统.doc
MFC编程及应用课程设计报告题目: 彩票自动选号系统 学号: 1004220327 姓名: 李康 指导老师: 杨均匀 时间: 2011年10月7日 评语:1、设计步骤(1) 工程建立建立基于对话框的应用程序(2) 类中新增变量的作用1、 在资源中增加两个对话框,并建立类向导,创建两个类CPage1,CPage2.2、 增加类Cli1004220327在后面静态成员变量关联起来3、 在类CPage1中增加m_num1,m_num2,.m_num35与对话框中的静态文本关联起来,也就是彩票的数字.4、 在对话框中增加五个单选按钮,用来选择投注数,当选择第一注时,变量m_touzhu1=0,选择第二注时m_touzhu1=1,依此类推5、 对话框中的开始按钮,增加关联函数OnStart(),当m_touzhu1=-1时,表示没有投注,用MessageBox弹出对话框提示请投注,当m_touzhu1=0时,即表示投一注,在设置定时器时,只设置7个,当m_touzhu1=1时,定时器设置14个。SetTimer(i,1,NULL);i表示定时器的名字,中间的1表示间隔1ms,NULL表示空,用for循环依次设置定时器6、 增加消息函数,TIMER,设置定时器响应的函数,当m_touzhu1=0时,表示设置了7个定时器,int型i用来随机产生一个很大的整数,语句i = rand()%10用来随机产生一个小于10的整数,也就是我们所看到的彩票,语句str.Format("%i",i);m_num1.SetWindowText(str);是将产生的整数i转换成CString型,后面代码的功能基本是一样的。7、 类CPage1的OnStop()函数的功能是来结束定时器,同样,当m_touzhu1=0时,只产生7个定时器,KillTimer(i)的i是指定时器的名字,用for循环来结束每个定时器。当m_touzhu1=1,2,3,4时,依此类推8、 类CPage1中OnQinglimg()函数的功能是将所有的彩票号码变为0,m_num1.SetWindowText("0");可以实现该功能。9、 类CPage1中OnCtlColor()函数是用来控制彩票号码的顔色,pDC->SetTextColor(RGB(0,0,255);来控制颜色。10、 在类CPage1中增加CFont m_font1;变量,再通过语句m_font1.CreateFont(-24,-20,0,0,100,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_ROMAN,"宋体");来控制字体的大小和形状。11、 在类CPage1中OnAuto()函数是用来自动产生一组彩票,点击一下自动按钮时,彩票自动选号系统开始自动选票,然后再点击一下时,彩票选号系统停止,随机产生一组彩票,这个功能和我开始想的有出入,我开始以为是点击一下就实现自动选号的功能。 if(k=0) OnStart(); k=1; else if(k=1) OnStop(); k=0; 定义一k在中间传递,变换的调用OnStart();和OnStop()函数,实现自动选号的功能。12、类CPage2和CPage1中各个函数的功能基本相同,只是在两个地方有细小不同,i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num36.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num36.SetWindowText("0"+str);用来区分彩票是大于10还是小于10,如果小于10,需在号码前加一个0,另外,产生随机号码时是对36求余,使彩票号码介于0035之间13、类CMy1004220327Dlg中的OnPaint()函数用来给背景, 这个功能是我baidu来的,把背景改成了南京理工大学的喷泉广场。(3)源代码,由于个人能力有限,所用的算法比较简单,但代码很长,CPage1和Cpage2代码差不多,我只复制CPage1的代码。WM_TIMER代码:void CPage2:OnTimer(UINT nIDEvent) CString str ;if(m_touzhu2=0)int i ;switch (nIDEvent)case 1:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num36.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num36.SetWindowText("0"+str);break;case 2:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num37.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num37.SetWindowText("0"+str);break;case 3:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num38.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num38.SetWindowText("0"+str);break;case 4:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num39.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num39.SetWindowText("0"+str);break;case 5:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num40.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num40.SetWindowText("0"+str);break;case 6:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num41.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num41.SetWindowText("0"+str);break;case 7:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num42.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num42.SetWindowText("0"+str);break;else if(m_touzhu2=1)int i ;switch (nIDEvent)case 1:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num36.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num36.SetWindowText("0"+str);break;case 2:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num37.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num37.SetWindowText("0"+str);break;case 3:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num38.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num38.SetWindowText("0"+str);break;case 4:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num39.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num39.SetWindowText("0"+str);break;case 5:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num40.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num40.SetWindowText("0"+str);break;case 6:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num41.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num41.SetWindowText("0"+str);break;case 7:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num42.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num42.SetWindowText("0"+str);break;case 8:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num43.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num43.SetWindowText("0"+str);break;case 9:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num44.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num44.SetWindowText("0"+str);break;case 10:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num45.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num45.SetWindowText("0"+str);break;case 11:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num46.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num46.SetWindowText("0"+str);break;case 12:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num47.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num47.SetWindowText("0"+str);break;case 13:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num48.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num48.SetWindowText("0"+str);break;case 14:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num49.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num49.SetWindowText("0"+str);break;else if(m_touzhu2=2)int i ;switch (nIDEvent)case 1:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num36.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num36.SetWindowText("0"+str);break;case 2:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num37.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num37.SetWindowText("0"+str);break;case 3:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num38.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num38.SetWindowText("0"+str);break;case 4:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num39.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num39.SetWindowText("0"+str);break;case 5:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num40.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num40.SetWindowText("0"+str);break;case 6:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num41.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num41.SetWindowText("0"+str);break;case 7:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num42.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num42.SetWindowText("0"+str);break;case 8:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num43.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num43.SetWindowText("0"+str);break;case 9:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num44.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num44.SetWindowText("0"+str);break;case 10:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num45.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num45.SetWindowText("0"+str);break;case 11:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num46.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num46.SetWindowText("0"+str);break;case 12:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num47.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num47.SetWindowText("0"+str);break;case 13:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num48.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num48.SetWindowText("0"+str);break;case 14:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num49.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num49.SetWindowText("0"+str);break;case 15:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num50.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num50.SetWindowText("0"+str);break;case 16:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num51.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num51.SetWindowText("0"+str);break;case 17:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num52.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num52.SetWindowText("0"+str);break;case 18:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num53.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num53.SetWindowText("0"+str);break;case 19:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num54.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num54.SetWindowText("0"+str);break;case 20:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num55.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num55.SetWindowText("0"+str);break;case 21:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num56.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num56.SetWindowText("0"+str);break;else if(m_touzhu2=3)int i ;switch (nIDEvent)case 1:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num36.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num36.SetWindowText("0"+str);break;case 2:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num37.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num37.SetWindowText("0"+str);break;case 3:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num38.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num38.SetWindowText("0"+str);break;case 4:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num39.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num39.SetWindowText("0"+str);break;case 5:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num40.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num40.SetWindowText("0"+str);break;case 6:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num41.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num41.SetWindowText("0"+str);break;case 7:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num42.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num42.SetWindowText("0"+str);break;case 8:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num43.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num43.SetWindowText("0"+str);break;case 9:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num44.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num44.SetWindowText("0"+str);break;case 10:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num45.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num45.SetWindowText("0"+str);break;case 11:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num46.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num46.SetWindowText("0"+str);break;case 12:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num47.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num47.SetWindowText("0"+str);break;case 13:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num48.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num48.SetWindowText("0"+str);break;case 14:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num49.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num49.SetWindowText("0"+str);break;case 15:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num50.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num50.SetWindowText("0"+str);break;case 16:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num51.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num51.SetWindowText("0"+str);break;case 17:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num52.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num52.SetWindowText("0"+str);break;case 18:i = rand()%36;if (i>9&&i<36)str.Format("%i",i);m_num53.SetWindowText(str);else if(i<10)str.Format("%i",i);m_num53.SetWindowText("0"+str);break;case 19:i = r