I have a windows form Window that is being painted on top of by another process. If I try to copy the window image using PrintWindow or device context copy, only my window below shows up:
Window before it's painted on by another process:
Window after it's painted:
Window I get when I do PrintWindow or BitBlt:
Is it possible to read the window draw from the window directly without sending it the paint argument? Can I read it from the graphics card directly?
DirectX breaks the rules, you cannot make PrintWindow() work. Using Graphics.CopyFromScreen() doesn't work either, it has a critical bug that prevents you from passing the correct CopyPixelOperation value. One that was addressed in Windows 8 by Windows itself, you can't rely on it yet.
You'll need to fallback to BitBlt(). The critical option is CopyPixelOperation.CaptureBlt so that video overlays are included in the copy. You'll find the required code in this answer.
If I am correct you want to copy window that is rendered by some DirectX proccess?
You can do that but you need to understand that you can't copy memory from window directly because winows form doesn't have your image, it only have a placeholder for rendered image.
It is only a ilusion that image is rendered inside form.
What you need to do is to copy memory from graphic card but unfortunately I don't know how to do that.
Most simple idea is to get window screenshot like alt+print screen, remove the border and copy that image to your window.
Maybe it will help http://www.codeproject.com/Articles/274461/Very-fast-screen-capture-using-DirectX-in-Csharp
Dmitry is right.
You can only make a CopyFromScreen as he suggested:
Capture the Screen into a Bitmap
You can modify the source code to create a bitmap large as your window and copy only that part of screen
Related
I once wrote an app that could display photographs. I am trying to re-write it in Visual Studio with C# and give it new features. The application I am writing now does use scroll bars to facilitate viewing an over-sized image. The previous app would fill the form area with the image and you could drag and hold the mouse to move it about on the screen. If the image was bigger than the screen you'd simply move it about to view previously hidden areas. By making the form the same size as the image it was very elegant way of dealing with the 'problem' of viewing an image that is bigger than your screen dimensions.
The advantage of this over putting the image inside a statically re-sizable form with scroll-bars was that the image would fill the available screen space, and if the next image in the sequence (it is a browser that allows you to cycle through images) was small, the image app would only take up as much space as the image. You could easily move it to one side. You didn't have to manually resize the form that was displaying it to make room for other applications.
I am unable to implement the same feature in the new app because Visual Studio won't let me dynamically re-size the form to be taller or wider than the screen.
Does anyone know of a plugin or workaround to override this limitation?
I am open to suggestions to achieve the same goal, but I would still like to know if this limitation can be turned off, perhaps with a plugin or in code somehow. Below is a link to a video of the previous incarnation of the app, demonstrating the behavior I want to acheive by being able to set the form size larger than the screen dimensions...
Edit: A demo of the the previous application - and the behavior I want to implement...
http://youtu.be/J16EwuozvbQ
I think having a form bigger than the screen is not what you should search for. You can play with the position (top/left) coordination of the image on the form. You can have coordinates with minus values, so you will give the impression to the end user that he browse the image boundaries that's outside of the screen dimension.
Simply, you can create a Form with a PictureBox.
Then change the AutoScroll property of the Form (or the container of the PictureBox, if applicable) to true.
And then change the SizeMode property of the PictureBox to AutoSize.
You should end up with something like this:
I've created an WPF based application showing me thumbnails of external windows. As an example i pick up icq, firefox and some other windows, create thumbnails of these and render them onto my WPF based application.
That works fine already and looks like this:
http://img560.imageshack.us/img560/1170/oijoijio.jpg
(Just showing one thumbnail in here, but there will be multiple in future)
The WPF application will also contain some controls to actually select the windows being "thumbnailed" and a few others.
The next step and my actual question is about how i would redirect these content being rendered into a Bitmap instead of the "WPF window" itself.
Is there a way to accomblish that goal? All the windows content (WPF containers and the drawn thumbnails) need to be rendered into a bitmap which i can display in directx window being owned by a game.
I know that it is possible todo that somehow, as a programm called overwolf also uses WPF inside of their application. They actually install device inline detours to hook into the rendering process of the game, where they render their wpf content. I am not sure if they use some kind of bitmap they render in there, or if they directly render the wpf content onto the dx-surface somehow.
Other ideas besides the bitmap based style i plan to go for are welcome aswell!
Thanks for your reading until here, and another big hug for any answer :)
Any WPF Visual object can be rendered into a bitmap using RenderTargetBitmap.
Is this possible. I have three (3) windows:
Window1 - not active
Window2 - not active
Window3 - active
If I take the screenshot of the desktop I want Window3 to be hidden quietly. Provided the user is using Window3 the program must not in any way hide the windows like minimizing it or anything. In short, I need an unobtrusive way of hiding specific windows from desktop screenshot.
That's not going to be possible without quite a bit of work. The print screen functionality just copies the contents of the desktop DC to an image and places it on the keyboard. It doesn't actually re-render the whole desktop into a new DC. So there's no way that it can silently remove a particular window.
I suppose you could hook the print screen button (or the function, whatever it is) and allow it to create the image on the clipboard. Then your hook could read the location of the window in question from the desktop and clear out that area of the bitmap that's on the clipboard.
Your hook would do this:
call the normal print screen function
load image from clipboard
get location and size of Window3 from desktop
fill that rectangle in the image with black (or whatever)
put the modified image back on the clipboard
Assuming, of course, that you can hook the print screen function. I suspect it's possible, although I've never tried it.
I'm working on a c# wpf app in which I want a grid or rectangle to show the contents of a window in my application. It should be like a monitor which constantly shows what happens in the other window (video is being played in in it).
Is there a good way to capture the screen or some other option?
Thanks
You can take a look at the VisualBrush class - that might be able to handle what you want. I don't know if it can handle cloning video but this example shows it copying a static part of the screen.
OK, anyone can explain how Jing take screen shots with that overlay form? It appears that it take a full screen shot and records all visible window handles and let you select within the form a specific hwnd. could be true? if is, what are the big steps to achieve this? could be a simple picturebox or without a custom control i don't have a chance to freeze the screen while taking a screen shot?
Thank you!
I'm not familiar enough with Jing to know exactly what it uses. But there are two basic techniques. One is as you mention, capture the screen and display it in a topmost borderless form. The Vista/Win7 Snipping tool works that way. You'll find the code you need to get this started it in my answer in this thread.
The other, perhaps more likely to be used by Jing, is similar to what Spy++ does, allowing the user to move the mouse and draw a selection rectangle around the window. Its advantage is that it can deal with windows resizing or disappearing while you've got the tool running. You implement it by using a topmost form the size of the screen that has its TransparencyKey property set to the value of the BackColor. Fuchsia is a popular choice. You can draw on this form with the OnPaint() method, the drawing appears on top of all the windows. You'd need some P/Invoke (GetWindow) to iterate the underlying windows in their Z-order to know which window the user is pointing at. GetWindowRect() to get the window rectangle. Plus some hassle to deal with Aero lying about the border size.
You can find sample code to get you started on that technique in my answer in this thread.