Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
that's about what I did, but I didn't finish it until the end, it
should be like on a gif

ill — ImgBB[example]

I need to make the circles appear one after the other and there is no one
in the current program, the circle just moves in a circle

What I have tried:

<pre>// кругиView.cpp: реализация класса CкругиView
//
 
#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS можно определить в обработчиках фильтров просмотра реализации проекта ATL, эскизов
// и поиска; позволяет совместно использовать код документа в данным проекте.
#ifndef SHARED_HANDLERS
#include "круги.h"
#endif
#define _USE_MATH_DEFINES
 
#include "кругиDoc.h"
#include "кругиView.h"
#include <math.h>
 
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
 
int centerX = 300;
int centerY = 175;
int radius = 100;
int numberOfPoints = 12;
double theta = 360 / numberOfPoints;
double angle;
 
 
 
// CкругиView
 
IMPLEMENT_DYNCREATE(CкругиView, CView)
 
BEGIN_MESSAGE_MAP(CкругиView, CView)
    // Стандартные команды печати
    ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CкругиView::OnFilePrintPreview)
    ON_WM_CONTEXTMENU()
    ON_WM_RBUTTONUP()
END_MESSAGE_MAP()
 
// Создание или уничтожение CкругиView
 
CкругиView::CкругиView() noexcept
{
    // TODO: добавьте код создания
 
}
 
CкругиView::~CкругиView()
{
}
 
BOOL CкругиView::PreCreateWindow(CREATESTRUCT& cs)
{
    // TODO: изменить класс Window или стили посредством изменения
    //  CREATESTRUCT cs
 
    return CView::PreCreateWindow(cs);
}
 
void drawPoint(HDC hdc, int currentPoint, int totalPoints)
{
    theta = ((M_PI * 2) / totalPoints);
    angle = (theta * currentPoint);
 
    electron.pivot.x = (radius * cos(angle));
    electron.pivot.y = (radius * sin(angle));
 
    return electron;
}
 
void cycle(HDC hdc)
{
    for (int i = 1; i <= totalPoints; i++)
    {
        drawPoint(100, i, totalPoints);
    }
}
 
// Рисование CкругиView
 
void CкругиView::OnDraw(CDC* pDC)
{
    CкругиDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;
 
    // TODO: добавьте здесь код отрисовки для собственных данных
 
    //================================== создание большого круга, чтобы по нему разместить маленькие 
    //CGdiObject* two = new CBrush(RGB(255, 255, 255)); 
    //pDC->SelectObject(two);
    //pDC->Ellipse(CRect(25, 5, 555, 535)); 
}
 
// Печать CкругиView
 
 
void CкругиView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
    AFXPrintPreview(this);
#endif
}
 
BOOL CкругиView::OnPreparePrinting(CPrintInfo* pInfo)
{
    // подготовка по умолчанию
    return DoPreparePrinting(pInfo);
}
 
void CкругиView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: добавьте дополнительную инициализацию перед печатью
}
 
void CкругиView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: добавьте очистку после печати
}
 
void CкругиView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
    ClientToScreen(&point);
    OnContextMenu(this, point);
}
 
void CкругиView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
    theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}
 
 
// Диагностика CкругиView
 
#ifdef _DEBUG
void CкругиView::AssertValid() const
{
    CView::AssertValid();
}
 
void CкругиView::Dump(CDumpContext& dc) const
{
    CView::Dump(dc);
}
 
CкругиDoc* CкругиView::GetDocument() const // встроена неотлаженная версия
{
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CкругиDoc)));
    return (CкругиDoc*)m_pDocument;
}
#endif //_DEBUG
 
 
// Обработчики сообщений CкругиView
Posted
Updated 2-Nov-21 16:30pm
v6
Comments
OriginalGriff 31-Oct-21 10:54am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
[no name] 31-Oct-21 13:12pm    
What / where is "electron" defined? And why is drawPoint() declared as returning void while it is returning "electron"?
merano99 31-Oct-21 21:41pm    
The functions drawPoint() and cycle() are not used, variable totalPoints not defined.
Call of drawPoint(100, i, totalPoints) does not match declaration.

Better to use cmath instead of math.h.

#define _USE_MATH_DEFINES
#include <cmath>

A timer is probably needed that calls OnDraw regularly by callin e.g. InvalidateRect().

"one after another" sounds like an animation. Than you must draw all objects in some timelimed operation.
Sounds like some enum which will triggered by a timer.

Step 0 is clearing the screen and drawing the background.

Addition: Read this drawing tutorial for MFC. Maybe you only asked for CDC:Ellipse which also is drawing circles.

Please you english in your code. Even I learned russish some 40 years ago it isnt fluid like my native german tongue ;-)
 
Share this answer
 
v2
Comments
merano99 1-Nov-21 8:32am    
The Russian texts are comments generated by the Russian IDE. For me, German is usually also used in these places.
Since I don't speak Russian, I have replaced the names and supplemented the existing functions so that a graphic is displayed at the calculated positions.

-- snip CDrawStarView.cpp --
C++
point calcPoint(int currentPoint, int totalPoints)
{
	double theta = ((M_PI * 2) / totalPoints);
	double angle = (theta * currentPoint);
	const int radius = 100;
	point rt;
	rt.x = cos(angle);
	rt.y = sin(angle);
	return rt;
}

// CDrawStarView drawing
// The usual and recommended way in MFC handle all drawing in onDraw() only
void CDrawStarView::OnDraw(CDC* pDC)
{
	CDrawStarDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// determine size, if necessary
	// BITMAP bm;
	// m_bitmap_star.GetBitmap(&bm);

	point pt;
	for (int i = 0; i < 12; i++) {
		pt = calcPoint(i, 12);
		m_bitmap_star.Draw(pDC, (int)(pt.x*m_r + m_ofs), (int)(pt.y*m_r + m_ofs));
	}
}
-- /snip --

-- snip CDrawStarView.h --
C++
#pragma once

#define _USE_MATH_DEFINES
#include <cmath>
#include <vector>
#include "MyBitmap.h"

typedef struct { double x, y; } point;

class CDrawStarView : public CView
{
protected: // create from serialization only
	CDrawStarView();
	DECLARE_DYNCREATE(CDrawStarView)
public:
	virtual ~CDrawStarView();
	CDrawStarDoc* GetDocument() const;
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view

protected:
	CMyBitmap m_bitmap_star;     // handle bitmap
	int m_r = 100, m_ofs = 120;  // define size

// Generated message map functions
protected:
	DECLARE_MESSAGE_MAP()
public:
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnSize(UINT nType, int cx, int cy);
};

In order to achieve the running effect, a timer can be built in, which selects a point at regular points in time, which is left out when drawing and causes everything to be redrawn.

Since the CBitmap class unfortunately does not contain a drawing function, the class has been extended by a function with the usual code.
C++
// CMyBitmap class
class CMyBitmap : public CBitmap
{
public:
	CMyBitmap();
	virtual ~CMyBitmap();
	void Draw(CDC* pDC, int x, int y);
};
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900