R
Roy Soltoff
I have seen various methods of capturing the screen or a window in .Net, but
so far, code found can only capture a visible window. In VB6, I used a
technique from MSKB article Q194580 to do this using SendMessage. My need is
to be able to capture the image of the contents of all tabs in a tabstrip so
that I can pass them to a PrintPreview component. This allows me to provide
a facility where a user can selectively print any or all of the contents of
a multi-tab dialog. I have tried the following in DotNet (where TabPage2 is
not the visible tab):
Dim rv As Integer
Dim g As Graphics = dest.CreateGraphics
Dim hDc As System.IntPtr = g.GetHdc
Dim gs As Graphics = TabPage2.CreateGraphics
Dim shDc As System.IntPtr = gs.GetHdc
'BitBlt(hDc, 0, 0, TabPage2.Width, TabPage2.Height, shDc, 0, 0, SRCCOPY)
gs.ReleaseHdc(shDc)
gs.Dispose()
rv = SendMessage(TabPage2.Handle, WM_PAINT, hDc, 0)
rv = SendMessage(TabPage2.Handle, WM_PRINT, hDc, _
PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
g.ReleaseHdc(hDc)
g.Dispose()
I can confirm that the Paint event of TabPage2 is called. I even put in a
DrawLine API in the Paint handler to in fact draw a line to the graphics
device context. The attempt to capture the TabPage2 image does in fact draw
the line to the destination picturebox, but if the tabpage is not visible,
none of the controls are drawm. If I add the bitBlt API call as has been
suggested by many to capture the window, the destination picture box gets
the image of what is visible on the screen at the time of the capture (which
was TabPage1).
Is there any way to force the .Net core to paint the controls onto the
device context pased so that the hidden area of the control can get
captured? This seems like such a useful facility.
Additionally, the PrintWindow GDI API has been suggsted, but it was not put
into the OS until XP.
so far, code found can only capture a visible window. In VB6, I used a
technique from MSKB article Q194580 to do this using SendMessage. My need is
to be able to capture the image of the contents of all tabs in a tabstrip so
that I can pass them to a PrintPreview component. This allows me to provide
a facility where a user can selectively print any or all of the contents of
a multi-tab dialog. I have tried the following in DotNet (where TabPage2 is
not the visible tab):
Dim rv As Integer
Dim g As Graphics = dest.CreateGraphics
Dim hDc As System.IntPtr = g.GetHdc
Dim gs As Graphics = TabPage2.CreateGraphics
Dim shDc As System.IntPtr = gs.GetHdc
'BitBlt(hDc, 0, 0, TabPage2.Width, TabPage2.Height, shDc, 0, 0, SRCCOPY)
gs.ReleaseHdc(shDc)
gs.Dispose()
rv = SendMessage(TabPage2.Handle, WM_PAINT, hDc, 0)
rv = SendMessage(TabPage2.Handle, WM_PRINT, hDc, _
PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
g.ReleaseHdc(hDc)
g.Dispose()
I can confirm that the Paint event of TabPage2 is called. I even put in a
DrawLine API in the Paint handler to in fact draw a line to the graphics
device context. The attempt to capture the TabPage2 image does in fact draw
the line to the destination picturebox, but if the tabpage is not visible,
none of the controls are drawm. If I add the bitBlt API call as has been
suggested by many to capture the window, the destination picture box gets
the image of what is visible on the screen at the time of the capture (which
was TabPage1).
Is there any way to force the .Net core to paint the controls onto the
device context pased so that the hidden area of the control can get
captured? This seems like such a useful facility.
Additionally, the PrintWindow GDI API has been suggsted, but it was not put
into the OS until XP.