How to grab a screen shot with "Tool Tips" in VB.Net?

G

gregory_may

Is there a way to grab a "Screen Shot" that includes "Tool Tips"? I saw
this code someplace, cant remember where. But it doesnt grab "Tool Tips".
Is there a better way to do this in .net?
Thanks!



Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal
lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As
String, ByVal lpInitData As String) As Integer

Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As
Integer) As Integer

Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As
Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer

Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps"
(ByVal hdc As Integer, ByVal nIndex As Integer) As Integer

Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer,
ByVal hObject As Integer) As Integer

Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal
srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As
Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As
Integer, ByVal op As Integer) As Integer

Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As
Integer

Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As
Integer

Const SRCCOPY As Integer = &HCC0020

Private oBackground As System.Drawing.Bitmap

Private FW, FH As Integer



Public Sub CaptureScreen()

Dim hSDC, hMDC As Integer

Dim hBMP, hBMPOld As Integer

Dim r As Integer



hSDC = CreateDC("DISPLAY", "", "", "")

hMDC = CreateCompatibleDC(hSDC)

FW = GetDeviceCaps(hSDC, 8)

FH = GetDeviceCaps(hSDC, 10)

hBMP = CreateCompatibleBitmap(hSDC, FW, FH)

hBMPOld = SelectObject(hMDC, hBMP)

r = BitBlt(hMDC, 0, 0, FW, FH, hSDC, 0, 0, 13369376)

hBMP = SelectObject(hMDC, hBMPOld)

r = DeleteDC(hSDC)

r = DeleteDC(hMDC)

oBackground = System.Drawing.Image.FromHbitmap(New IntPtr(hBMP))

DeleteObject(hBMP)

DeleteObject(hBMPOld)
 
G

Gary Chang

Hi gregory_may,

Thanks for using Microsoft MSDN Managed Newsgroup.

Currently I am looking for somebody who could help you on it. We will reply
here with more information as soon as possible.
If you have any more concerns on it, please feel free to post here.


Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
G

gregory_may

Thanks Gary:

This code below also doesnt Grab the "Mouse". I need code that that can
grab a screen shot including the "mouse" "Cursors" & "tool tips".

Thanks for your help!
 
T

Tian Min Huang

Hello Gregory,

Thanks for your post. As I understand, the problem you are facing is to get
a screen shot with ToolTips and Cursor. Please correct me if there is any
misunderstanding. I'd like to share the following information with you:

1. Based on my experience and research, we are able to grab a screen shot
with "Tool Tips". With a ToolTip window open, you can simply press the "Pr
Scrn" (print screen key in keyboard), paste the screen shot to Paint.exe,
and you will see the ToolTip. You may perform some actions (say,
moving/clicking the mouse), which will disable the ToolTip, in order to
trigger your ScreenShot function, I believe that's the reason why the
ToolTip is not shown in your screen shot.

To work around the problem, you can use keyboard message to start the
ScreenShot function.

If it's system-wide, that is, you need to grab screen shot when your VB
.NET application is not active, you will need to call SetWindowsHookEx to
install a global hook to monitor keyborad message for grabbing a screen
shot. We have to use Visual C++ to create a native system-wide Hook DLL,
because a global hook must have a native dynamic-link library (DLL) export
to inject itself in another process that requires a valid, consistent
function to call into. This requires a DLL export, which .NET Framework
does not support. Managed code has no concept of a consistent value for a
function pointer because these function pointers are proxies that are built
dynamically. I believe the following MSDN articles are helpful:

HOW TO: Set a Windows Hook in Visual C# .NET
http://support.microsoft.com/?kbid=318804

SetWindowsHookEx
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui
/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindows
hookex.asp

Hooks
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui
/windowsuserinterface

2. As far as know, it's by design that cursor is excluded from the screen
shot. You may have to get the cursor information and add it to the bitmap
of screenshot manually.

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

gregory_may

Thanis Tain for your reply.

I am willing to try your solution, but I have a few concerns:
1) I would like to leave the clip board alone. Or restore it to its
previous state prior to grabbing the screen.
2) I have a performance concern. I would like to be able to grab up to
30 Screen Shots/Second if possible.

If I grab the screen & restore the clipboard, it seems my performance would
not be very good. Are there any other options for this? I was hoping maybe
a GDI call? I have tested the GDI Code below and it seems to give very good
performance. I can consistently get 30 Frames/Second (I just need the Mouse
& cursor & tool tips added to this). Maybe this question fits better in a
different group?

g.


Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal
lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As
String, ByVal lpInitData As String) As Integer

Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As
Integer) As Integer

Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As
Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer

Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps"
(ByVal hdc As Integer, ByVal nIndex As Integer) As Integer

Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer,
ByVal hObject As Integer) As Integer

Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal
srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As
Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As
Integer, ByVal op As Integer) As Integer

Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As
Integer

Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As
Integer

Const SRCCOPY As Integer = &HCC0020

Private oBackground As System.Drawing.Bitmap

Private FW, FH As Integer



Public Sub CaptureScreen()

Dim hSDC, hMDC As Integer

Dim hBMP, hBMPOld As Integer

Dim r As Integer

Try

hSDC = CreateDC("DISPLAY", "", "", "")

hMDC = CreateCompatibleDC(hSDC)

FW = GetDeviceCaps(hSDC, 8)

FH = GetDeviceCaps(hSDC, 10)

hBMP = CreateCompatibleBitmap(hSDC, FW, FH)

hBMPOld = SelectObject(hMDC, hBMP)

r = BitBlt(hMDC, 0, 0, FW, FH, hSDC, 0, 0, 13369376)

hBMP = SelectObject(hMDC, hBMPOld)

r = DeleteDC(hSDC)

r = DeleteDC(hMDC)

oBackground = System.Drawing.Image.FromHbitmap(New IntPtr(hBMP))

DeleteObject(hBMP)

DeleteObject(hBMPOld)

'Seems to be a memory hole in fromHbitmap ....

GC.Collect()

Catch ex As Exception

Debug.WriteLine("General GDI+ Error")

End Try

End Sub
 
G

gregory_may

Tain:

I went a head and posted a simlar message into the GDIWin32 group. If I get
anything, I will post it here.

g
 
T

Tian Min Huang

Hello Gregory,

Thanks for your feedback.
in?
Maybe you can manually draw the cursor to the bitmap by calling GDI Bitmap
functions say, SetPixel. Please refer to the MSDN article for a list of
Bitmap functions at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps
_87eb.asp.

I reviewed the article you mentioned in the previous post, based on my
experience, the DirectX method also cannot include the cursor.

In addition, I believe such questions are best suited for the
microsoft.public.win32.programmer.gdi which is also managed newsgroup.
Thanks for your understanding.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top