April 26, 2024, 03:30:30 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Dragging controls - testing

Started by Andy, November 23, 2017, 05:42:52 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aurelCB

oh i see now
you want to move created controls around window?
that is relatively easy
under windows message WM_MOUSEMOVE
you must add code to detect position of your control
for example if your button is
x=100,y=100
under submesagge WM_LMOUSEBUTTONDOWN
which mean when your left mouse button is down
then you use
api call - MoveWindow where you add x,y variable to track you mouse pointer
is that clear for you?

jalih

Quote from: Andy on November 26, 2017, 03:23:37 AM
The whole point of me writing this file was so that any of us could add in say just 5 or 6 lines to their iwb program in a simple way to give some powerful functions.

Example:

To check if the mouse is over a control you only need 3 commands, all written for you (and yes that timer)....

1. MouseOverControl(w1,1) <--- Tell the include file the control you want to keep track of.
2. Trackwindow(w1) <--- Track the window in case it is moved / re-sized.
3. IF MouseOver(w1,1) <--- Mouse is over the control ----- do something.....

Where w1 is the window, and 1 is the control.
You could subclass control and store controls parent HWND. Define your own custom window message. Inside your subclassed control handler, you handle WM_NCHITTEST message and test if result is HTCLIENT. If it is, then get mouse cursor position and send your custom window message to parent window along with controls HWND and mouse cursor position information. You can store that information inside wparam and lparam of window message.

Now parent window gets window message along with control handle and mouse cursor position, when mouse cursor moves inside controls client area.

This functionality could be encapsulated inside  two functions (add and remove tracking). Program using these functions would only need to handle your custom window message.

Andy

Both good ideas / suggestions, thanks - I will look into them.

So to round up the original question if my drag control command worked on other machines - yes it did.

Thanks every one for the posts / testing / suggestions, always useful and constructive.

Andy.
:)




Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Aurel,

This topic is in danger of becoming a Big Willy contest! I wish I knew more about the API without having to look them up frequently, and you must be clever to do what you have done, with your DLLS

But you started somewhere, and had some source code to get where you are now. What we are doing with the windowssdk.inc is a shortcut, admittedly. But the clever part is knowing which constant, type or declare, etc, to use given your current needs

Enough already!

Brian

jalih

Andy,

Here are my mouse tracking support routines for controls. You simply get window messages for mouse enter, mouse move and mouse leave.

Have fun!


$INCLUDE "windowssdk.inc"

' User defined window messages
$define MSG_TRACK_ENTER   0x4001
$define MSG_TRACK_MOVE    0x4002
$define MSG_TRACK_LEAVE   0x4003


window w1
openwindow w1,10,20,800,800,@sysmenu,0,"Mouse tracking for controls...",&w1_handler
CONTROL w1,@BUTTON,"1",50,40,200,50,0x50000000,1
CONTROL w1,@BUTTON,"2",50,150,100,50,0x50000000,2
CONTROL w1,@BUTTON,"3",50,250,100,50,0x50000000,3
CONTROL w1,@STATIC,"4",50,400,102,340,SS_NOTIFY, 4

TrackControl(w1, 1)
TrackControl(w1, 2)
TrackControl(w1, 3)
TrackControl(w1, 4)

openconsole

waituntil iswindowclosed(w1)
end

sub w1_handler(),int
SELECT @MESSAGE
CASE @IDCREATE
centerwindow w1
CASE @IDCLOSEWINDOW
UnTrackControl(w1, 1)
UnTrackControl(w1, 2)
UnTrackControl(w1, 3)
UnTrackControl(w1, 4)
CLOSEWINDOW w1
CASE MSG_TRACK_ENTER
print "Mouse Enter: ", "window handle:", @WPARAM, "x:", @LPARAM & 0xFF, "y:", @LPARAM >> 16
CASE MSG_TRACK_MOVE
print "Mouse Move : ", "window handle:", @WPARAM, "x:", @LPARAM & 0xFF, "y:", @LPARAM >> 16
CASE MSG_TRACK_LEAVE
print "Mouse Leave: ", "window handle:", @WPARAM
print ""
endselect
RETURN 0
ENDSUB


/****************************************************************************/

sub TrackHandler(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam),LRESULT
static int enter = FALSE

TRACKMOUSEEVENT tme
tme.cbSize = sizeof(tme)
tme.dwFlags = TME_LEAVE
tme.hwndTrack = hWnd
tme.dwHoverTime = HOVER_DEFAULT

pointer dat = GetWindowLong(hWnd, GWL_USERDATA)

SELECT uMsg
CASE WM_MOUSEMOVE
if !enter
enter = TRUE
TrackMouseEvent(&tme)
sendmessage(#<int>dat[0], MSG_TRACK_ENTER, hWnd, lParam)
ELSE
sendmessage(#<int>dat[0], MSG_TRACK_MOVE, hWnd, lParam)
EndIF
return 0
CASE WM_MOUSELEAVE
enter = FALSE
sendmessage(#<int>dat[0], MSG_TRACK_LEAVE, hWnd, 0)
return 0
ENDSELECT
RETURN CallWindowProcA(#<int>dat[1],hWnd,uMsg,wParam,lParam)
ENDSUB


SUB TrackControl(WINDOW parent, INT id)
  HWND hControl = GETCONTROLHANDLE(parent,id)
  WNDPROC lpFn = GetWindowLong(hControl, GWL_WNDPROC)
  pointer dat

  IF lpFn <> &TrackHandler
    WNDPROC OldWndProc = SetWindowLongA(hControl,GWL_WNDPROC,&TrackHandler)
    dat = new(int, 2)
    #<int>dat[0] = parent.hwnd
    #<int>dat[1] = OldWndProc
    SetWindowLong(hControl, GWL_USERDATA, dat)
  endif
endsub


SUB UnTrackControl(WINDOW parent, INT id)
  HWND hControl = GETCONTROLHANDLE(parent,id)

  WNDPROC lpFn = GetWindowLong(hControl, GWL_WNDPROC)
  if lpFn = &TrackHandler
    pointer dat = GetWindowLong(hControl, GWL_USERDATA)
    SetWindowLongA(hControl, GWL_WNDPROC, #<int>dat[1])
    delete dat
  endif
endsub

Andy

Thanks Jalih,

I will.

Think / consider this post closed now as far as I am concerned - thanks everyone.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.