コード例 #1
0
ファイル: graphics.cpp プロジェクト: sngvahmed/Graphics
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;
	Draw Ahmed;
	switch (message)
	{
		case WM_LBUTTONDOWN: 
			if(!isSecond) 
				X1 = LOWORD(lParam), Y1 = HIWORD(lParam) , isSecond = true;
			else 
				X2 = LOWORD(lParam) , Y2 = HIWORD(lParam) , InvalidateRect(hWnd, NULL, false);
		break;
		case WM_COMMAND:
			wmId = LOWORD(wParam) , wmEvent = HIWORD(wParam);
			// Parse the menu selections:
			switch (wmId){
				case IDM_S:
					ss.open("input.in") , tmp.clear() , tmp = var;
					while(var.size())
						ss << var.front().x1 << " " << var.front().y1 << " " << var.front().x2 << " " << 
							var.front().y2 << " " << var.front().P <<"\n" , var.pop_front();
					var = tmp , ss.close();
				break;
				case IDM_O:
					clr() , OT = true;
					InvalidateRect(hWnd, NULL, true); // draw only a line on the screen
				break;
				case IDM_DDA_LINE:
					clr() , BDDA = 1;
				break;
				case IDM_MP_LINE:
					clr() , BMP = true;
				break;
					case IDM_MP_CIRCULE:
					clr() , MPC = true;
				break;
				case IDM_CIRC_CART:
					clr() , cartizen = true;
				break;
				case IDM_RES:
					RES = true;
					isSecond  = false;
					InvalidateRect(hWnd, NULL, true); // draw only a line on the screen
				break;
				case IDM_R:
					clr() ,  R = true , InvalidateRect(hWnd , 0 , false);
				break;
				case IDM_U:
					clr() ,  U = true , InvalidateRect(hWnd , 0 , false);
				break;
				case IDM_COL:
					memset(&color,0,sizeof(color));
					color.lStructSize=sizeof(CHOOSECOLOR);
					color.hwndOwner=hWnd;
					color.lpCustColors=ccref;
					color.rgbResult=selcolor;
					color.Flags=CC_RGBINIT;
					if(ChooseColor(&color))
						selcolor=color.rgbResult;
					isSecond = false;
				break;
				case IDM_ABOUT:
					DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
					break;
				case IDM_EXIT:
					DestroyWindow(hWnd);
					break;
				default:
					return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
			case WM_PAINT:
				hdc = BeginPaint(hWnd, &ps);
				Ahmed.ps = ps ;
				if(OT == true){
					ss.open("input.in");
					PT tmst;
					while(!ss.eof()){
						ss >> tmst.x1 >> tmst.y1 >> tmst.x2 >> tmst.y2 >> tmst.P;			
						if (tmst.P == 'D')
							Ahmed.DDA(tmst.x1 , tmst.y1 , tmst.x2 , tmst.y2 , selcolor);
						if (tmst.P == 'M')
							Ahmed.MidPoint(tmst.x1 , tmst.y1 , tmst.x2 , tmst.y2 , selcolor);
						if (tmst.P == 'C')
							Ahmed.drawCircle(tmst.x1 , tmst.y1 , Ahmed.Distance(tmst.x1 , tmst.y1 , tmst.x2 , tmst.y2), selcolor);
						if(tmst.P == 'Z')
							Ahmed.MIDPOINT_CARTISIEAN(tmst.x1, tmst.y1 , Ahmed.Distance(tmst.x1 , tmst.y1 , tmst.x2 , tmst.y2), selcolor);
					}
					ss.close();
					clr() , BDDA = true , X1 = X2 = Y1 = Y2 = 0;
					EndPaint(hWnd, &ps);
					break;
				}
				if(U == true){
					if(var.size() != 0){
						PT t = var.back();
						var.pop_back() , var.push_front(t) ;
						if (t.P == 'D')
							Ahmed.DDA(t.x1 , t.y1 , t.x2 , t.y2 , RGB(250,250,250));
						if (t.P == 'M')
							Ahmed.MidPoint(t.x1 , t.y1 , t.x2 , t.y2 , RGB(250,250,250)); 
						if (t.P == 'C')
							Ahmed.drawCircle(t.x1 , t.y1 , Ahmed.Distance(t.x1,t.y1,t.x2,t.y2), RGB(250,250,250));
						if(t.P == 'Z')
							Ahmed.MIDPOINT_CARTISIEAN(t.x1, t.y1 , Ahmed.Distance(t.x1 , t.y1 , t.x2 , t.y2), RGB(250,250,250));
					}
					clr() , BDDA = true , X1 = X2 = Y1 = Y2 = 0;
					EndPaint(hWnd, &ps);
					break;
				} 
				if(R == true){
					if(var.size() != 0){
						PT t = var.front();
						var.pop_front() , var.push_back(t);
						if (t.P == 'D')
							Ahmed.DDA(t.x1 , t.y1 , t.x2 , t.y2 , selcolor);
						if (t.P == 'M')
							Ahmed.MidPoint(t.x1 , t.y1 , t.x2 , t.y2 , selcolor);
						if (t.P == 'C')
							Ahmed.drawCircle(t.x1 , t.y1 , Ahmed.Distance(t.x1 , t.y1 , t.x2 , t.y2), selcolor);
						if(t.P == 'Z')
							Ahmed.MIDPOINT_CARTISIEAN(t.x1, t.y1 , Ahmed.Distance(t.x1 , t.y1 , t.x2 , t.y2), selcolor);
					}
					clr() , BDDA = true , X1 = X2 = Y1 = Y2 = 0;
					EndPaint(hWnd, &ps);
					break;
				}
				if(MPC == true)
					Ahmed.drawCircle(X1 , Y1 , Ahmed.Distance(X1,Y1,X2,Y2), selcolor) , var.push_back(PT(X1,Y1,X2,Y2,'C'));
				if(BDDA == true)
					Ahmed.DDA(X1 , Y1 , X2 , Y2 , selcolor) ,var.push_back(PT(X1,Y1,X2,Y2,'D'));
				if (BMP == true)
					Ahmed.MidPoint(X1 , Y1 , X2 , Y2 , selcolor) ,var.push_back(PT(X1,Y1,X2,Y2,'M'));
				if(cartizen == true)
					Ahmed.MIDPOINT_CARTISIEAN(X1,Y1 , Ahmed.Distance(X1,Y1,X2,Y2) , selcolor) , var.push_back(PT(X1,Y1,X2,Y2,'Z'));
				EndPaint(hWnd, &ps) , isSecond = false;
				break;
			case WM_DESTROY:
				PostQuitMessage(0);
			break;
			default:
				return DefWindowProc(hWnd, message, wParam, lParam);
	}