|
■No99458 (ぜん さん) に返信 > しかし、Chrome以外のウインドウだとうまくいくのですが > Chromeだけは、画像が真っ暗になってしまいます。
対象のウィンドウは "Chrome_WidgetWin_1" クラスですか?
■No99466 (ぜん さん) に返信 > また、DWM Thumbnail APIでもできそうなことが書かれてあるのですが > これはどうやって使えば良いですか? > 検索してもいまいち使い方が分かりませんでした。 そうですか? 使い方の説明なら、すぐに出てきましたよ。 使う関数もそう多くは無いですし。 https://docs.microsoft.com/ja-jp/windows/win32/dwm/thumbnail-ovw
Option Strict On Imports System.Runtime.InteropServices
Public Class Form1 Private ThumbnailId As IntPtr = IntPtr.Zero Private Function GetChromeHandle() As IntPtr Throw New NotImplementedException("取得対象の HWND を取得するコードをここに記述") End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Button1.Text = "描画開始" End Sub Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing If ThumbnailId <> IntPtr.Zero Then DwmUnregisterThumbnail(ThumbnailId) ThumbnailId = IntPtr.Zero End If End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click If ThumbnailId = IntPtr.Zero Then Dim chromeHandle As IntPtr = GetChromeHandle() DwmRegisterThumbnail(Me.Handle, chromeHandle, ThumbnailId) UpdateThumbnail() Button1.Text = $"描画停止:{ThumbnailId}" Else DwmUnregisterThumbnail(ThumbnailId) ThumbnailId = IntPtr.Zero Button1.Text = "描画開始" End If End Sub
Private Sub UpdateThumbnail() If ThumbnailId <> IntPtr.Zero Then Dim rect = Me.RectangleToClient(PictureBox1.RectangleToScreen(PictureBox1.ClientRectangle)) DwmUpdateThumbnailProperties(ThumbnailId, New DWM_THUMBNAIL_PROPERTIES(rect, False)) End If End Sub
#Region "DWM サムネイル API" Private Declare Auto Function DwmRegisterThumbnail Lib "dwmapi" (hwndDestination As IntPtr, hwndSource As IntPtr, <Out> ByRef phThumbnailId As IntPtr) As Integer Private Declare Auto Function DwmUpdateThumbnailProperties Lib "dwmapi" (hThumbnailId As IntPtr, <[In]> ptnProperties As DWM_THUMBNAIL_PROPERTIES) As Integer Private Declare Auto Function DwmUnregisterThumbnail Lib "dwmapi" (hThumbnailId As IntPtr) As Integer <StructLayout(LayoutKind.Sequential)> Public Structure RECT Public left As Integer, top As Integer, right As Integer, bottom As Integer Public Shared Widening Operator CType(r As RECT) As Rectangle Return Rectangle.FromLTRB(r.left, r.top, r.right, r.bottom) End Operator Public Shared Widening Operator CType(r As Rectangle) As RECT Return New RECT With {.left = r.Left, .top = r.Top, .right = r.Right, .bottom = r.Bottom} End Operator End Structure <Flags> Private Enum DWM_TNP As UInteger None = 0 RectDestination = &H1UI RectSource = &H2UI Opacity = &H4UI Visible = &H8UI SourceClientAreaOnly = &H10UI End Enum <StructLayout(LayoutKind.Sequential)> Private Class DWM_THUMBNAIL_PROPERTIES Public dwFlags As DWM_TNP = DWM_TNP.None Public rcDestination As RECT Public rcSource As RECT Public opacity As Byte = 255 <MarshalAs(UnmanagedType.Bool)> Public fVisible As Boolean = False <MarshalAs(UnmanagedType.Bool)> Public fSourceClientAreaOnly As Boolean = False Public Sub New() End Sub Public Sub New(destination As Rectangle, clientOnly As Boolean) dwFlags = DWM_TNP.RectDestination Or DWM_TNP.SourceClientAreaOnly rcDestination = destination fSourceClientAreaOnly = clientOnly End Sub End Class #End Region End Class
|