Old 01-25-2020, 04:00 AM   #921
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,588
Default

Thanks for the help Edgemeal!



That is the window that tweaks the colors of a theme.


Theme development: Show theme tweak/configuration window, action 41930


Win10(US English), REAPER v6.03/x64 here too.
amagalma is offline   Reply With Quote
Old 01-25-2020, 04:31 AM   #922
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,588
Default

Quote:
Originally Posted by amagalma View Post
Thanks for the help Edgemeal!



That is the window that tweaks the colors of a theme.


Theme development: Show theme tweak/configuration window, action 41930


Win10(US English), REAPER v6.03/x64 here too.

Edit.. Actually what is returned is not 'chinese'.. it's all the the characters of the keyboard..


Code:
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™
amagalma is offline   Reply With Quote
Old 01-25-2020, 05:05 AM   #923
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,960
Default

Quote:
Originally Posted by Dafarkias View Post
Quick question regarding my usage of the following code:

Code:
if reaper.JS_VKeys_GetState( 0 ):byte(hotkey[a].key) ~= 0 then
It works just fine to intercept key-presses from almost every window in REAPER, except the mixer.

Is there a way to combat this?
Could you elaborate? (Do you mean that when the mixer is in the foreground, GetState does not detect any key strokes?)
juliansader is offline   Reply With Quote
Old 01-25-2020, 05:07 AM   #924
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,960
Default

Quote:
Originally Posted by spk77 View Post
Is there any way to set the minimum size of a window?
It can get quite tiny (window style is "WS_BORDER"):
You can perhaps check the window size in every defer cycle, and then resize whenever the size is too small.

Alternatively, use a window style that does not allow resizing.
juliansader is offline   Reply With Quote
Old 01-25-2020, 05:25 AM   #925
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,634
Default

Quote:
Originally Posted by amagalma View Post
That is the window that tweaks the colors of a theme.
Theme development: Show theme tweak/configuration window, action 41930
Oh OK, thats an owner-drawn listbox (SPY++ says LBS_OWNERDRAWFIXED style), I don't know how you go about reading item text from those.

EDIT
To be able to use LB_GETTEXT like I was seems that owner-drawn listbox would also need to have the LBS_HASSTRINGS flag set which it doesn't.

List Box Styles,
https://docs.microsoft.com/en-us/win...ist-box-styles


I'm not a Win32 API guru either, so...

Last edited by Edgemeal; 01-26-2020 at 03:29 PM.
Edgemeal is offline   Reply With Quote
Old 01-25-2020, 07:42 AM   #926
Dafarkias
Human being with feelings
 
Dafarkias's Avatar
 
Join Date: Feb 2019
Location: England
Posts: 456
Default

Quote:
Originally Posted by juliansader View Post
Could you elaborate? (Do you mean that when the mixer is in the foreground, GetState does not detect any key strokes?)
Sorry for not making that clear, yes.

For me, when the mixer is focused, the VKeys code I shared does not receive any input.
Dafarkias is offline   Reply With Quote
Old 01-25-2020, 10:35 AM   #927
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,960
Default

Quote:
Originally Posted by Dafarkias View Post
Sorry for not making that clear, yes.

For me, when the mixer is focused, the VKeys code I shared does not receive any input.
Good catch. I will submit a bug report.
juliansader is offline   Reply With Quote
Old 01-25-2020, 01:41 PM   #928
Dafarkias
Human being with feelings
 
Dafarkias's Avatar
 
Join Date: Feb 2019
Location: England
Posts: 456
Default

Quote:
Originally Posted by juliansader View Post
Good catch. I will submit a bug report.
That's a bug?

Hm.

I guess I just figured that I was missing something or just wasn't using the function properly...
Dafarkias is offline   Reply With Quote
Old 01-28-2020, 04:49 AM   #929
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,588
Default

How to know if particular keys are being held down during defer?


Example/pseudo code:
Code:
function main()
  --[[
  OK = check if alt + shift are being pressed
  --]]
  if OK then
    reaper.defer(main)
  else
    reaper.ShowConsoleMsg("You released Alt+Shift")
    return
  end
end
amagalma is offline   Reply With Quote
Old 01-28-2020, 10:26 AM   #930
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,960
Default

Quote:
Originally Posted by amagalma View Post
How to know if particular keys are being held down during defer?
You can either use JS_VKeys_GetState (which is similar to the Win32 function GetKeyboardState) or, for modifier keys only, JS_Mouse_GetState:

Code:
if reaper.JS_VKeys_GetState(scriptStartTime):byte(x) ~= 0 then ...
or

Code:
if reaper.JS_Mouse_GetState(24) == 24 then ... -- 8:Shift, 16:Alt
juliansader is offline   Reply With Quote
Old 01-28-2020, 03:05 PM   #931
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,588
Default

Quote:
Originally Posted by juliansader View Post
You can either use JS_VKeys_GetState (which is similar to the Win32 function GetKeyboardState) or, for modifier keys only, JS_Mouse_GetState:

Code:
if reaper.JS_VKeys_GetState(scriptStartTime):byte(x) ~= 0 then ...
or

Code:
if reaper.JS_Mouse_GetState(24) == 24 then ... -- 8:Shift, 16:Alt

Thanks!!


If for example I want to check if "o" is being pressed then the code would be:
Code:
if reaper.JS_VKeys_GetState(scriptStartTime):byte("o") ~= 0 then

Correct?
amagalma is offline   Reply With Quote
Old 01-28-2020, 03:36 PM   #932
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,634
Default

Quote:
Originally Posted by amagalma View Post
Correct?
Think you need to use a virtual key code,
https://docs.microsoft.com/en-us/win...tual-key-codes

so something like,
VK_O = 0x4F -- 'O' key
... :byte(VK_O) ~= 0 then ...
Edgemeal is offline   Reply With Quote
Old 01-29-2020, 05:53 AM   #933
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,588
Default

Quote:
Originally Posted by Edgemeal View Post
Think you need to use a virtual key code,
https://docs.microsoft.com/en-us/win...tual-key-codes

so something like,
VK_O = 0x4F -- 'O' key
... :byte(VK_O) ~= 0 then ...

Thank you Edgemeal!!

Another question:

How can I know what key triggered the current script so that I can check if it is still being held down? For example I have set my script to work with mousewheel+Alt+Shift and have hard-coded in the script to check if Alt+Shift are being held (as julian showed me):
Code:
if reaper.JS_Mouse_GetState(24) == 24 then ... -- 8:Shift, 16:Alt
How could my script know the modifiers that triggered it without hard-coding it inside?
pseudo-code:
Code:
modifiers_that_triggered_script = xxxx
if reaper.JS_Mouse_GetState(modifiers_that_triggered_script ) == modifiers_that_triggered_script then

Last edited by amagalma; 01-29-2020 at 06:05 AM.
amagalma is offline   Reply With Quote
Old 01-29-2020, 06:31 AM   #934
amagalma
Human being with feelings
 
Join Date: Apr 2011
Posts: 1,588
Default

Found it!


Just this code outside of the defer:
Code:
for i = 60, 0, -4  do
  modifiers = reaper.JS_Mouse_GetState(i)
  if modifiers ~= 0 then break end
end
And this inside:
Code:
reaper.JS_Mouse_GetState(modifiers) == modifiers
amagalma is offline   Reply With Quote
Old 01-30-2020, 06:40 AM   #935
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,890
Default

Is there a code-snippet available, from which I can learn, how to save parts of the screen as pngs?

Basically my question is, how do I create a bitmap from the screen's contents, so I can use JS_LICE_WritePNG?
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635

Last edited by mespotine; 01-30-2020 at 07:02 AM.
mespotine is offline   Reply With Quote
Old 01-30-2020, 02:40 PM   #936
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,634
Default

Quote:
Originally Posted by mespotine View Post
Basically my question is, how do I create a bitmap from the screen's contents, so I can use JS_LICE_WritePNG?
Excellent question! I messed around with that a little bit before, PNG's look OK but I was never really sure I'm doing it correctly , would love to get Julian's feedback!

Capture screen area to PNG,..
Updated, Requires API v0.999
Code:
function CaptureScreenArea(x,y,w,h,filename)
  scrnDC = reaper.JS_GDI_GetScreenDC() --< Only available on Windows!
  destBmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  destDC = reaper.JS_LICE_GetDC(destBmp)
  reaper.JS_GDI_Blit(destDC, 0, 0, scrnDC, x, y, w, h)
  reaper.JS_LICE_WritePNG(filename, destBmp, false)
  reaper.JS_LICE_DestroyBitmap(destBmp)
  reaper.JS_GDI_ReleaseDC(scrnDC)
end

Capture a window to PNG,..
* On Windows 10 it captures only the target app window, even when behind other windows!
Code:
function GetBounds(hwnd)
  local _, left, top, right, bottom = reaper.JS_Window_GetRect(hwnd)
  return left, top, right-left, bottom-top
end

function CaptureWindow(windowTitle, filename, win10) 
  window = reaper.JS_Window_FindTop(windowTitle, true)
  if not window then reaper.MB('Window not found!','Capture Error',0) return end
  sourceHDC = reaper.JS_GDI_GetWindowDC(window)
  _,_,w,h = GetBounds(window)
  srcx,srcy = 0,0
  if win10 then srcx=7 w=w-14 h=h-7 end -- workaround for invisible Win10 borders.
  dest_bmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  destDC = reaper.JS_LICE_GetDC(dest_bmp)
  -- copy source to dest & write PNG
  reaper.JS_GDI_Blit(destDC, 0, 0, sourceHDC, srcx, srcy, w, h)
  reaper.JS_LICE_WritePNG(filename, dest_bmp, false) 
  -- clean up resources
  reaper.JS_GDI_ReleaseDC(window, sourceHDC)
  reaper.JS_LICE_DestroyBitmap(dest_bmp)
end

Last edited by Edgemeal; 02-08-2020 at 04:12 PM. Reason: Update for JS_API v0.999
Edgemeal is offline   Reply With Quote
Old 01-30-2020, 03:14 PM   #937
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,890
Default

Quote:
Originally Posted by Edgemeal View Post
Excellent question! I messed around with that a little bit before, PNG's look OK but I was never really sure I'm doing it correctly , would love to get Julian's feedback!

Capture screen area to PNG,..
Code:
function CaptureScreenArea(x,y,w,h,filename)
  sourceHDC = reaper.JS_GDI_GetScreenDC()
  destBmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  destDC = reaper.JS_LICE_GetDC(destBmp)
  reaper.JS_GDI_Blit(destDC, 0, 0, sourceHDC, x, y, w, h)
  reaper.JS_LICE_WritePNG(filename, destBmp, false)
  reaper.JS_LICE_DestroyBitmap(destBmp)
end

Capture a window to PNG,..
Code:
function GetBounds(hwnd)
  local _, left, top, right, bottom = reaper.JS_Window_GetRect(hwnd)
  return left, top, right-left, bottom-top
end

function CaptureWindow(windowTitle, filename, win10) 
  window = reaper.JS_Window_FindTop(windowTitle, true)
  if not window then reaper.MB('Window not found!','Capture Error',0) return end
  sourceHDC = reaper.JS_GDI_GetWindowDC(window)
  _,_,w,h = GetBounds(window)
  srcx,srcy = 0,0
  if win10 then srcx=7 w=w-14 h=h-7 end -- workaround for invisible Win10 borders.
  dest_bmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  destDC = reaper.JS_LICE_GetDC(dest_bmp)
  -- copy source to dest & write PNG
  reaper.JS_GDI_Blit(destDC, 0, 0, sourceHDC, srcx, srcy, w, h)
  reaper.JS_LICE_WritePNG(filename, dest_bmp, false) 
  -- clean up resources
  reaper.JS_GDI_ReleaseDC(window, sourceHDC)
  reaper.JS_LICE_DestroyBitmap(dest_bmp)
end
Thank You, Savior of the Universe
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 01-30-2020, 03:23 PM   #938
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,890
Default

Quote:
Originally Posted by juliansader View Post

I have spent an embarrassing amount of time trying to get png writing to work, but I can't get libpng to link properly.

However, this afternoon I tried writing jpegs with jpeglib, and it compiled and worked immediately.
From some time ago: would it be possible to add jpg support as well? This would help us tons at Ultraschall.
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 01-31-2020, 03:31 AM   #939
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,960
Default

Quote:
Originally Posted by Edgemeal View Post
Excellent question! I messed around with that a little bit before, PNG's look OK but I was never really sure I'm doing it correctly , would love to get Julian's feedback!
This is indeed the correct way to do it, AFAIK.

I just realized that there is no API function to release screen DCs, and I will add it in the next update.
juliansader is offline   Reply With Quote
Old 01-31-2020, 06:58 AM   #940
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,890
Default

@edgemeal
Works great
I will add slightly altered versions of your functions to my Ultraschall-Api, if that's ok.
I think they are real nice to have in the first place.

One more thing: when I capture a window, that is hidden by another window, I will capture the overlapping window instead or at least as well. Is there a chance to get the content of the window regardless of being hidden behind other windows?
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 01-31-2020, 12:27 PM   #941
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,634
Default

Quote:
Originally Posted by juliansader View Post
This is indeed the correct way to do it, AFAIK.

I just realized that there is no API function to release screen DCs, and I will add it in the next update.
Thanks for the reply! I was wondering about that, looking at it again today I see the GDI Object counter for reaper.exe increments everytime I call the CaptureScreenArea function, so ya looks like it has a leak!
Edgemeal is offline   Reply With Quote
Old 01-31-2020, 12:28 PM   #942
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,634
Default

Quote:
Originally Posted by mespotine View Post
@edgemeal
One more thing: when I capture a window, that is hidden by another window, I will capture the overlapping window instead or at least as well. Is there a chance to get the content of the window regardless of being hidden behind other windows?
If you use the CaptureWindow function the source window can be completely behind other windows, or not completely visible in desktop area and the capture should be only the source window, at least thats the way it works here on Win10.
Edgemeal is offline   Reply With Quote
Old 02-02-2020, 09:15 AM   #943
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,890
Default

Hmm...maybe something changed since Windows 7 as I had numerous problems with it.

Will investigate into it further. Maybe I'm just holding it wrong.
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 02-02-2020, 10:47 AM   #944
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,634
Default

Quote:
Originally Posted by mespotine View Post
Hmm...maybe something changed since Windows 7 as I had numerous problems with it.

Will investigate into it further. Maybe I'm just holding it wrong.
Not sure how Julian's API is doing it but 10+ years ago I used BitBlt and StretchBlt in many Windows apps where I'd blit parts of hidden images to create new images without a problem.

So can only guess you're using JS_GDI_GetScreenDC() instead of JS_GDI_GetWindowDC(hwnd).
Edgemeal is offline   Reply With Quote
Old 02-04-2020, 02:36 PM   #945
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,890
Default

I experimented with the problem further and it seems, that at least on Windows 7, the capturing of the gfx.init-window is not entirely possible.
Run the code and move windows on top of the gfx.init-window. You'll see the problems in the written pngs very quickly, as you can see the windows on top of the gfx.init-window in the written pngs.

I've looked into Julian's code and it seems, that this isn't a problem in his code, so I suspect, there's a WDL-bug somewhere.

Code:
-- This script will attempt to save a screenshot of the gfx-window once a second.
-- Just move some windows in front of the gfx-window to see the effect.
-- It captures the right window, BUT: also what's before it.
-- Maybe this is a Reaper-bug?

-- Set this output path and run the program.
-- In this path, all screenshots will be stored.
output_path="c:\\temp\\A2/"



-- the function for capturing, which is mostly your code, slightly altered(and simplified for this demo)
-- still, the bug remains

ultraschall={}
function ultraschall.CaptureWindowAsPNG(windowTitle, filename_with_path, x, y, w, h, win10)
  local window
  
  window = reaper.JS_Window_FindTop(windowTitle, true)
  
  local sourceHDC = reaper.JS_GDI_GetWindowDC(window)
  
  local _, Aleft, Atop, Aright, Abottom = reaper.JS_Window_GetRect(window)
  Aright=Aright-Aleft
  Abottom=Abottom-Atop
  if x==nil then x=0 end
  if y==nil then y=0 end
  if w==nil then w=Aright end
  if h==nil then h=Abottom end
  
  if win10 then srcx=7 w=w-14 h=h-7 end -- workaround for invisible Win10 borders.
  local dest_bmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  local destDC = reaper.JS_LICE_GetDC(dest_bmp)
  -- copy source to dest & write PNG
  reaper.JS_GDI_Blit(destDC, 0, 0, sourceHDC, x, y, w, h)
  local writeable = reaper.JS_LICE_WritePNG(filename_with_path, dest_bmp, false)
  -- clean up resources
  reaper.JS_GDI_ReleaseDC(window, sourceHDC)
  reaper.JS_LICE_DestroyBitmap(dest_bmp)
  if writeable==false then return 8 end
  return writeable
end




-- window
gfx.init("Tudelu bugtest")

-- prepare some variables and stuff
B=gfx.loadimg(1, reaper.GetResourcePath().."/data/track_icons/group.png")
gfx.x=-50
gfx.y=-300
gfx.blit(1,14,0)
gfx.setfont(1, "Arial", 50, 0)
counter=0
index=0


-- the main-defer-loop, which stores a screenshot of the gfx-window every second
function main()
  counter=counter+1
  if counter==30 then
    index=index+1
    if index<10 then zero="0" else zero="" end
    A=ultraschall.CaptureWindowAsPNG("Tudelu bugtest", output_path..zero..index..".png", 0, 0, gfx.w, gfx.h, true)
    counter=0
  end
  reaper.defer(main)
end

main()
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 02-04-2020, 03:20 PM   #946
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,634
Default

Quote:
Originally Posted by mespotine View Post
I experimented with the problem further and it seems, that at least on Windows 7, the capturing of the gfx.init-window is not entirely possible.
Ya OK, I tried the script on Win10 and is OK, but on Win7 I can see other windows that cover the source window.
Edgemeal is offline   Reply With Quote
Old 02-04-2020, 03:37 PM   #947
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,890
Default

Ok, then I'll add a note to the function's description, that it doesn't work on Windows 7 without issues.

@juliansader
Do you have an idea, what the problem could be? Shall I bugreport it?
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 02-05-2020, 12:19 AM   #948
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,960
Default

This is a Windows issue, not WDL, so unfortunately the bug cannot be reported to Cockos.

When I first started with the JS_Composite function, I also tried blitting from overlapped windows using GDI, and encountered the same problem. I then read somewhere that this behavior changed sometime around Windows XP: In the olden days, you could blit hidden parts of windows, but not in recent versions of Windows. I am actually surprised that it works (again) in Windows 10.

Perhaps it has something to do with windows styles? (Perhaps check whether the "overlapped" style has any effect?)
juliansader is offline   Reply With Quote
Old 02-05-2020, 11:39 AM   #949
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,634
Default

I must of been thinking of the PrintWindow function, that can capture windows behind other windows, my notes show I tested it in WinXP and Win7, and just now in Win10 and still works, one minor drawback is it ignores a windows opacity setting.
Edgemeal is offline   Reply With Quote
Old 02-05-2020, 01:05 PM   #950
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,666
Default

(Just a thing I noticed)
AHK source code seems to be very well documented - maybe it would be a useful resource for this extension.
https://github.com/Lexikos/AutoHotke.../master/source

Last edited by spk77; 02-05-2020 at 01:27 PM.
spk77 is offline   Reply With Quote
Old 02-05-2020, 01:09 PM   #951
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,890
Default

Quote:
Originally Posted by Edgemeal View Post
I must of been thinking of the PrintWindow function, that can capture windows behind other windows, my notes show I tested it in WinXP and Win7, and just now in Win10 and still works, one minor drawback is it ignores a windows opacity setting.
Would this be addable to JS-extension? This sounds like exactly what I need.
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 02-05-2020, 04:15 PM   #952
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,890
Default

Hmm, we've tried using my demo script under MacOS but for some reason, they only write black images, so there seems to be a problem with capturing the contents of the gfx-window.

tested on Reaper 6.03, Catalina 10.15.3
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 02-08-2020, 03:26 PM   #953
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,960
Default

I've update the extension to v0.999:
* JS_Window functions: On Linux and macOS, don't crash if handle is invalid.
* JS_Mouse_LoadCursorFromFile: On Windows, accept Unicode paths.
* JS_GDI_ReleaseDC: Can release screen HDCs.

Regarding the JS_Window functions:

Windows' own Win32 functions handle invalid HWNDs gracefully, but WDL/swell crashes (as I dramatically warned in the API documentation). When I first uploaded the extension, WDL/swell did not have a working IsWindow function, and reaper.ValidatePtr(hwnd, "HWND") did not yet exist, so I coded my own IsWindow function. My function work accurately, but was pretty slow, so I didn't want to run it each and every time a window-related function was called. Instead, scripts had to check IsWindow themselves, at strategic times.

REAPER's new ValidatePtr with "HWND" is quite fast -- a fraction of a microsecond -- so I think it is unlikely to affect performance, and I therefore added it to all the window-related functions on macOS and Linux. Hopefully it would prevent a few crashes and make the extension API feel more stable.
juliansader is offline   Reply With Quote
Old 02-08-2020, 03:55 PM   #954
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 1,634
Default

Quote:
Originally Posted by juliansader View Post
I've update the extension to v0.999:
Thanks for the updates!

Updated CaptureScreenArea function (API v0.999), no more leak!
Code:
function CaptureScreenArea(x,y,w,h,filename)
  scrnDC = reaper.JS_GDI_GetScreenDC() --< Only available on Windows!
  destBmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  destDC = reaper.JS_LICE_GetDC(destBmp)
  reaper.JS_GDI_Blit(destDC, 0, 0, scrnDC, x, y, w, h)
  reaper.JS_LICE_WritePNG(filename, destBmp, false)
  reaper.JS_LICE_DestroyBitmap(destBmp)
  reaper.JS_GDI_ReleaseDC(scrnDC)
end
Edgemeal is offline   Reply With Quote
Old 02-09-2020, 02:44 PM   #955
lb0
Human being with feelings
 
Join Date: Apr 2014
Posts: 3,426
Default

Quote:
Originally Posted by juliansader View Post
I've update the extension to v0.999:
Ooh - SetParent - thank you so much...

I'll have a play with that No idea whether it will do what I want it to do - and I may just end up breaking things - but will try a few things out. Much appreciated!
__________________
Projects - Reascripts - Lua:
LBX Stripper | LBX Chaos Engine | LBX Floating FX Positioner | LBX SRD Smart Knobs
Donate via Paypal
lb0 is offline   Reply With Quote
Old 02-10-2020, 07:42 AM   #956
rstockm
Human being with feelings
 
rstockm's Avatar
 
Join Date: May 2012
Location: Berlin, Germany
Posts: 88
Default

Quote:
Originally Posted by Edgemeal View Post
Thanks for the updates!

Updated CaptureScreenArea function (API v0.999), no more leak!
Code:
function CaptureScreenArea(x,y,w,h,filename)
  scrnDC = reaper.JS_GDI_GetScreenDC() --< Only available on Windows!
  destBmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  destDC = reaper.JS_LICE_GetDC(destBmp)
  reaper.JS_GDI_Blit(destDC, 0, 0, scrnDC, x, y, w, h)
  reaper.JS_LICE_WritePNG(filename, destBmp, false)
  reaper.JS_LICE_DestroyBitmap(destBmp)
  reaper.JS_GDI_ReleaseDC(scrnDC)
end
I figure this will not/never work on MacOS?
rstockm is offline   Reply With Quote
Old 02-15-2020, 02:54 PM   #957
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,960
Default

Quote:
Originally Posted by rstockm View Post
I figure this will not/never work on MacOS?
On Linux and macOS, standard WDL/swell functions provided by REAPER only have access to windows created by WDL/swell itself, so unfortunately it is unlikely to ever work on the whole screen.

(Unless of course if some macOS wizard on the forums can figure out custom code to accomplish it.)
juliansader is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:13 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.