我想做的事:
- 使用 CreateWindowEx 创建一个新的透明全屏窗口。
- 将句柄传递给 SlimDx
- 使用 SlimDX 在该窗口上绘图
我当前的代码:这是我的 CreateWindowEx 函数:
Handle = Win32.CreateWindowEx(WindowConstants.WINDOW_EX_STYLE_DX, WindowConstants.DESKTOP_CLASS, "", WindowConstants.WINDOW_STYLE_DX, X, Y, Width, Height, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero)
Dim PresentParams As New PresentParameters With {.Windowed = True, .SwapEffect = SwapEffect.Discard, .BackBufferFormat = Format.A8R8G8B8, .BackBufferWidth = Width, .BackBufferHeight = Height, .Multisample = MultisampleType.EightSamples, .PresentationInterval = PresentInterval.Immediate}
Device = New Device(New Direct3D, 0, DeviceType.Hardware, Handle, CreateFlags.HardwareVertexProcessing, PresentParams)
Win32.SetLayeredWindowAttributes(Handle, 0, 255, Win32.LWA_ALPHA)
Win32.SetWindowLong(Handle, Win32.GWL_EXSTYLE, Win32.GetWindowLong(Handle, Win32.GWL_EXSTYLE) Or Win32.WS_EX_LAYERED Or Win32.WS_EX_TRANSPARENT)
Dim Margins As Win32.Margins = New Win32.Margins With {.Left = X, .Top = Y, .Right = Width, .Bottom = Height}
Win32.DwmExtendFrameIntoClientArea(Handle, Margins)
这是我的 CreateWindowEX:
<DllImport("user32.dll")>
Public Shared Function CreateWindowEx(dwExStyle As UInteger, lpClassName As String, lpWindowName As String, dwStyle As UInteger, x As Integer, y As Integer,
nWidth As Integer, nHeight As Integer, hWndParent As IntPtr, hMenu As IntPtr, hInstance As IntPtr, lpParam As IntPtr) As IntPtr
End Function
正在创建窗口,我可以使用 GetWindowRect 检查它的大小,但是我的屏幕只是变白并且 SlimDX 没有在上面绘制。
我的绘图代码:
OverlayThread = New Thread(AddressOf OverlayLoop) With {.IsBackground = Background}
Overlaythread.Start()
Public Sub OverlayLoop()
While True
Device.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0, 0), 1.0F, 0)
Device.BeginScene()
DrawLine(100, 100, 500, 500, 5, Color.Red)
Device.EndScene()
Device.Present()
Thread.Sleep(10)
End While
End Sub