Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All:
i am new, i just start to learn draw shape with vs2012 c++ and Gdiplus about 5 weeks, i create a simple project to test, but when i draw polygon finish, i cannot delete any polygon which i selected from canvas, it not so easy like to delete a rectangle or a ellipse, only delete the parameter in CArray, but the canvas still can find the "polygon", like my project result show...

i put my project here :
https://drive.google.com/file/d/1LrQY0tQ7RqqXDiRjonASU5QXMRh3X2t0/view?usp=sharing

it can be work, i need someone to help me or teach me the "key point".

Q1 : how do i to identify the background memory area, or show memory area when i use double buffer to draw shape, i use bitblt , it not very good to show the draw result?

Q2 : how do i to use "Object Oriented Programming" idea, to rewrite my test code and let it become more easy to read or easy to add any new item, for example : read some books or some information !

Q3 : i am interest in code programming, what basic books or knowledge i need to know, if i wish to become a good "coder".

or if you have any idea, it is ok~~~

how to use my project :
1. open the project, and start to run.
2. select draw mode or delete mode.
3. when user select draw rectangle : use mouse left button and keep it down, start to draw, and it can resize.
4. when select draw polygon : use mouse left button and move mouse, start to draw, and user select next point you want, it will auto connect the last point to the new point, if you want to close, please use mouse right button and click once.
5. when user select delete : use mouse select any shape you draw, and click the shape topleft or bottomright, messagebox will show, if you select "ok", the shape will redraw by pen notxorpen mode.

What I have tried:

i try to find so much title or answer from book and web side, but those are not very clear i thought, i try to write code to test and find how it get answer or what happen when i go different way to test the gdiplus, i do not very understand how the code to programming, like : double buffer to draw shape, use the "Object Oriented Programming" to create a new full project, or how to become more easy to read or test other people's thought. i know it not a short time to get the right way, i just want to get more basic knowledge to study.
Posted
Updated 23-May-19 5:23am

1 solution

You should do all your painting/drawing to the screen in the function that handles the WM_PAINT message. Each time this function is called it should redraw all the shapes. When a shape is deleted you just remove it from the list of items to draw, and then call InvalidateRect to force a repaint of the client window.
 
Share this answer
 
Comments
Member 14430889 29-May-19 23:18pm    
Thanks for your suggestion, Sir. I try to use CArray to record each point and parameter from polygon which i draw. But it is not the good way, and not convenient about oop idea. And second way : I create a new memory buffer to redraw. It only can undo the step for last shape. There still have a lot of bug after i draw and not easy to know how to get solution or improve my code. Could you kindly to give me some "key word" to search reference or a sample code. The thought not need very precise. But it will be very helpful for me now. Thanks again~
Richard MacCutchan 30-May-19 3:31am    
Using a CArray to hold a set of points is a reasonable choice. You could also use one of the STL containers like std::vector. The final choice is yours of course. As to the actual painting, each shape should paint itself. Take a look at some of the links at shape class paint c - Google Search[^].

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