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

📄 朱瑞菜单操作.cpp

📁 能够实现菜单的基本操作
💻 CPP
📖 第 1 页 / 共 3 页
字号:
				MoveToEx(hDC,Bi.begin.x,Bi.begin.y,NULL);
				ScreenToClient(hWnd,&Bi.end);
				LineTo(hDC,Bi.end.x,Bi.end.y);
				ReleaseDC(hWnd,hDC);
				break;
               //---------- ------------------------------实心矩形------------------------------------------------------------------------//
			case 2:
				hDC=GetDC(hWnd);
				GetCursorPos(&Bi.end);		
				hPen=CreatePen(Bi.penstyle,Bi.width,Bi.color);
				hBrush=CreateSolidBrush(Brushcolor);
				MoveToEx(hDC,Bi.begin.x,Bi.begin.y,NULL);//设置画刷
				SelectObject(hDC,hPen);
				SelectObject(hDC,hBrush);
				ScreenToClient(hWnd,&Bi.end);
				if(wParam&MK_CONTROL)   //按下ctrl画正方形
				{
					Rectangle(hDC,Bi.begin.x,Bi.begin.y,Bi.end.x,Bi.begin.y+Bi.end.x-Bi.begin.x);
				}
				else
				{
					Rectangle(hDC,Bi.begin.x,Bi.begin.y,Bi.end.x,Bi.end.y);
				}
				ReleaseDC(hWnd,hDC);
				break;
                          //-------- --------------------实心椭圆------------------------------------------------------------------------//
			case 3:
				hDC=GetDC(hWnd);
				GetCursorPos(&Bi.end);		
				hPen=CreatePen(Bi.penstyle,Bi.width,Bi.color);
				hBrush=CreateSolidBrush(Brushcolor);	//设置画刷
				SelectObject(hDC,hPen);
				SelectObject(hDC,hBrush);
				ScreenToClient(hWnd,&Bi.end);
				if(wParam&MK_CONTROL)   //按下ctrl画圆
				{
					Ellipse(hDC,Bi.begin.x,Bi.begin.y,Bi.end.x,Bi.begin.y+Bi.end.x-Bi.begin.x);
				}
				else
				{
					Ellipse(hDC,Bi.begin.x,Bi.begin.y,Bi.end.x,Bi.end.y);
				}
				ReleaseDC(hWnd,hDC);
				break;
                         //-----------------------橡皮擦----------------------------------------------------------------------//
			case 4:
				hDC=GetDC(hWnd);
				GetCursorPos(&Bi.end);
				hPen=CreatePen(Bi.penstyle,Bi.width,RGB(255,255,255));
				hBrush=CreateSolidBrush(RGB(255,255,255));	//设置画刷
				SelectObject(hDC,hPen);
				SelectObject(hDC,hBrush);
				Rectangle(hDC,Bi.begin.x,Bi.begin.y,Bi.end.x,Bi.begin.y+Bi.end.x-Bi.begin.x);
				ReleaseDC(hWnd,hDC);
				break;
                        //--------------------- ------------碰碰球------------------------------------------------------------------------//
			case 5:
				hDC=GetDC(hWnd);
				hPen=CreatePen(PS_SOLID,Bi.width,RGB(10,63,57));
				hBrush=CreateSolidBrush(RGB(10,63,57));//设置画刷
				SelectObject(hDC,hPen);
				SelectObject(hDC,hBrush);
				RECT rect;
				GetClientRect(hWnd,&rect);

				yuan2_x=rect.right-50;    yuan2_y=rect.bottom/2;
				yuan1_x=50;yuan1_y=50;				

				Rectangle(hDC,0,0,rect.right,rect.bottom);
				hBrush=CreateSolidBrush(Brushcolor);
				SelectObject(hDC,hBrush);		
				yuan1_y=rect.bottom/2;
				if(loop==1)
				{
					SetBkColor(hDC,Bkcolor);
					SetTextColor(hDC,RGB(255,0,0));
					TextOut(hDC,rect.right/2-250,50,"为了能跳出循环,由于缺少线程知识,循环次数暂设为2次,循环结束即可正常操作",73);
					TextOut(hDC,rect.right/2-200,70,"背景色和球的填充色均可在颜色菜单中设置,设置好后,单击用户区开始",59);
					while(loop<5)
					{
						for(;yuan1_x<rect.right/2-50&&yuan2_x>rect.right/2+50;)
						{
							Ellipse(hDC,yuan1_x-50,yuan1_y-50,yuan1_x+50,yuan1_y+50);
							Ellipse(hDC,yuan2_x-50,yuan2_y-50,yuan2_x+50,yuan2_y+50);
							yuan1_x+=20;
							yuan2_x-=20;
							Sleep(1);
						}
						
						Sleep(100);
						
						for(;yuan1_x>50&&yuan2_x<rect.right-50;)
						{
							Ellipse(hDC,yuan1_x-50,yuan1_y-50,yuan1_x+50,yuan1_y+50);
							Ellipse(hDC,yuan2_x-50,yuan2_y-50,yuan2_x+50,yuan2_y+50);
							yuan1_x-=1;
							yuan2_x+=1;							
						}
						Sleep(500);	
						loop++;
					}
					loop=1;
					flag=0;
					ReleaseDC(hWnd,hDC);
				}
				break;

                          //----------------- -------------45度球------------------------------------------------------------------------//

			case 6:
				yuan1_x=50;  yuan1_y=50; // yuan2_x=0;  yuan2_y=0;
				hDC=GetDC(hWnd);
				GetClientRect(hWnd,&rect);
				hPen=CreatePen(PS_SOLID,Bi.width,Bkcolor);
				hBrush=CreateSolidBrush(Brushcolor);
				SelectObject(hDC,hPen);
				SelectObject(hDC,hBrush);
				while(loop<2)
				{
					SetBkColor(hDC,Bkcolor);
					SetTextColor(hDC,RGB(255,0,0));
					TextOut(hDC,rect.right/2-250,50,"为了能跳出循环,由于缺少线程知识,循环次数暂设为1次,循环结束即可正常操作",73);
					TextOut(hDC,rect.right/2-200,70,"背景色和球的填充色均可在颜色菜单中设置,设置好后,单击用户区开始",59);
					for(;yuan1_y<rect.bottom-50;)
					{
						Ellipse(hDC,yuan1_x-50,yuan1_y-50,yuan1_x+50,yuan1_y+50);
						yuan1_y++;
						yuan1_x++;
						Sleep(3);
					}
					
					for(;yuan1_y>=50;)
					{
						Ellipse(hDC,yuan1_x-50,yuan1_y-50,yuan1_x+50,yuan1_y+50);
						yuan1_y--;
						yuan1_x++;
						Sleep(3);
					}
					for(;yuan1_y<rect.bottom-50;)
					{
						Ellipse(hDC,yuan1_x-50,yuan1_y-50,yuan1_x+50,yuan1_y+50);
						yuan1_y++;
						yuan1_x--;
						Sleep(3);
					}
					for(;yuan1_y>=50;)
					{
						Ellipse(hDC,yuan1_x-50,yuan1_y-50,yuan1_x+50,yuan1_y+50);
						yuan1_y--;
						yuan1_x--;
						Sleep(3);
					}
					loop++;					
					Sleep(3);					
				}
				loop=1;
				flag=0;
				ReleaseDC(hWnd,hDC);
				break;
                               //-------------- --------对角线球------------------------------------------------------------------------//
			case 7:
				yuan1_x=50;  yuan1_y=50;  //yuan2_x=0;  yuan2_y=0;
				hDC=GetDC(hWnd);
				GetClientRect(hWnd,&rect);
				hPen=CreatePen(PS_SOLID,Bi.width,Bkcolor);
				hBrush=CreateSolidBrush(Brushcolor);
				SelectObject(hDC,hPen);
				SelectObject(hDC,hBrush);
				while(loop<3)
				{
					SetBkColor(hDC,Bkcolor);
					SetTextColor(hDC,RGB(255,0,0));
					TextOut(hDC,rect.right/2-250,50,"为了能跳出循环,由于缺少线程知识,循环次数暂设为2次,循环结束即可正常操作",73);
					TextOut(hDC,rect.right/2-200,70,"背景色和球的填充色均可在颜色菜单中设置,设置好后,单击用户区开始",59);
					xielv=(double)rect.bottom/rect.right;
					for(;yuan1_y<rect.bottom-50;)
					{
						yuan1_x+=1;
						yuan1_y=xielv*yuan1_x-25;
						Ellipse(hDC,yuan1_x-50,yuan1_y-50,yuan1_x+50,yuan1_y+50);						
						Sleep(3);
					}
					for(;yuan1_y>50;)
					{
						yuan1_x-=1;
						yuan1_y=xielv*yuan1_x+10;
						Ellipse(hDC,yuan1_x-50,yuan1_y-50,yuan1_x+50,yuan1_y+50);
						//Sleep(3);
					}
					loop++;
				}
				loop=1;
				flag=0;
				ReleaseDC(hWnd,hDC);
				break;	
				//-------------------------------------------空心矩形-------------------------------------------------------------//
			case 8:
				hDC=GetDC(hWnd);
				GetCursorPos(&Bi.end);		
				hPen=CreatePen(Bi.penstyle,Bi.width,Bi.color);
				hBrush=CreateSolidBrush(Bkcolor);
				MoveToEx(hDC,Bi.begin.x,Bi.begin.y,NULL);//设置画刷
				SelectObject(hDC,hPen);
				SelectObject(hDC,hBrush);
				ScreenToClient(hWnd,&Bi.end);
				if(wParam&MK_CONTROL)   //按下ctrl画正方形
				{
					Rectangle(hDC,Bi.begin.x,Bi.begin.y,Bi.end.x,Bi.begin.y+Bi.end.x-Bi.begin.x);
				}
				else
				{
					Rectangle(hDC,Bi.begin.x,Bi.begin.y,Bi.end.x,Bi.end.y);
				}
				ReleaseDC(hWnd,hDC);
				break;
                //-------------------------------------------空心椭圆-----------------------------------------------------------//
			case 9:
				hDC=GetDC(hWnd);
				GetCursorPos(&Bi.end);		
				hPen=CreatePen(Bi.penstyle,Bi.width,Bi.color);
				hBrush=CreateSolidBrush(Bkcolor);	//设置画刷
				SelectObject(hDC,hPen);
				SelectObject(hDC,hBrush);
				ScreenToClient(hWnd,&Bi.end);
				if(wParam&MK_CONTROL)   //按下ctrl画圆
				{
					Ellipse(hDC,Bi.begin.x,Bi.begin.y,Bi.end.x,Bi.begin.y+Bi.end.x-Bi.begin.x);
				}
				else
				{
					Ellipse(hDC,Bi.begin.x,Bi.begin.y,Bi.end.x,Bi.end.y);
				}
				ReleaseDC(hWnd,hDC);
				break;
               //-------------------------------------------------------最长路径----------------------------------------------------//
			case 10:
				int i=0,j=0;
				POINT pt;
				hDC=GetDC(hWnd);
				hPen=CreatePen(PS_SOLID,Bi.width,RGB(0,0,0));
				hBrush=CreateSolidBrush(RGB(0,0,255));//设置画刷
				SelectObject(hDC,hPen);
				SelectObject(hDC,hBrush);
				GetClientRect(hWnd,&rect);
				int x_unit=rect.right/16;
				int y_unit=rect.bottom/16;
				for(i=1;i<=16;i++)
				{
					for(j=1;j<=16;j++)
						if((i+j)%2==0)
						{
							hPen=CreatePen(PS_SOLID,2,RGB(0,255,0));
							SelectObject(hDC,hPen);
							hBrush=CreateSolidBrush(RGB(0,0,0));
							SelectObject(hDC,hBrush);
							Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
						}
						else
						{
							hPen=CreatePen(PS_SOLID,2,RGB(0,255,0));
							SelectObject(hDC,hPen);
							hBrush=CreateSolidBrush(RGB(255,0,0));
							SelectObject(hDC,hBrush);
						Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
						}
				}
				GetCursorPos(&pt);
				ScreenToClient(hWnd,&pt);
				i=pt.x/x_unit+1;
				j=pt.y/y_unit+1;
				int x_start=i,y_start=j;
				if(i==1&&j==16)
				{
					MessageBox(hWnd,"此点为终点不能作为始发点!!","提示",MB_OK);
					break;
				}


				if((i>=1)&&(i<16)&&(j>1)&&(j<16))
				{
					if((i+j)%2==1&&(i%2==1))            //起点为红色,顶点为黑色;
					{
						for(;j>=1;)
						{
							hPen=CreatePen(PS_SOLID,2,RGB(255,0,255));
							SelectObject(hDC,hPen);
							hBrush=CreateSolidBrush(RGB(255,255,255));
							SelectObject(hDC,hBrush);
							Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
							Sleep(150);
							j=j-1;
						}
						i=i+1;
						for(;i<=16;i++)
						{
							if(i%2==1)
							{
								for(;j>=1;)
								{
									Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
									j=j-1;
									Sleep(150);
								}
								--j;
							}
							if(i%2==0)
							{
								for(;j<=y_start+1;)
								{
									Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
									j=j+1;
									Sleep(150);
								}
								--j;
							}
						}


						j=j+1;
						i=i-1;
						for(;j<=16;++j)
						{
							if(j%2==1)
							{
								for(;i<=16;)
								{
									Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
									i=i+1;
									Sleep(150);
								}
								--i;
							}
							if(j%2==0)
							{
								for(;i>=x_start;)
								{
									Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
									i=i-1;
									Sleep(150);
								}
								++i;
							}
						}



						j=j-1;
						i=i-1;
						for(;i>=1;--i)
						{
							if(i%2==0)
							{
								for(;j>=1;)
								{
									Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
									j=j-1;
									Sleep(150);
								}
								++j;
							}
							if(i%2==1)
							{
								for(;j<=16;)
								{
									Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
									j=j+1;
									Sleep(150);
								}
								--j;
							}
						}
						MessageBox(hWnd,"完成!","提示",MB_OK);
						flag=0;
						break;
					}
					//--------------------------------------------------------黑黑---------------------------------------------//


					if((i+j)%2==0&&(i%2==1))
					{
						for(;j>=1;)
						{
							hPen=CreatePen(PS_SOLID,2,RGB(255,0,255));
							SelectObject(hDC,hPen);
							hBrush=CreateSolidBrush(RGB(255,255,255));
							SelectObject(hDC,hBrush);
							Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
							j=j-1;
							Sleep(150);
						}
						i=i+1;
						for(;i<=16;++i)
						{
							if(i%2==0)
							{
								for(;j<=y_start;)
								{
									Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
									j=j+1;
									Sleep(150);
								}
								--j;
							}
							if(i%2==1)
							{
								for(;j>=1;)
								{
									Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
									j=j-1;
									Sleep(150);
								}
								++j;
							}
						}


						++j;
						--i;
						for(;j<=16;++j)
						{
							if(j%2==0)
							{
								for(;i>=x_start;)
								{
									Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
									i=i-1;
									Sleep(150);
								}
								++i;
							}
							if(j%2==1)
							{
								for(;i<=16;)
								{
									Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
									i=i+1;
									Sleep(150);
								}
								--i;
							}
						}

						--j;
						--i;
						for(;i>=1;--i)
						{
							if(i%2==0)
							{
								for(;j>=1;)
								{
									Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
									j=j-1;
									Sleep(150);
								}
								++j;
							}
							if(i%2==1)
							{
								for(;j<=16;)
								{
									Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
									j=j+1;
									Sleep(150);
								}
								--j;
							}
						}
						MessageBox(hWnd,"完成!","提示",MB_OK);
						flag=0;
						break;
					}

                                            //------------------------红红-----------------------------------//
					if((i+j)%2==1&&(i%2==0))
					{
						for(;j>=2;)
						{
							hPen=CreatePen(PS_SOLID,2,RGB(255,0,255));
							SelectObject(hDC,hPen);
							hBrush=CreateSolidBrush(RGB(255,255,255));
							SelectObject(hDC,hBrush);
							Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
							j=j-1;
							Sleep(150);
						}
						i=i+1;
						++j;
						if(i<=15)
						{
							
							for(;i<=15;++i)
							{
								if(i%2==1)
								{
									for(;j<=y_start+1;)
									{
										Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
										j=j+1;
										Sleep(150);
									}
									--j;
								}
								if(i%2==0)
								{
									for(;j>=2;)
									{
										Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
										j=j-1;
										Sleep(150);
									}
									++j;
								}
							}
							for(;j<=15;++j)
							{
								if(j%2==1)
								{
									for(;i>=x_start;)
									{
										Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
										i=i-1;
										Sleep(150);
									}
									++i;
								}
								if(j%2==0)
								{
									for(;i<=15;)
									{
										Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
										i=i+1;
										Sleep(150);
									}
									--i;
								}
							}
							for(;i>=2;--i)
							{
								if(i%2==1)
								{
									for(;j>=2;)
									{
										Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
										j=j-1;
										Sleep(150);
									}
									++j;
								}
								if(i%2==0)
								{
									for(;j<=15;)
									{
										Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
										j=j+1;
										Sleep(150);
									}
									--j;
								}
							}
							++j;
							++i;
							for(;i<=16;)
							{
								Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
								i=i+1;
								Sleep(150);
							}
							--i;
							for(;j>=1;)
							{
								Rectangle(hDC,(i-1)*x_unit,(j-1)*y_unit,i*x_unit,j*y_unit);
								j=j-1;
								Sleep(150);
							}
							++j;
							for(;i>=1;)

⌨️ 快捷键说明

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