What i want to do:
- Use CreateWindowEx to make a new transparent, fullscreen window.
- Pass the Handle to SlimDx
- Draw onto that window with SlimDX
My current code: This is my CreateWindowEx Function:
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)
This is my 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
The Window is being created and i can check its size with GetWindowRect, however my screen just goes white and SlimDX doesnt draw onto it.
My Drawing Code:
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