By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

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

P: n/a
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)


Jul 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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.
--------------------

Jul 21 '05 #2

P: n/a
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!

"Gary Chang" <v-******@online.microsoft.com> wrote in message
news:fG**************@cpmsftngxa07.phx.gbl...
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. --------------------

Jul 21 '05 #3

P: n/a
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/de...us/winui/winui
/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindows
hookex.asp

Hooks
http://msdn.microsoft.com/library/de...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.

Jul 21 '05 #4

P: n/a
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

"Tian Min Huang" <ti******@online.microsoft.com> wrote in message
news:Ln**************@cpmsftngxa07.phx.gbl...
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/de...us/winui/winui /windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindows hookex.asp

Hooks
http://msdn.microsoft.com/library/de...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.

Jul 21 '05 #5

P: n/a
Tain:

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

g
"gregory_may" <None> wrote in message
news:u0**************@TK2MSFTNGP12.phx.gbl...
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

"Tian Min Huang" <ti******@online.microsoft.com> wrote in message
news:Ln**************@cpmsftngxa07.phx.gbl...
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/de...us/winui/winui

/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindows
hookex.asp

Hooks

http://msdn.microsoft.com/library/de...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.


Jul 21 '05 #6

P: n/a
Tain:

Do you have any suggestions on how I could manually put the mouse pointer
in? If I use GDI or the Print Screen method, It looks like I will need to
put this in somehow.

Also found this article that goes through some of the Screen Capture
options:

http://www.geocities.com/krishnapg/screencap.html

Thanks!
g.

"Tian Min Huang" <ti******@online.microsoft.com> wrote in message
news:Ln**************@cpmsftngxa07.phx.gbl...
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/de...us/winui/winui /windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindows hookex.asp

Hooks
http://msdn.microsoft.com/library/de...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.

Jul 21 '05 #7

P: n/a
Hello Gregory,

Thanks for your feedback.
Do you have any suggestions on how I could manually put the mouse pointer

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/de...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.

Jul 21 '05 #8

P: n/a
This has been answered already over on microsoft.public.platformsdk.gdi:
http://groups.google.co.uk/groups?se...TNGP10.phx.gbl

Thanks everyone for your help!!!

g.

"gregory_may" <None> wrote in message
news:eA**************@TK2MSFTNGP10.phx.gbl...
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)

Jul 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.