soccer jersey forums.silverfrost.com :: View topic - EXPORT_WINDOW_IMAGE@
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 

EXPORT_WINDOW_IMAGE@

 
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: 726
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Fri Oct 18, 2024 12:43 pm    Post subject: EXPORT_WINDOW_IMAGE@ Reply with quote

I don�t normally use an external monitor with my laptop, and I received some feedback from a user who does.

The following program creates a %gr region and has some controls to the right of this.

There is a menu item �To clipboard� which copies the whole window to the clipboard.

This works so long as the user has not moved the window onto a second display i.e. large monitor.

If the window is on the large monitor, the �To clipboard� operation does not capture the correct parts of the monitor display i.e. EXPORT_WINDOW_IMAGE@ fails in this scenario.

Is there a simple fix to this?
Code:
module test
use clrwin
implicit none
real*8 :: pi=4.0*atan(1.d0)
integer :: tmp_gr_handle  = 1000
integer(7) :: plot_window_handle
contains
integer function g()
integer :: iw
   iw = winio@('%hw&',plot_window_handle)
   iw = winio@('%mn[Exit]&','exit')
   iw = winio@('%mn[To clipboard]&',to_clipboard_cb)
   iw = winio@('%2.1ob&')
   iw = winio@('%gr[red]%cb&',900,620)
   iw = winio@('Pi = %`rf&',pi)
   iw = winio@('%cb&')
   iw = winio@('')
   g = 1
 end function g

 integer function to_clipboard_cb()
! Call back function to copy current client area of active window to windows clipboard
integer :: i, width, height, nbbp, ercode
integer(2):: ercode1
   i = EXPORT_WINDOW_IMAGE@(plot_window_handle, 'tmp.jpg', 1)
   call GET_DIB_SIZE@('tmp.jpg', width, height, nbbp, ercode)
   i = CREATE_GRAPHICS_REGION@(tmp_gr_handle,width,height)
   i = IMPORT_IMAGE@('{tmp.jpg}',1,1)
   i = GRAPHICS_TO_CLIPBOARD@(1,1,width-3,height-3) !Trim edges
   i = DELETE_GRAPHICS_REGION@(tmp_gr_handle)
   CALL ERASE@('tmp.jpg',ercode1)
   to_clipboard_cb = 2
 end function to_clipboard_cb
end module test

program main
use test
i = g()
end program main
Back to top
View user's profile Send private message Visit poster's website
Kenneth_Smith



Joined: 18 May 2012
Posts: 726
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Fri Oct 18, 2024 12:53 pm    Post subject: Reply with quote

Here is a link to two images for the two scenarios described above:

https://www.dropbox.com/scl/fi/m0b9l1vkyu6oz4fclcbg9/example.pdf?rlkey=5nx1g978s847lp1ucley1vkgo&st=lk0fjqtt&dl=0
Back to top
View user's profile Send private message Visit poster's website
JohnCampbell



Joined: 16 Feb 2006
Posts: 2593
Location: Sydney

PostPosted: Fri Oct 18, 2024 2:08 pm    Post subject: Reply with quote

Ken,

It has been a long time since I wrote this code (~2005), but I recall I overcame this secondary screen problem by providing a window handle then selecting the graphics region I wanted to populate then dump.

The main %gr window was numbered by
i = winio@ ('%hw', hw_handle) ! return the handle of the current window.

However if I use other secondary (virtual) windows, then I have
handle(ii) = ii+10
i = create_graphics_region@ (handle(ii), nxpix+11, nypix+35)
i = select_graphics_object@ (handle(ii))

I then selected the window I wanted to be active and dumped to the file type with:
error_jpg = export_image@ (file_jpg) ! use .png format

The multiple secondary windows can be used to draw then display sinusoidal motion.

I don't recall the second physical screen being a problem. It must be in focus / selected.

I also utilised this approach for higher resolution dumps, by creating a larger
virtual graphics region (with a different handle) then selecting, then populating and finally dumping.

My graphics approach is to use a virtual screen of both 2d arrays for integer*1 pixel colour index ( up to 127 or 255 colours) and real*4 pixel depth to provide hidden line removal, then finalise by dumping the integer*4 pixel colours to the select_graphics_object@
These virtual screens were created large enough for the virtual size (4000 x 3000 at the time). This was all done before /64.
(when updating it was important to scan the screen in a contiguous way; I used by "y" and the arrays were transposed )

The approach of first selecting either %gr or virtual window, then exporting has worked with no problem.
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 726
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Fri Oct 18, 2024 3:16 pm    Post subject: Reply with quote

John,

Thanks for your comments and observations.

EXPORT_WINDOW_IMAGE@ is a relatively new feature which allows you to capture the whole window including controls that surround the graphics region.

Here is the window I am trying to capture:

https://www.dropbox.com/scl/fi/b4ab0xr4jf4fwt4zaren3/Hist.jpg?rlkey=lltagidhpx600r5m6bdwe2i2s&st=59bnpptg&dl=0

There is an %ob2.1[invisible], the %pl graphics region is in the left box and in the right box I have a long list of information providing data using %`rf.

At first glance it appears that this information has been written to the right margin of a %pl region but this is not the case.

Nesting all these outputs via %`rf simplified the initial programming (I was being lazy) and all appeared to work fine a few months back when I wrote this program having just found EXPORT_WINDOW_IMAGE@ in cwplus.enh (no pivot on the %pl so no problems with these elements sliding downward).

Now I fear I may need to revise the code, remove all the %`rf and add all this information in a larger right margin within the %pl callback via DRAW_CHARACTERS@. I can then avoid the use of EXPORT_WINDOW_IMAGE@

So not quite the same as what you describe.
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


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

PostPosted: Sat Oct 19, 2024 7:49 am    Post subject: Reply with quote

Ken

I have tested your program and it works for me. I use two monitors and it works both ways, when the slave monitor is to the right and when it is to the left.

When grabbing the client window, EXPORT_WINDOW_IMAGE@ calls

Code:
      GetClientRect(hwnd, &rc);
      MapWindowPoints(hwnd, NULL, (POINT*)&rc, 2);


in order to get the client rectangle that is used to grab the desktop DIB.

So it seems that GetClientRect is not giving the correct result for the user's monitor configuration. But, in the absence of a failing demonstration, I can't begin to explore alternatives to GetClientRect.
Back to top
View user's profile Send private message AIM Address
Kenneth_Smith



Joined: 18 May 2012
Posts: 726
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Sat Oct 19, 2024 10:52 am    Post subject: Reply with quote

Paul,

Thanks for confirming that the sample program works correctly for you.

Encouraged by this I interrogated the system settings this morning, and I see there is an option:

System > Display > Scale & layout where scale was set at 125% (Recommended!)

When I change this to 100%, the issue with EXPORT_WINDOW_IMAGE@ vanishes . All other available settings (125%, 150%, 175%) have problems when the window is moved on to the external monitor.

I guess 125% is the default factory setting, as I don�t recall changing this.

Ken
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


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

PostPosted: Sun Oct 20, 2024 3:32 pm    Post subject: Reply with quote

Ken

I also see the fault when using a display scaling factor that is not 100%.

One way to fix this is to call

Code:
iw = SetDpiAwareness@(0)


at the start of the program.

The Windows API function

Code:
dpi = GetDpiForWindow(hwnd)


gives 96 for 100% scaling with other values for 125% etc.. So this call would indicate when a correction is needed.

Please let me know if this is sufficient for your purposes. In theory ClearWin+ can be fixed to make it work for any DPI setting but, off hand, I don't know how easy that would be.
Back to top
View user's profile Send private message AIM Address
Kenneth_Smith



Joined: 18 May 2012
Posts: 726
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Mon Oct 21, 2024 10:03 am    Post subject: Reply with quote

Paul,

Thanks for the one line fix.

This works well in my application:

Code:
iw = SetDpiAwareness@(2)


No need for you to take this further.

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