[comp.os.os2.programmer] Dragging graphical objects

martti@spencer.cs.uoregon.edu (Martti Kantola) (08/07/90)

I need to drag graphical objects around on the screen using the mouse but can't
figure out how to do it. What I think I need is something similar to the Mac's
DragGrayRgn-function. Is there a PM counterpart for this function, anyone?

Thanks, Marti Kantola

ie15@vaxb.acs.unt.edu (09/01/90)

In article <1990Aug6.190714.5592@cs.uoregon.edu>, martti@spencer.cs.uoregon.edu (Martti Kantola) writes:
> I need to drag graphical objects around on the screen using the mouse but can't
> figure out how to do it. What I think I need is something similar to the Mac's
> DragGrayRgn-function. Is there a PM counterpart for this function, anyone?
> 

What I have been doing to is to change the mouse pointer to the new object,
a file folder for instance, then I capture all the mouse messages and wait for
a button1 up, asuming this function was initiated from some menu selection as
opposed to some "pick-up-and-drop". When I get the mouse button up message I
unset the pointer, un capture the mouse mesassages, find out where the mouse
pointer is pointing at, and take apprpriate steps. Pseudo-C-Code looks like:

   wpMain( HWND   hwnd...)
   {static HPOINTER   hptr;

      WM_COMMAND: * The users selections some sort of initial function that
                  we know means the user wants to manipulate his document
                  hptr =WinLoadPointer( HWND_DESKTOP, NULL, ID_PTR_DOC);
                  WinSetCapture( HWND_DESKTOP, hwnd, TRUE);
                  WinSetPointer( HWND_DESKTOP, hptr);
                  * any other internal flags settings, processing
                  return( 0);
     WM_MOUSEMOVE: We need to set the mouse pointer to OUR document pointer
                   every time the mouse moves because PM will change it back
                   to the default pointer every mousemove
                  WinSetPointer( HWND_DESKTOP, hptr);
                  return( 1); * returning a 1 is important

     WM_MOUSEBUTTON1_DOWN:
                  * The user has clicked on a spot where he wants the document
                    dropped. The pointer position comes in as a message param
                    one. Check it and see if it's a valid spot. If it is then
                    do the proper manipulations
                  * And now WinDestroyPointer( hptr) to free up the mouse
                    pointer's resources 
                  * WinSetCapture( HWND_DESKTOP, hwnd, FALSE) to set capturing
                    off
                  return( 0);

When the mouse capturing is on it is impossible for the user to click another
window since our window procedure gets all the mouse button downs. Also,
strange X & Y coordinates may come in since all clicks are related to our
window and our window doesn't necessarily cover the entire window. So a click
to the left or under our window will return negative values. As expected,
really, considering the Cartesian coordinate system

Good luck,
Ken Tabor
UNT