I am creating a form designer, and I would like to get the native look of a window as a picture. I am pretty sure there is a function in MSDN, but I couldn’t find it after some googling.
Any ideas?
I am creating a form designer, and I would like to get the native look of a window as a picture. I am pretty sure there is a function in MSDN, but I couldn’t find it after some googling.
Any ideas?
You may just want to grab the screen picture
https://forum.xojo.com/12170-printwindow-api?search=bitblt
Thanks Michel, but is that how Xojo (and other IDEs) do it? Seems very hacky, and could cause many issues.
All depends what you need the picture for. If you need the picture to mimic a window for some reason, I would gather taking a shot once is all you need. Since the user could have set a theme, it may be impossible to use a pre-recorded picture. Yet, that would be the safest course.
I will leave you with your “hackish” comment, or what kind of issues you foresee. By definition, I consider any declare as “hackish”, since you bypass Xojo to tap in the lower level code, effectively hack the API. Bitblt is a Win32 API documented way of grabbing the screen, and as far as I know, a blank window cannot be generated without displaying it. So I do not quite see how one could get an image of an object that exists only on the screen. But I love to learn.
Maybe people at Xojo can tell you their secret, if they have one, as you seem to believe ?
Is it not far simpler, though, if you need a blank window, to simply pop up one ?
I was trying to reply to https://forum.xojo.com/12170-printwindow-api?search=bitblt
but could not do so no write a reply … was seen
I would like to capture the screen as an image (.png), like it is done with Mac or Linux in the link
I modified it like this but could not get the whole screen, any suggestions?
#If TargetWin32 Then
Declare Function GetDC Lib “User32” (HWND As Integer) As Integer
Declare Function BitBlt Lib “GDI32” (DCdest As Integer, xDest As Integer, yDest As Integer, nWidth As Integer, nHeight As Integer, _
DCdource As Integer, xSource As Integer, ySource As Integer, rasterOp As Integer) As Boolean
Declare Function ReleaseDC Lib “User32” (HWND As Integer, DC As Integer) As Integer
Const CAPTUREBLT = &h40000000
Const SRCCOPY = &HCC0020
Dim screenCap As New Picture(Screen(0).Width, Screen(0).Height, 32)
Dim ViewerDC as Integer = GetDC(TheControl.Handle)
Call BitBlt(screenCap.Graphics.Handle(1), 0, 0, Screen(0).Width , Screen(0).Height , ViewerDC, -2, -2, SRCCOPY or CAPTUREBLT)
Call ReleaseDC(TheControl.Handle, ViewerDC)
Return screenCap
#endif
Thanks
Lennox
[quote=159011:@Michel Bujardet]All depends what you need the picture for. If you need the picture to mimic a window for some reason, I would gather taking a shot once is all you need. Since the user could have set a theme, it may be impossible to use a pre-recorded picture. Yet, that would be the safest course.
I will leave you with your “hackish” comment, or what kind of issues you foresee. By definition, I consider any declare as “hackish”, since you bypass Xojo to tap in the lower level code, effectively hack the API. Bitblt is a Win32 API documented way of grabbing the screen, and as far as I know, a blank window cannot be generated without displaying it. So I do not quite see how one could get an image of an object that exists only on the screen. But I love to learn.
Maybe people at Xojo can tell you their secret, if they have one, as you seem to believe ?
Is it not far simpler, though, if you need a blank window, to simply pop up one ?[/quote]
I need the screenshot, cause my application has a form designer. I currently use a rectangle as the window, which is kinda ugly.
The Bitblt declare is hackish, because that means that I will have to 1) open the window, 2) immediately take a screenshot, 3) close the window. How is the user going to resize the window? Each little step will require a new screenshot (not to mention the new random window that pops up).
I could have a hidden window, and use a win32 api (wm_print, PrintWindow, etc) to draw the window into a picture (without the window showing). I still haven’t been able to use these apis successfully though.
Thanks Michel
[quote=159077:@Lennox Jacob]I was trying to reply to https://forum.xojo.com/12170-printwindow-api?search=bitblt
but could not do so no write a reply … was seen
I would like to capture the screen as an image (.png), like it is done with Mac or Linux in the link
I modified it like this but could not get the whole screen, any suggestions?
#If TargetWin32 Then
Declare Function GetDC Lib “User32” (HWND As Integer) As Integer
Declare Function BitBlt Lib “GDI32” (DCdest As Integer, xDest As Integer, yDest As Integer, nWidth As Integer, nHeight As Integer, _
DCdource As Integer, xSource As Integer, ySource As Integer, rasterOp As Integer) As Boolean
Declare Function ReleaseDC Lib “User32” (HWND As Integer, DC As Integer) As Integer
Const CAPTUREBLT = &h40000000
Const SRCCOPY = &HCC0020
Dim screenCap As New Picture(Screen(0).Width, Screen(0).Height, 32)
Dim ViewerDC as Integer = GetDC(TheControl.Handle)
Call BitBlt(screenCap.Graphics.Handle(1), 0, 0, Screen(0).Width , Screen(0).Height , ViewerDC, -2, -2, SRCCOPY or CAPTUREBLT)
Call ReleaseDC(TheControl.Handle, ViewerDC)
Return screenCap
#endif
Thanks
Lennox[/quote]
Hey man, download WFS. Add it to your project, and use the code below to get a screenshot of the window:
Dim p as Picture = GraphicsHelpersWFS.CaptureScreen(false)
[quote=159146:@Ashot Khachatryan]I need the screenshot, cause my application has a form designer. I currently use a rectangle as the window, which is kinda ugly.
The Bitblt declare is hackish, because that means that I will have to 1) open the window, 2) immediately take a screenshot, 3) close the window. How is the user going to resize the window? Each little step will require a new screenshot (not to mention the new random window that pops up).
I could have a hidden window, and use a win32 api (wm_print, PrintWindow, etc) to draw the window into a picture (without the window showing). I still haven’t been able to use these apis successfully though.
l[/quote]
Why can’t you simply use a window for your form designer ? Maybe a floating one ?
Or do like the Xojo IDE, draw the window yourself. I do not believe the window that shows at design time in the IDE is anything but a clever emulation. It has a Windows 7 look that never changes under Windows 8 or Windows 10 that have very different design, or comply to the current Windows theme. Also, look closely and you will notice that corners are in fact white, the rounded window picture sort of taking the eye out of it. Plus the window title font is not right, and the drawing of the controls on the right of the window is not standard. Yet, the illusion is often good enough.
Finally, I looked at PrintWindow(), and it does not seem that terrible. From what I read, the thorniest thing is creating a device context. Fortunately, there is already an example in WFS in HBITMAPFromPicture. But will it be able to manage without displaying all so briefly the window ?
[quote=159189:@Michel Bujardet]
Or do like the Xojo IDE, draw the window yourself. I do not believe the window that shows at design time in the IDE is anything but a clever emulation.[/quote]
We actually get the OS to draw it hence why it looks correct but it is just a picture in the editor
The gyrations needed to get the OS to draw it for us are quite involved
OK it works, thanks…
(I deleted my previous post indicating that it did not work).
Hey man, download WFS . Add it to your project, and use the code below to get a screenshot of the window:
Dim p as Picture = GraphicsHelpersWFS.CaptureScreen(false)
Lennox
[quote=159261:@Norman Palardy]We actually get the OS to draw it hence why it looks correct but it is just a picture in the editor
The gyrations needed to get the OS to draw it for us are quite involved[/quote]
Norman, I fail to see how the system can draw the standard window. Here is the look of he IDE versus Win 8.1 and Win 10 :
The least one would expect from the system is to use the default window style, if not apply the theme colors.
As for the OP need, frankly, given the relatively crude design of Windows windows, it seems relatively simple to emulate, even with standard rectangles, and even resizable…
[quote=159189:@Michel Bujardet]Why can’t you simply use a window for your form designer ? Maybe a floating one ?
[/quote]
I don’t like floating windows in an IDE. Complicates things.
Also my current form designer, is canvas based, which gives me complete control.
[quote=159189:@Michel Bujardet]
Or do like the Xojo IDE, draw the window yourself. I do not believe the window that shows at design time in the IDE is anything but a clever emulation. It has a Windows 7 look that never changes under Windows 8 or Windows 10 that have very different design, or comply to the current Windows theme. Also, look closely and you will notice that corners are in fact white, the rounded window picture sort of taking the eye out of it. Plus the window title font is not right, and the drawing of the controls on the right of the window is not standard. Yet, the illusion is often good enough.
Finally, I looked at PrintWindow(), and it does not seem that terrible. From what I read, the thorniest thing is creating a device context. Fortunately, there is already an example in WFS in HBITMAPFromPicture. But will it be able to manage without displaying all so briefly the window ?[/quote]
If you try Delphi, or other IDEs on Win8, they also have the Vista, Win7 look. The title on Xojo is most probably just a DrawString (not sure why though, probably has something to do with the way Xojo devs did it).
I tried PrintWindow, and coulnd’t make it work unfortunately. Tried creating a valid device context too, but all I get is a blank white picture.
[quote=159261:@Norman Palardy]We actually get the OS to draw it hence why it looks correct but it is just a picture in the editor
The gyrations needed to get the OS to draw it for us are quite involved[/quote]
Hmmm that’s discouraging. Any hints? (if you can share of course …)
[quote=159299:@Michel Bujardet]Norman, I fail to see how the system can draw the standard window. Here is the look of he IDE versus Win 8.1 and Win 10 :
The least one would expect from the system is to use the default window style, if not apply the theme colors.
As for the OP need, frankly, given the relatively crude design of Windows windows, it seems relatively simple to emulate, even with standard rectangles, and even resizable…[/quote]
It is weird, but that’s the default window in many cases. Check the following examples (I am on Windows 8)
Example 1: MDI Window in a Xojo/RS example
Example 2: Visual Studio 2012 Form Designer
Just for fun, I very quickly built a window mockup. I even added a resize cursor in the lower right corner, but did not feel like adding the necessary code in MouseDrag to actually manage the resize. It is fairly simple, though.
You will see that within reasonable proportions, the mockup does resize in the IDE without much efforts.
https://dl.dropboxusercontent.com/u/17407375/mywindow.zip
Of course, that can still be refined with gradients and light effects. But once again, it is a small prototype.
PS : I lifted the buttons images from the IDE, but if necessary, One can get the originals from a Windows 7 screen.
[quote=159741:@Michel Bujardet]Just for fun, I very quickly built a window mockup. I even added a resize cursor in the lower right corner, but did not feel like adding the necessary code in MouseDrag to actually manage the resize. It is fairly simple, though.
You will see that within reasonable proportions, the mockup does resize in the IDE without much efforts.
https://dl.dropboxusercontent.com/u/17407375/mywindow.zip
Of course, that can still be refined with gradients and light effects. But once again, it is a small prototype.
PS : I lifted the buttons images from the IDE, but if necessary, One can get the originals from a Windows 7 screen.[/quote]
Thank you for this, it looks great! I will probably use something like this!