|
Hi Eslam,
Thanks for the pointers ... What I've come up with is the following:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.Windows.RoutedEventArgs) _
Handles Button1.Click
Dim CaptureForm As New TestForm
CaptureForm.Left = -999
CaptureForm.Show()
Image1.Source = CaptureFrameworkElement(CaptureForm)
CaptureForm.Close()
CaptureForm = Nothing
End Sub
Function CaptureFrameworkElement(ByVal fe As FrameworkElement) As BitmapSource
Dim renderBitmap As New RenderTargetBitmap(CInt(Math.Ceiling(fe.ActualWidth)), _
CInt(Math.Ceiling(fe.ActualHeight)), _
96, 96, PixelFormats.Pbgra32)
Dim dv As New DrawingVisual()
Using dc As DrawingContext = CType(dv.RenderOpen(), DrawingContext)
Dim visualBrush As New VisualBrush(fe)
Dim rect1 As New Rect(New System.Windows.Point(0, 0),_
VisualTreeHelper.GetDescendantBounds(fe).Size)
dc.DrawRectangle(visualBrush, Nothing, rect1)
End Using
renderBitmap.Render(dv)
Return CType(renderBitmap, BitmapSource)
End Function
This will let you capture any visual element. The only issue I have now is that only the contents of the form are captured and not the non-client area.
Any thoughts?
|
|
|
|
|
GraGra_33 wrote: The only issue I have now is that only the contents of the form are captured and not the non-client area.
I'm thinking about accessing the Window as a Form, and call the DrawToBitmap. But I couldn't get it to work now and I don't know if it's possible. I have an exam tomorrow so I can't investigate it further right now. Maybe if there is some Win32 API that does take a snapshot of a window by handle, since we can access the handle.
' the code is not tested
Dim hlper As New System.Windows.Interop.WindowInteropHelper(Me)
Dim windowAsForm = System.Windows.Forms.Form.FromHandle(hlper.Handle) ' returns null, don't know why
Dim w = windowAsForm.Size.Width
Dim h = windowAsForm.Size.Height
Dim bitmap As New System.Drawing.Bitmap(w, h)
windowAsForm.DrawToBitmap(bitmap, New System.Drawing.Rectangle(0, 0, w, h))
' code from <a href="http://dedjo.blogspot.com/2007/05/how-to-use-systemdrawingbitmap-hbitmap.html">here</a>[<a href="http://dedjo.blogspot.com/2007/05/how-to-use-systemdrawingbitmap-hbitmap.html" target="_blank" title="New Window">^</a>], i didn't test it
Return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), _
IntPtr.Zero, _
Int32Rect.Empty, _
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions())
Eslam Afifi
modified on Wednesday, April 8, 2009 2:31 PM
|
|
|
|
|
Thanks Eslam,
I was hoping for a more WPF native solution rather than a hack... Will try tonight...
|
|
|
|
|
You're welcome.
So, how did it go? Did it work? Could you find any WPF method? I'm also wondering, why would you want to show non-client area in the thumbnails?
Eslam Afifi
|
|
|
|
|
I couldn't get around your problem... So I tried something different but not getting an image...
Dim hlper As New System.Windows.Interop.WindowInteropHelper(Me)
Dim gr As System.Drawing.Graphics = System.Drawing.Graphics.FromHwnd(hlper.Handle)
Dim ms As New MemoryStream
Dim bmp As System.Drawing.Bitmap = New System.Drawing.Bitmap(gr.VisibleClipBounds.Width, gr.VisibleClipBounds.Height, gr)
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim bImg As System.Windows.Media.Imaging.BitmapImage = New System.Windows.Media.Imaging.BitmapImage()
bImg.BeginInit()
bImg.StreamSource = New MemoryStream(ms.ToArray())
bImg.EndInit()
Return bImg
Any thoughts?
PS: I'm running in fullscreen mode and want preview and open window thumbnails as navigational tools... 
|
|
|
|
|
This won't work.
GraGra_33 wrote: Dim gr As System.Drawing.Graphics = System.Drawing.Graphics.FromHwnd(hlper.Handle)
A Graphics object is just a drawer.
GraGra_33 wrote: Dim bmp As System.Drawing.Bitmap = New System.Drawing.Bitmap(gr.VisibleClipBounds.Width, gr.VisibleClipBounds.Height, gr)
It takes only the resolution from the Graphics object.
I can't think of any other ideas. I see no reason why you would want to draw the non-client area! Maybe you should rethink why you would need the non-client area.
Eslam Afifi
|
|
|
|
|
Thanks for trying...
I haven't done GDI+ programming for a long time ... so am a bit rusty...
Why non-client area? As previously mentioned... I guess, until such time as I work it out, I'll fudge it until then ...
Anyone else with ideas? 
|
|
|
|
|
I tried sending WM_PAINT to the window but I only got the border without the content. Looks like WPF windows do not respond to WM_PAINT properly and there is no built-in method to draw non-client area. Try to get the non-client area and the client area and compose into a single bitmap. Or maybe you should look into this DWM Thumbnail Overview[^].
Eslam Afifi
|
|
|
|
|
Eslam Afifi wrote: I tried sending WM_PAINT to the window but I only got the border without the content.
What I do know is that WPF & GDI+ work in two seperate worlds... WPF draws in DirectX space...
I'd be interested in looking at it. I've got the code to capture the elements and you've got the code to capture the non-client area. Tying the two techniques together is a near enough hack to solve my problem.
Would you mind?
Does someone else have a cleaner way of doing it?
|
|
|
|
|
Private Const WM_PRINT As Integer = &H317
Private Const PRF_NON_CLIENT As Integer = &H2
Private Const PRF_CLIENT As Integer = &H4
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageW" (ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As Integer
Public Sub DrawToBitmap(ByVal hWnd As IntPtr, ByVal bitmap As System.Drawing.Bitmap, _
ByVal targetBounds As System.Drawing.Rectangle)
If (bitmap Is Nothing) Then Throw New ArgumentNullException("bitmap")
If (((targetBounds.Width <= 0) OrElse (targetBounds.Height <= 0)) _
OrElse ((targetBounds.X < 0) OrElse (targetBounds.Y < 0))) Then _
Throw New ArgumentException("targetBounds")
Using graphics = System.Drawing.Graphics.FromImage(bitmap)
Dim hDC = graphics.GetHdc()
SendMessage(hWnd, WM_PRINT, hDC.ToInt32(), PRF_CLIENT + PRF_NON_CLIENT)
graphics.ReleaseHdc(hDC)
End Using
End Sub
But you'll have to get the exact width and height of the window in case the window is maximized.
Althought WPF uses DirectX, I think they could have made WM_Print work by composing the client and non-client bitmaps the same way you would do with the code.
Eslam Afifi
|
|
|
|
|
Hello Team,
Need an urgent help. Requirement seems simple. But me new to WPF.
Say I have three PNG files displayed with Close,Minimise and Maximise buttons for each PNG. If one of the PNG is closed, the other two should resize and occupy the space.
Please assistance ASAP.
Thanks in advance
Newtodev
|
|
|
|
|
Are there any issues with using a WPF Browser Application with WCF as I was reading something about issues with WSDualHttpBinding. If this is the case is the best way around it to have use BasicHttpBinding or WSHttpBinding and don't use callbacks.
Cheers for your view / help with this.
Some people are like slinky's... They're not really good for anything but they bring a smile to your face when pushed down the stairs
|
|
|
|
|
Hello guys! I need to have different context menus in my datagrid - one for its header and one for rows of a grid. So I'm handling MouseClick event and than I need to evaluate if the underlying object for mouse cursor is Datagrid's header. Can you explain me how can I make this? The thing that I can't understand is that neither of DataGrid's and DataGridColumn's hierarchy of objects contain DataGridColumnHeader object or any reference to it. But in virtual tree if I get textblock that is located in header and contains column header's text and then get it parent container, I'll get DatagridColumnHeader object.
Any help is appreciated. Thanks in advance!
|
|
|
|
|
You might have better luck getting a good answer over on the codeplex forum.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
How to deploy Silverlight application on IIS server?
|
|
|
|
|
Silverlight is a client-side technology - deploying to a server is
pretty much as simple as copying the xap file (and any related files) to
a folder accessible by the web server.
Do you have a more specific question?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Please Give some easiest step to deploy the silver light project
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
I am using webservice and webreference in my project.
When i deploy and run the project it runs fine but it gives error where i called by the web service.
Thanks in advance.
|
|
|
|
|
I assume you are not pointing to localhost and you are using WCF services.
Probably you will have to create a host factory (that happened to me on the shared hosting where I have my app:
public class MyServiceHostFactory : MyServiceHostFactory
{
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
// Specify the exact URL of your web service
Uri webServiceAddress = new Uri("http://www.mysite.com/myservice.svc");
ServiceHost webServiceHost = new ServiceHost(serviceType, webServiceAddress);
return webServiceHost;
}
How to use it, in the svc header:
<%@ ServiceHost Language="C#" Service="MyService" CodeBehind="MyService.svc.cs" Factory="MyServiceHostFactory"%>
In a separated post I send you trouble shooting links.
HTH
Braulio
/// -------------------------
Braulio Díez
DBSchemaEditor.com
Free Silverlight based DB Schema Modeling Tool
/// -------------------------
|
|
|
|
|
|
right click on server side application in your visual studio and click publish
then in your IIS server you create a virtual folder and give it the path of your deploy application.

|
|
|
|
|
Have anyone used Deepearth in Silverlight? If so, can you please give some instructions on how to show addresses in Deepearth?
Thanks,
Sam
|
|
|
|
|
|
Hi
I want to create a listbox or listview displaying various furniture parts such as "table leg" or "table top", and then I want to be able to click on these items, and then drag them onto a viewport, but soon as my mouse pointer enters the viewport, the application should generate a 3D model of a table leg or table top, and fix the model in place as soon as I release the mouse button. Similar to how MS Visio works.
Would this be possible? Any help will be appreciated!
|
|
|
|
|