標題:
[分享]
請問print screen的代碼如何寫?? (API運用)
[打印本頁]
作者:
Hsieh
時間:
2010-5-7 15:21
標題:
請問print screen的代碼如何寫?? (API運用)
我的要求是
打開檔案時即擷取一張屏幕圖
(截屏前須先將EXCEL視窗縮至最小以顯現要截屏的畫面)
並將其貼到A1
以後每小時擷取一張屏幕圖
(截屏前一樣須先將EXCEL視窗縮至最小
下張圖則貼至最適合之高度之行(緊接前一張圖)
例如第一張圖貼滿A1:K20
第二張貼到A21
不知如何達成
Emily_Li 回覆
Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal _
bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const VK_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12
Dim ws As Worksheet
Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Sub Print_Screen()
keybd_event VK_MENU, 0, 0, 0
DoEvents
keybd_event VK_SNAPSHOT, 0, 0, 0
DoEvents
keybd_event VK_SNAPSHOT, 0, VK_KEYUP, 0
DoEvents
keybd_event VK_MENU, 0, VK_KEYUP, 0
DoEvents
Set ws = ActiveSheet
ws.Paste Destination:=ws.Range("A1")
DoEvents
End Sub
複製代碼
結果與要求有落差內
這代碼是擷取excel的畫面
我的要求是
打開檔案時即擷取一張屏幕圖
(截屏前須先將EXCEL視窗縮至最小以顯現要截屏的畫面)
亦即是擷取另一個正於視窗最上層執行的程式畫面而不是擷取excel的畫面
並將其貼到A1
以後每小時擷取一張屏幕圖
(截屏前一樣須先將EXCEL視窗縮至最小)
不知能否改改
hsieh回覆:
依樣畫葫蘆
利用Emily_Li 前輩程式碼修改
Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal _
bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const VK_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12
Dim ws As Worksheet
Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Sub Print_Screen()
keybd_event VK_MENU, 0, 0, 0
DoEvents
Application.WindowState = xlMinimized
Application.Wait Now + TimeValue("00:00:05")
keybd_event VK_SNAPSHOT, 0, 0, 0
DoEvents
keybd_event VK_SNAPSHOT, 0, VK_KEYUP, 0
DoEvents
keybd_event VK_MENU, 0, VK_KEYUP, 0
DoEvents
Application.WindowState = xlMaximized
Set ws = ActiveWorkbook.ActiveSheet
ws.Paste Destination:=ws.Range("A1")
DoEvents
Application.OnTime Now + TimeValue("01:00:00"), "Print_Screen"
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)