Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SendKeys Ctrl+Alt+PrintScrn 7

Status
Not open for further replies.

aarondewberry

IS-IT--Management
Jul 20, 2005
148
0
0
GB
Hi all, I am trying to replicate pushing Ctrl+Alt+PrintScrn at the same time to take a snapshot of my active window.
I'm not sure why my code isn't working. I have used the help and logic would say (not that i'm very logical) that it should be correct.

Code:
SendKeys "(^%{PRTSC})"

Is there something obvious i'm missing or....?
 
Just had a look at the SendKeys documentation and at the bottom there's a note stating that it can't send the Print Screen key ({PRTSC}) to any application.

Hope this helps (though it's probably not what you wanted to hear).

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Just for info I have got some code that does take a screenshot and pastes it to the clipboard.

Just call the Screendump() function to run or use ?ScreenDump() in the Immediate window.

Code:
Option Compare Database
Option Explicit

Type RECT_Type

   left As Long
   top As Long
   right As Long
   bottom As Long

End Type

'The following declare statements are case sensitive.

Declare Function GetActiveWindow Lib "User32" () As Long
Declare Function GetDesktopWindow Lib "User32" () As Long
Declare Sub GetWindowRect Lib "User32" (ByVal Hwnd As Long, _
                                    lpRect As RECT_Type)
Declare Function GetDC Lib "User32" (ByVal Hwnd As Long) As Long
Declare Function CreateCompatibleDC Lib "Gdi32" (ByVal hdc As Long) _
                                    As Long
Declare Function CreateCompatibleBitmap Lib "Gdi32" (ByVal hdc _
                                    As Long, ByVal nWidth As Long, _
                                    ByVal nHeight As Long) As Long
Declare Function SelectObject Lib "Gdi32" (ByVal hdc As Long, _
                                    ByVal hObject As Long) As Long
Declare Function BitBlt Lib "Gdi32" (ByVal hDestDC As Long, _
                                    ByVal X As Long, ByVal Y _
                                    As Long, ByVal nWidth As Long, _
                                    ByVal nHeight As Long, _
                                    ByVal hSrcDC As Long, _
                                    ByVal XSrc As Long, _
                                    ByVal YSrc As Long, _
                                    ByVal dwRop As Long) As Long
Declare Function OpenClipboard Lib "User32" (ByVal Hwnd As Long) As Long
Declare Function EmptyClipboard Lib "User32" () As Long
Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, _
                                    ByVal hMem As Long) As Long
Declare Function CloseClipboard Lib "User32" () As Long
Declare Function ReleaseDC Lib "User32" (ByVal Hwnd As Long, _
                                    ByVal hdc As Long) As Long
Declare Function DeleteDC Lib "Gdi32" (ByVal hdc As Long) As Long

Global Const SRCCOPY = &HCC0020
Global Const CF_BITMAP = 2

Function ScreenDump()
   Dim AccessHwnd As Long, DeskHwnd As Long
   Dim hdc As Long
   Dim hdcMem As Long
   Dim rect As RECT_Type
   Dim junk As Long
   Dim fwidth As Long, fheight As Long
   Dim hBitmap As Long

   DoCmd.Hourglass True

   '---------------------------------------------------
   ' Get window handle to Windows and Microsoft Access
   '---------------------------------------------------
   DeskHwnd = GetDesktopWindow()
   AccessHwnd = GetActiveWindow()

   '---------------------------------------------------
   ' Get screen coordinates of Microsoft Access
   '---------------------------------------------------
   Call GetWindowRect(AccessHwnd, rect)
   fwidth = rect.right - rect.left
   fheight = rect.bottom - rect.top

   '---------------------------------------------------
   ' Get the device context of Desktop and allocate memory
   '---------------------------------------------------
   hdc = GetDC(DeskHwnd)
   hdcMem = CreateCompatibleDC(hdc)
   hBitmap = CreateCompatibleBitmap(hdc, fwidth, fheight)

   If hBitmap <> 0 Then
      junk = SelectObject(hdcMem, hBitmap)

      '---------------------------------------------
      ' Copy the Desktop bitmap to memory location
      ' based on Microsoft Access coordinates.
      '---------------------------------------------
      junk = BitBlt(hdcMem, 0, 0, fwidth, fheight, hdc, rect.left, _
                    rect.top, SRCCOPY)

      '---------------------------------------------
      ' Set up the Clipboard and copy bitmap
      '---------------------------------------------
      junk = OpenClipboard(DeskHwnd)
      junk = EmptyClipboard()
      junk = SetClipboardData(CF_BITMAP, hBitmap)
      junk = CloseClipboard()
   End If

   '---------------------------------------------
   ' Clean up handles
   '---------------------------------------------
   junk = DeleteDC(hdcMem)
   junk = ReleaseDC(DeskHwnd, hdc)

   DoCmd.Hourglass False

End Function
 
Aaron, thanks for posting your solution. It worked a charm!

"Talent hits a target no one else can hit; Genius hits a target no one else can see." --- Arthur Schopenhauer
 
Yes, thanks for giving your solution after finding it. That's A LOT of code to replicate "Print Screen!"

I'm certain this will be useful in the future.
 
Hi Arron
I pasted your code in a new module and received an error Compile Error: Internal error. Do I have to have a particular reference listed? Also, is it possible to have it go to a printer instead of the clipboard? I am dealing with very novice computer users.

Thanks
lhuffst
 
Looks like a pretty neat deal. Good find!

--

"If to err is human, then I must be some kind of human!" -Me
 
lhuffst - I have attempted to duplicate your compile error. When I put Aaron's code into a module, it compiled just fine. When I tried to put code behind a form, it would not compile. But you specifically mention putting it in a module, so that must not be the problem.
Is there any more to the error message beyond "Compile Error: Internal error" ???
BTW I am running Access 2007, but have used this on Access XP previously.
NorthNone (a grateful user of Aaron's original code posting)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top