Silverfrost Forums

Welcome to our forums

callback mouse click

19 Jun 2015 8:04 #16477

Who can help me: Is there a callback to check, if a left_mouse_click was done without using the format codes (%gr) or (%dw) analogous the ('%ac) codes in the example (see ??? in attached example). If not what solutions exists to realise this?

winapp 
program mouse_click_test 
include <windows.ins> 
external ienter,iesc
!external ileft_mouse_click  ????????
character*5 data1, data2
integer*4 ifocus,ncontrol,icontrol(2)
common/focus_control/ifocus,ncontrol,icontrol

data1 = '11111'
data2 = '22222'
i=ifw() 
call add_focus_monitor@(ifw)
ncontrol = 2 
i=winio@('%ac[Enter]&',ienter) 
i=winio@('%ac[ESC]&',iesc)
!i=winio@('%?????????????&',ileft_mouse_click)   ?????????????
i=winio@('%nl%rs%lc&',data1,icontrol(1))
i=winio@('%nl%rs%lc',data2,icontrol(2))
call remove_focus_monitor@(ifw)       
end 

integer*4 function ienter()
include <windows.ins>
integer*4 ifocus,ncontrol,icontrol(2)
common/focus_control/ifocus,ncontrol,icontrol
ienter=1
write(*,*)'ienter pressed'
! do something
if(ifocus.eq.icontrol(1))call set_highlighted@(icontrol(2))
if(ifocus.eq.icontrol(2))call set_highlighted@(icontrol(1))
end

integer*4 function iesc()
include <windows.ins> 
integer*4 ifocus,ncontrol,icontrol(2)
common/focus_control/ifocus,ncontrol,icontrol
iesc=0
write(*,*)'ESC pressed'
! End
end

integer*4 function ifw() 
include <windows.ins> 
common/focus_control/ifocus,ncontrol,icontrol(100) 
ifw=2 
ifocus=clearwin_info@('FOCUSSED_WINDOW') 
end 

! ????????????????????????
!integer*4 function ileft_mouse_click()
!include <windows.ins> 
!integer*4 ifocus,ncontrol,icontrol(2)
!common/focus_control/ifocus,ncontrol,icontrol
!ileft_mouse_click = 1
!write(*,*)'ileft_mouse_click pressed'
! do something
!end
19 Jun 2015 2:41 #16478

CLEARWIN_STRING looks like it might help.

Eddie

22 Jun 2015 7:35 #16486

The short answer is that it is not possible to attach a callback to a mouse click in the same way that you would attach a callback to a key press. You might be able to use %mg with WM_LBUTTONDOWN but this could be tricky. I can supply further details if you want to try this approach.

22 Jun 2015 8:37 #16487

Paul, i am very interested to find o solution and would be happy about a sample. Thank you.

22 Jun 2015 11:08 #16488

Here is something to get you started but it only works when you click on the main window. It may not work when you click on a control within the main window.

WINAPP
program main
use mswin
integer iw,n
integer,external::cb
n = 100
iw=winio@('%mg&', WM_LBUTTONDOWN, cb)
iw=winio@('%`rd', n)
end

integer function cb()
integer iw
integer,external::winio@
iw = winio@('OK')
cb = 3
end
22 Jun 2015 1:49 #16490

Paul, thank you, this works super but the problem is really that it doesn't work within a control. Is their a possibility to attach a separate callback to a mouse click within a control(perhaps with CLEARWIN_STRING) ?

22 Jun 2015 1:54 #16491

Which control do you have in mind?

22 Jun 2015 2:04 #16492

mostly the rs control like for example i=winio@('%nl%rs%lc &',cpos,icontrol(1))

22 Jun 2015 3:24 #16494

%rs uses a Microsoft Edit control. When you click on it, it gets the focus.

Perhaps you need to monitor the focus using add_focus_monitor@.

22 Jun 2015 7:20 #16497

It looked to me that you could only detect a mouse click inside a control, and as Paul's solution works outside the controls, maybe you have to have separate code for inside and out.

In the callback from your control CLEARWIN_STRING@(CALLBACK_REASON) should allow you to detect all manner of mouse click and release events according to the documentation, which is what I meant with my original terse post.

Paul's solution of detecting gaining focus surely works for only the first click?

Eddie

23 Jun 2015 6:25 #16498

I suspect that 'CALLBACK_REASON' is not useful in this context.

module mymod
character(20) txt
contains
 integer function cb()
 use clrwin
 print*, trim(clearwin_string@('callback_reason')), ':', trim(txt)
 cb = 2
 end function
end module

WINAPP
program main
use mymod
integer iw
integer,external::winio@
txt = ' '
iw=winio@('%^rs', txt, cb)
end
23 Jun 2015 6:47 #16499

Here is a sample for add_focus_monitor@. As Eddie says, it is only useful for the first click on a given control. A second click on the same control has no effect.

module mymod
character(20) txt
integer han,h1,h2
contains
 integer function cb()
 use clrwin
 integer h
 h = clearwin_info@('focussed_window')
 han = 0
 if(h == h1) han = 1
 if(h == h2) han = 2
 call window_update@(han)
 cb = 2
 end function
end module

WINAPP
program main
use clrwin
use mymod
integer iw
integer,external::winio@
txt = ' '
call add_focus_monitor@(cb)
iw=winio@('%ff%nl%rs%lc&', txt, h1)
iw=winio@('%ff%nl%rs%lc&', txt, h2)
iw=winio@('%ff%nl%rd', han)
end
23 Jun 2015 2:24 #16500

I have a bunch of adages, and one of them is that if what you want to do seems impossible or difficult, then quite possibly what you are attempting is a non-standard way of working in a Windows application!

For further advice/suggestions, please tell us exactly where the mouse pointer might be when you want to detect clicks, and also, why you want them and what you would do with them when (and if) you got them ...

Eddie

23 Jun 2015 6:36 #16501

Paul, your sample with add_focus_monitor@ seems to be a solution for me and I will try it.

What I want to do: I youse my short sample code from Fri Jun 19, 2015 for input real values, integer values, characters aso. When I press for example the ENTER button, the ienter() function will be called, the control jumps into the next line and I can do many tests within the ienter() function, like -tests for defined characters like 'yes', 'no' -convert the characters to integer values with „read (cfeld,'(i10)') izahl -convert the characters to real values with „read (cfeld,'(f10.3)') rzahl -test the integer or real values for predefinded values like 1,5,7,13 , values greater than or less than and, and, and This works really very good since a long time.

The recurrent problem is, when I change from one control to the next not with the ENTER button but with a left-coursor-click the ienter() callback and it’s tests will not be called.

PS: In my original program I can change the controls with many key buttons like %ca[UP], %ca[DOWN] aso. It's not a disaster, when there is no solution, but of course it would be helpful.

24 Jun 2015 7:13 #16508

Bartl,

I think that you are trying to do too much with %rs (I salute your imagination!), and you should use the individual types of edit box for each type of variable.

If you have unlimited time and patience, and you really do want to have a general purpose input box that responds to all types of input including various mouse clicks, then you could program it in a small %gr box and process all or most of the events in its callback.

Eddie

28 Jun 2015 8:05 #16526

Perhaps I will ty it at any time.

Thank you very much for your help.

Please login to reply.