@@ -42,6 +42,8 @@ Option Private Module
4242 Private Declare PtrSafe Function RemoveClipboardFormatListener Lib "user32 .dll " (ByVal hWnd As LongPtr ) As Long
4343 Private Declare PtrSafe Function GetForegroundWindow Lib "user32 " () As LongPtr
4444
45+ Declare PtrSafe Function GetTickCount Lib "kernel32 " Alias "GetTickCount64 " () As LongLong
46+
4547#Else
4648
4749 Private Declare Function SetWindowLong Lib "user32 " Alias "SetWindowLongA " (ByVal hwnd As Long , ByVal nIndex As Long , ByVal dwNewLong As Long ) As Long
@@ -52,6 +54,7 @@ Option Private Module
5254 Private Declare Function AddClipboardFormatListener Lib "user32 .dll " (ByVal hwnd As Long ) As Long
5355 Private Declare Function RemoveClipboardFormatListener Lib "user32 .dll " (ByVal hwnd As Long ) As Long
5456 Private Declare Function GetForegroundWindow Lib "user32 " () As Long
57+ Private Declare Function GetTickCount Lib "kernel32 " () As Long
5558
5659#End If
5760
@@ -75,27 +78,31 @@ Private mlngBlankNum As Long
7578Private mblnPageBreakEnable As Boolean
7679Private mlngPageBreakNun As Long
7780
81+ Private mlngSleep As Long
82+
7883Public tray As TaskTrayView
7984
8085Private WS As Worksheet
81- Sub GetScreenSetting (ByRef blnZoomEnable As Boolean , ByRef lngZoomNum As Long , ByRef blnSave As Boolean , ByRef lngBlankNum As Long , ByRef blnPageBreakEnable As Boolean , ByRef lngPageBreakNun As Long )
86+ Sub GetScreenSetting (ByRef blnZoomEnable As Boolean , ByRef lngZoomNum As Long , ByRef blnSave As Boolean , ByRef lngBlankNum As Long , ByRef blnPageBreakEnable As Boolean , ByRef lngPageBreakNun As Long , ByRef lngSleep As Long )
8287
8388 blnZoomEnable = GetSetting(C_TITLE, "ScreenShot" , "ZoomEnable" , False )
8489 lngZoomNum = GetSetting(C_TITLE, "ScreenShot" , "ZoomNum" , 100 )
8590 blnSave = GetSetting(C_TITLE, "ScreenShot" , "Save" , False )
8691 lngBlankNum = GetSetting(C_TITLE, "ScreenShot" , "BlankNum" , 2 )
8792 blnPageBreakEnable = GetSetting(C_TITLE, "ScreenShot" , "PageBreakEnable" , False )
8893 lngPageBreakNun = GetSetting(C_TITLE, "ScreenShot" , "PageBreakNum" , 1 )
94+ lngSleep = GetSetting(C_TITLE, "ScreenShot" , "Sleep" , 500 )
8995
9096End Sub
91- Sub SetScreenSetting (ByRef blnZoomEnable As Boolean , ByRef lngZoomNum As Long , ByRef blnSave As Boolean , ByRef lngBlankNum As Long , ByRef blnPageBreakEnable As Boolean , ByRef lngPageBreakNun As Long )
97+ Sub SetScreenSetting (ByRef blnZoomEnable As Boolean , ByRef lngZoomNum As Long , ByRef blnSave As Boolean , ByRef lngBlankNum As Long , ByRef blnPageBreakEnable As Boolean , ByRef lngPageBreakNun As Long , ByRef lngSleep As Long )
9298
9399 Call SaveSetting (C_TITLE, "ScreenShot" , "ZoomEnable" , blnZoomEnable)
94100 Call SaveSetting (C_TITLE, "ScreenShot" , "ZoomNum" , lngZoomNum)
95101 Call SaveSetting (C_TITLE, "ScreenShot" , "Save" , blnSave)
96102 Call SaveSetting (C_TITLE, "ScreenShot" , "BlankNum" , lngBlankNum)
97103 Call SaveSetting (C_TITLE, "ScreenShot" , "PageBreakEnable" , blnPageBreakEnable)
98104 Call SaveSetting (C_TITLE, "ScreenShot" , "PageBreakNum" , lngPageBreakNun)
105+ Call SaveSetting (C_TITLE, "ScreenShot" , "ScreenShot" , lngSleep)
99106
100107End Sub
101108Public Sub StartScreenShot ()
@@ -106,15 +113,17 @@ Public Sub StartScreenShot()
106113 Dim lngBlankNum As Long
107114 Dim blnPageBreakEnable As Boolean
108115 Dim lngPageBreakNun As Long
116+ Dim lngSleep As Long
109117
110- GetScreenSetting blnZoomEnable, lngZoomNum, blnSave, lngBlankNum, blnPageBreakEnable, lngPageBreakNun
118+ GetScreenSetting blnZoomEnable, lngZoomNum, blnSave, lngBlankNum, blnPageBreakEnable, lngPageBreakNun, lngSleep
111119
112120 mblnZoomEnable = blnZoomEnable
113121 mlngZoomNum = lngZoomNum
114122 mblnSave = blnSave
115123 mlngBlankNum = lngBlankNum
116124 mblnPageBreakEnable = blnPageBreakEnable
117125 mlngPageBreakNun = lngPageBreakNun
126+ mlngSleep = lngSleep
118127 Set WS = ActiveSheet
119128
120129 mSetHWnd = frmScreenShot.hWnd
@@ -153,15 +162,23 @@ End Sub
153162Public Function WndProc (ByVal hWnd As LongPtr , ByVal uMsg As Long , ByVal wParam As LongPtr , ByVal lParam As LongPtr ) As LongPtr
154163
155164 Static bolWndProcCheck As Boolean
165+ Static t As LongLong
156166
157167 If Not bolWndProcCheck Then
158168
159169 bolWndProcCheck = True
160170
161171 Select Case uMsg
162172 Case WM_CLIPBOARDUPDATE
163- If IsClipboardFormatAvailable(CF_BITMAP) <> 0 And GetForegroundWindow() <> Application.hWnd Then
164- Application.OnTime Now, MacroHelper.BuildPath("pasteScreenShot" )
173+
174+ If t < GetTickCount() Then
175+
176+ t = GetTickCount() + mlngSleep
177+
178+ If IsClipboardFormatAvailable(CF_BITMAP) <> 0 And GetForegroundWindow() <> Application.hWnd Then
179+ Application.OnTime Now, MacroHelper.BuildPath("pasteScreenShot" )
180+ End If
181+
165182 End If
166183 End Select
167184
@@ -176,15 +193,24 @@ End Function
176193Public Function WndProc (ByVal hWnd As Long , ByVal uMsg As Long , ByVal wParam As Long , ByVal lParam As Long ) As Long
177194
178195 Static bolWndProcCheck As Boolean
196+ Static t As Long
197+
179198
180199 If Not bolWndProcCheck Then
181200
182201 bolWndProcCheck = True
183202
184203 Select Case uMsg
185204 Case WM_CLIPBOARDUPDATE
186- If IsClipboardFormatAvailable(CF_BITMAP) <> 0 And GetForegroundWindow() <> Application.hWnd Then
187- Application.OnTime Now, MacroHelper.BuildPath("pasteScreenShot" )
205+
206+ If t < GetTickCount() Then
207+
208+ t = GetTickCount() + mlngSleep
209+
210+ If IsClipboardFormatAvailable(CF_BITMAP) <> 0 And GetForegroundWindow() <> Application.hWnd Then
211+ Application.OnTime Now, MacroHelper.BuildPath("pasteScreenShot" )
212+ End If
213+
188214 End If
189215 End Select
190216
@@ -204,6 +230,8 @@ Public Sub pasteScreenShot()
204230 If WS Is Nothing Then
205231 tray.ShowBalloon "貼りつけるシートが見つかりません。コピー失敗しました"
206232 Else
233+
234+ Sleep mlngSleep
207235
208236 '画像を張付
209237 WS.Paste
0 commit comments