Hi, I have a question concerning drawing gdi's on a window: Lets say i drew an arc on a window and gave it an arrow head at one end, and a dot (larger than the line width) in the center of the arc. While having only the integer co-ordinate parameters of the arc, head, and dot stored in a structured, how would i make the dot or arrow head create a window message when the mouse clicks on either? For example: I want to move the head to a new location, so i would click on the head and drag it to a new point on the window?? Im only looking for the code to set an event in motion, so basically, im looking for hints, tips, etc. that would help me create 2 regions on the window that would send specific windows messages when clicked on. As always, thanx in advanced, NaN
Posted on 2001-03-15 02:00:00 by NaN
You can process the standard mouse messages like WM_LBUTTONDOWN, then compare it's position parameters (xPos, yPos) with the coordinates of the arrowhead. Like:

...WM_LBUTTONDOWN handler.....
mov eax, lParam
mov ecx, eax
shr ecx, 16     ;yPos
and eax, 0ffffh ;xPos
.IF (eax>=ArrowHead.leftpos) && (eax<=ArrowHead.rightpos) && \
    (ecx>=ArrowHead.toppos) && (ecx<=ArrowHead.bottompos)
    ; user clicked on the arrowhead
    ; do something with it and set the new coordinates
.ENDIF   
........
If your clickable region is defined in a RECT structure, you can use PtInRect to find out if a point given by a POINT structure is in the specified region given by a RECT structure. Also notice that some functions use screen coordinates instead of client coordinates, this can be very confusing. Use ScreenToClient/ClientToScreen to convert coordinates between them. Thomas
Posted on 2001-03-15 06:42:00 by Thomas
If you can use a region for your shape, check out PtInRegion. I've never worked with regions myself, so I don't know if this is of any use to you.
Posted on 2001-03-15 08:34:00 by f0dder
I suppose you could use some kind of "fake screen" with the same width & height as your window area, where you draw the curve in one colour. Use a different "colour" per object, then when the user clicks on the screen, test using the same coordinates on your fake screen, get the "colour" of that "fake" pixel and that'll give you your object. If you've only got 2^8 objects then you only 8bpp colour depth etc. Yes I know it is wasteful on memory, but it is simple (like me :) ) Mirno
Posted on 2001-03-15 08:50:00 by Mirno
Thanx all, I went with Thomas' suggestion, I didnt realize it was so simple, i was thinking is would need to define regions or something to that effect.. I have it working as i would like it now. And im using InvalidateRect on WM_MOUSEMOVE events to dynamically show the arrow moving as you move the mouse. My last question to this is: Is there a better way of re-drawing, where the toolbar and window wont flicker from so many InvalidateRect events? Thanx again, NaN
Posted on 2001-03-15 09:32:00 by NaN
Have you tried using a backbuffer? The WM_PAINT handler of your window should only bitblt a backbuffer DC onto the window. All the painting should be done on the backbuffer and when finished, do a InvalidateRect on the window to make the window procedure paint the backbuffer on the window. If that doesn't stop the flickering, try to only invalidate the part of the window that really needs to be redrawn by specifying the lpRect parameter of InvalidateRect. An alternative is to create an owner-drawn static control with the drawing, and then only update the control, not the entire window. Thomas
Posted on 2001-03-15 11:03:00 by Thomas
i'm not sure if this is what you're looking for, but i'll send you the source.
Posted on 2001-03-15 12:41:00 by [SaFc0n]
Thank you again, You've all been a great resource on the issue! I personally have been avoiding the gdi till now, because i didnt think i would need it (i do mainly engineering work). But irony has a funny way of showing up, and my Prof. asked me to devise a program to visually solve race free state assignments (in Digital Electronics). So i need to draw 'states' in little circles, and have arrows jumping in and out of each with specific colors, that can be moved around and adjusted.. Should have something working by the end of this evening. :) If any of you are interested i will post the source when done. NaN
Posted on 2001-03-15 18:57:00 by NaN