Hi

I have a prog whith a frame window (red color) and a child window (black color) much bigger than the frame window. The screen is marked with blue color. Now I draw a line on the child window with mouseclicking. The mouseclicking gives the startpoint and endpoint in screen coordinates. I convert the coordinates to client window coordinates and I have the green line. These APIs are used: GetDCOrgEx, MoveToEx and LineTo.

Moving the child window also moves the line keeping the correct startpoint and endpoint.

My problem is when the child window rectangle is changed (zooming). I have tryed different ways. I guess the endpoint of the line must be calculated in proportion of the new rectangle width/height to the old one. I have tryed MUL, DIV, FDIV and FMUL but can't handle these in a correct way like remainders etc. Or can it be done by APIs

I would appreciate if somebody could tell me how to do it in a correct way, i.e. in principle.

Regards
Posted on 2003-05-06 03:07:58 by minor28
It's difficult to visualize what you're trying to do from your description.

The child window seems to be larger than the screen size; is this for quick panning of something like a large 2D game board?

Is your "red frame window" another child window of the main program where you can view a section of the black child window? Or is it THE main window?

What controls your "zooming" in (or out) and its purpose? Is this for 3D animation?

Do you draw directly on the screen (your main window's DC) or in a separate compatible DC?

I guess I haven't answered too much of your question yet!:rolleyes:

Raymond

BTW If you are processing the WM_LBUTTONUP message to get mouse clicking coordinates, returned values are not in screen coordinates but in client area coordinates.
Posted on 2003-05-06 08:53:26 by Raymond
Coordinate Space and Transformation Functions
http://msdn.microsoft.com/library/en-us/gdi/cordspac_0u43.asp
Posted on 2003-05-06 11:18:07 by Brad
Hi Raymond and Brad

I will try to answer your questions.

The child window is larger than the screen size; this is for quick panning of a large 2D map.

The "red frame window" is the main program client area. It could be maximized but will never show the whole map.

I control the zooming with the mouse wheel and the purpose is to change the map scale.

I draw the line directly on the screen on the map by a mouse click. The line is drawn between the mouse pointer position and a given point on the map given by a GPS.

This is how it works so far.

A mousehook process sends a hitpoint message in screen coordinates on a WM_LBUTTONUP.
.elseif eax==WM_MOUSEHOOKPOINT

mov eax,wParam
mov pointIN.x,eax
mov eax,lParam
mov pointIN.y,eax

The same mousehook process also sends a handle message. If it is the correct window the screen coordinates are transformed and the line is drawn.
.elseif eax==WM_MOUSEHOOKWND

mov eax,wParam
.if hMap==eax
.if flPointCourseBTN==TRUE ;a pushbutton is pushed
invoke GetWindowDC,hMap
.if eax!=0
mov hDC,eax
invoke GetDCOrgEx,hDC,addr pointOUT
.if eax==TRUE
invoke MoveToEx,hDC,pointPOS.x,pointPOS.y,NULL
.if eax==TRUE
mov eax,pointIN.x
sub eax,pointOUT.x
mov pointTO.x,eax
mov ecx,pointIN.y
sub ecx,pointOUT.y
mov pointTO.y,ecx
invoke LineTo,hDC,pointTO.x,pointTO.y
.endif
.endif
.endif
mov flPointCourseBTN,FALSE
.endif
.endif

This code retrieves the given position on the map and redraws the line when the map is panned or redrawn.
.if eax==hMap

.if flPointCourseBTN==TRUE
mov ecx,[esp+(1*4)]
mov pointPOS.x,ecx
mov ecx,[esp+(2*4)]
mov pointPOS.y,ecx
.else
invoke MoveToEx,hDC,pointPOS.x,pointPOS.y,NULL
invoke LineTo,hDC,pointTO.x,pointTO.y
.endif
.endif

So far all works well. The problem is when the map is zoomed i.e. the map window rectangle is changed. As the code now is made the line disappears but returns when the Window rectangle resume its size when the line was drawn.

I have also succeded to hold the line but then it is fixed to the screen or client area. What I want is to have it fixed to the points on the map regardless of the map scale.

Brad. I will look closer at the functions in your link. Thanks.

Regards
Posted on 2003-05-06 15:35:42 by minor28
I can't figure out yet what you mean by zooming. For example, if you increase the window size by a factor of 2, do you have to increase the line lenght by a factor of 2 and enlarge the current selection of your 2D map to fit into the enlarged window without showing any additional detail of the 2D map?

Also, if you draw a line, can you draw a second line also? And if yes, do you have to erase the first line? Must the line(s) remain on the 2D map?

In my opinion, regardless of the answers to the above, you should consider drawing to a compatible DC the size of the screen. Then, when you want to draw a line (or resize the window), you copy the required rectangle from the 2D map, draw the line (or lines) and transfer the required rectangle from that compatible DC to the screen at the appropriate location.

A lot of maths involved, specially if you're really "zooming" into the 2D map.

Raymond
Posted on 2003-05-06 22:19:49 by Raymond
Hi Raymond

Zoom like "Zoom in" or "Zoom out" are expressions used in several applications such as MSPaint, MSWord and so on. You are right there are no additional details showing up when zooming in, but the fact that details beeing more readable. You are also right if the window size increases by a factor of 2 the line increases as well by a factor depending on if the factor is related to area or length and width.

I can draw a second line but then the first line disappear. There is only one line at the time on the map.

As for the compatible DC, I don't quite understand what you mean.

Well I concentrated on as you said "A lot of maths involved, specially if you're really "zooming" into the 2D map.". I don't think my zomming is what you call "really zomming" so the maths ought to be fairly simple which it turn out to be. I thank you for our discussion. A discussion always opens ones mind. The code in my previous contribution, the part concerning retrieving the given position on the map and redrawing the line when the map is panned or redrawn, is completed to the following code.
	.if eax==hMap

.if flPointCourseBTN==TRUE
mov ecx,[esp+(1*4)]
mov pointPOS.x,ecx
mov ecx,[esp+(2*4)]
mov pointPOS.y,ecx

invoke GetWindowRect,hMap,addr lpRect
mov eax,lpRect.right
sub eax,lpRect.left
mov X,eax
mov eax,lpRect.bottom
sub eax,lpRect.top
mov Y,eax
.else
invoke GetWindowRect,hMap,addr lpRectZOOM ;Map size after zooming
mov eax,lpRectZOOM.right
sub eax,lpRectZOOM.left
mov Xzoom,eax
mov eax,lpRectZOOM.bottom
sub eax,lpRectZOOM.top
mov Yzoom,eax

fld Xzoom
fdiv X
fmul pointPOS.x
fstp pointZOOM.x
mov eax,pointZOOM.x

fld Yzoom
fdiv Y
fmul pointPOS.y
fstp pointZOOM.y
mov ecx,pointZOOM.y

invoke MoveToEx,hDC,eax,ecx,NULL

fld Xzoom
fdiv X
fmul pointTO.x
fstp pointZOOM.x
mov eax,pointZOOM.x

fld Yzoom
fdiv Y
fmul pointTO.y
fstp pointZOOM.y
mov ecx,pointZOOM.y
invoke LineTo,hDC,eax,ecx
.endif
.endif

I woud appreciate if you could enlighten me on a better solution.

Regards
Posted on 2003-05-07 13:39:47 by minor28
Sorry about the question on zooming but I refered not to "assume" anything about your definition of it.

Your application seems pretty static (i.e. no animation) and, on second thought, a separate compatible DC for the screen does not seem necessary.

You probably had to select your large bitmap into a separate compatible DC anyway, and transfer the rectangles you need from there to the screen's DC, either with the BitBlt function if you need a "straight" copy, or with the StretchBlt function when you need zooming (in or out).

The only small advantage of a separate DC would be for repainting the window (when it got hidden for some reason) or for paning a section of your bitmap which has a line; it may be just as easy to redraw everything on the screen whenever necessary.

Not knowing exactly what you're trying to achieve, you probably have some good reason to "hook" the mouse input for the whole screen instead of processing mouse messages sent to the callback winproc of your window.

The beauty of assembler!!! You can achieve the same result in so many ways.

Raymond
Posted on 2003-05-07 22:41:35 by Raymond