[C] drawing: drag GDI shapes
we are beginners.
doubt: we would like to know what is the most convenient method to select and drag a shape drawn with Windows GDI (rectangles, ellipses, polygons...) inside a window or dialog box. for example, if we have drawn several ellipses (Ellipse() function) in a window's client area, we should be able to click one of the ellipses and drag it without affecting the other ellipses.
we have thought of a (na´ve) solution, but we don't know if it is correct, and it seems a little complicated to implement:
to have a (dynamic?) array of structs in which every struct has all the informations necessary to draw one polygon (type, position, color, whether it's selected or not etc.). when the user clicks the window, the program loops through the array of structs until it finds a struct where the cursor's position is inside a shape's limits. if it does, it selects it. when the user drags the cursor, the position information in the struct of the selected shape is continually changed according to the cursor's position (maybe inside WM_MOUSEMOVE). then we should program WM_PAINT to draw each shape from the array of structs and redraw the window each time positions change.
thus, the act of clicking and moving changes information inside an array of structs which is used by WM_PAINT to draw shapes on the window. thus, the user is able to add more objects to the screen by adding more structs to the array.
what do you think? is there a better way?
thank you in advance.