在CreateWindowEX创建的窗口上使用SlimDX绘图

时间:2017-06-30 17:58:59

标签: vb.net slimdx createwindowex

我想做什么:

  • 使用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

0 个答案:

没有答案