forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to identify the handle of a graphics region?

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
Kenneth_Smith



Joined: 18 May 2012
Posts: 126
Location: Glasgow, Scotland.

PostPosted: Sat Apr 08, 2017 10:34 pm    Post subject: How to identify the handle of a graphics region? Reply with quote

I've been thinking that my applications would be easier to use if the user could select a graphics region and export it to the clipboard for inclusion into a report. Generally I have multiple graphics regions open at any one time. I've come up with the following lines of code, which does the job when the user right clicks on the graphic region they want to copy but I need to have a dedicated call back function for each graphic region. Is there a way that I can simplify this so that there is only a single call back for every %gr or %pl region, perhaps there is a way to identify the handle of the graphics region that initiated the call back, or use of a "compound call-back" - I have found a fleeting reference to such a beast in the help files.

Any suggestions would be most welcome.

Thanks

Ken

Code:
program test
implicit none
include<windows.ins>
integer i, hand1, hand2, gw, gh
common /graphics/ hand1, hand2, gw, gh
integer gr_call_cb_1 ; external gr_call_cb_1
integer gr_call_cb_2 ; external gr_call_cb_2
real(kind=2) x(1:100), y(1:100), z(1:100), t, dt
hand1 = 1
hand2 = 2
gw = 300
gh = 200

t = 0.d0 ; dt = 0.0005d0
do i = 1, 100
  x(i) = t
  y(i) = sin(315.d0*t)
  z(i) = cos(315.d0*t)
  t = t + dt
end do

i = winio@('%`^pl[native,x_array,width=2,smoothing=4]&',gw,gh,100,x,y,hand1,gr_call_cb_1)
i = winio@('%`^pl[native,x_array,width=2,smoothing=4]' ,gw,gh,100,x,z,hand2,gr_call_cb_2)
!i = winio@('%`^gr[RED]&',gw,gh,hand1,gr_call_cb_1)
!i = winio@('%`^gr[BLUE]',gw,gh,hand2,gr_call_cb_2)

end program test


integer function gr_call_cb_1()
implicit none
include<windows.ins>
integer i1, i2, hand1, hand2, gw, gh
common /graphics/ hand1, hand2, gw, gh
integer SELECT_GRAPHICS_OBJECT@
  if (clearwin_string@('CALLBACK_REASON') .eq. 'MOUSE_RIGHT_CLICK') then
    i1 = SELECT_GRAPHICS_OBJECT@(hand1)
    i2 = GRAPHICS_TO_CLIPBOARD@(0,0,gw,gh)
    if (( i1 .eq. 1) .and. (i2 .eq. 1) ) write(6,*) 'STATUS: Graphics copied to clipboard'
  end if
  gr_call_cb_1 = 1
end function gr_call_cb_1


integer function gr_call_cb_2()
implicit none
include<windows.ins>
integer i1, i2, hand1, hand2, gw, gh
common /graphics/ hand1, hand2, gw, gh
integer SELECT_GRAPHICS_OBJECT@
  if (clearwin_string@('CALLBACK_REASON') .eq. 'MOUSE_RIGHT_CLICK') then
    i1 = SELECT_GRAPHICS_OBJECT@(hand2)
    i2 = GRAPHICS_TO_CLIPBOARD@(0,0,gw,gh)
    if (( i1 .eq. 1) .and. (i2 .eq. 1) ) write(6,*) 'STATUS: Graphics copied to clipboard'
  end if
  gr_call_cb_2 = 1
end function gr_call_cb_2
Back to top
View user's profile Send private message Visit poster's website
John-Silver



Joined: 30 Jul 2013
Posts: 558

PostPosted: Sun Apr 09, 2017 6:06 am    Post subject: Reply with quote

Quote:
perhaps there is a way to identify the handle of the graphics region that initiated the call back


Ken, might these CLEARWIN_INFO@ options help you:
Quote:
http://silverfrost.com/ftn95-help/clearwinp/library/clearwin_info_.aspx


In particular:
CALL_BACK_WINDOW
This option provides the call-back routine with the handle of the window generating the call-back.

and/or maybe

FOCUS_WINDOW
This parameter will return the Window handle of the window with focus, or zero if no window of the application has the focus ( see %hw).
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 4915
Location: Salford, UK

PostPosted: Sun Apr 09, 2017 8:35 am    Post subject: Reply with quote

Using CALL_BACK_WINDOW is a good idea. This can be coupled with using %lc immediately after each %gr in order to match the associated HWNDs.
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 1651
Location: Yateley, Hants, UK

PostPosted: Mon Apr 10, 2017 9:54 am    Post subject: Reply with quote

I think I must be missing something here, because I thought the user supplied the handle for a graphics region rather than it being one of a pool that windows assigns to every window or control when they are created. So unlike most other handles dealt with in Clearwin+.

That assumption has stood me in good stead in the past, and I've moved from graphics region to graphics region with never a glitch because I knew what the handles were - or thought I did.

If the handles for %gr are in fact those 'pick any number you didn't think of' integers that Windows gives you, then why the heck does my stuff work?

PS. If I can make things work by pure chance, then maybe my talents are wasted and I should be working in my retirement on porcine aviation, cold fusion, or teaching novel skills to elderly canines.

Eddie

(On the basis that a graphics region is a windows control, presumably it has a ghastly proper windows handle too. Kenneth, I'd stick to separate graphics call back functions. Mine are already ten to twenty times longer just for one graphics window than anything else I've written, but it does depend on how much graphics interaction the user has. There is nothing to stop you having multiple call-back functions that call other subprograms for common tasks. That method stops my %gr callback function(s) being a hundred times longer!)
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 4915
Location: Salford, UK

PostPosted: Mon Apr 10, 2017 10:48 am    Post subject: Reply with quote

Yes a %gr region has its own programmer defined identifier (which unfortunately is/was called a "handle" in the documentation). This identifier is used for example in SELECT_GRAPHICS_OBJECT@.

But the %gr control (like any other control) is also a Microsoft Window with its own HWND. You can get this value by using %lc immediately after %gr (in this case). This is the value given by a call to CLEARWIN_INFO@("CALL_BACK_WINDOW").
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 1651
Location: Yateley, Hants, UK

PostPosted: Mon Apr 10, 2017 11:09 am    Post subject: Reply with quote

Thanks Paul, so I was right. Apologies if the intended humour came over as something else.

E
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 126
Location: Glasgow, Scotland.

PostPosted: Mon Apr 10, 2017 6:00 pm    Post subject: Reply with quote

Paul, John, Eddie, thanks for the suggestions. After a frustrating Sunday afternoon, reading hitherto unexplored parts of the help manual I opted for a separate call back for each graphics region - a tad verbose but quick and simple.

Ken
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group