Silverfrost Forums

Welcome to our forums

How to identify the handle of a graphics region?

8 Apr 2017 9:34 #19366

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

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
9 Apr 2017 7:35 #19367

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.

10 Apr 2017 8:54 #19368

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!)

10 Apr 2017 9:48 #19369

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').

10 Apr 2017 10:09 #19370

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

E

10 Apr 2017 5:00 #19375

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

Please login to reply.