Quantcast
Channel: VBForums - API
Viewing all articles
Browse latest Browse all 168

[VB.Net] CreateWindowEx

$
0
0
Hi there, I'm trying to create a window in Visual Basic.Net using the CreateWindowEx API. Currently here is how I'm declaring my enumerators and function:
Code:

    <Flags()> Public Enum WindowStylesEx As UInteger
        AcceptFiles = &H10
        AppWindow = &H40000
        ClientEdge = &H200
        Composited = &H2000000
        ContextHelp = &H400
        ControlParent = &H10000
        DlgModelFrame = &H1
        Layered = &H80000
        LayoutRtl = &H400000
        Left = &H0
        LeftScrollBar = &H4000
        LTRReading = &H0
        MdiChild = &H40
        NoActivate = &H8000000
        NoInheritLayout = &H100000
        NoParentNotify = &H4
        PaletteWindow = WindowEdge Or ToolWindow Or TopMost
        Right = &H1000
        RTLReading = &H2000
        StaticEdge = &H20000
        ToolWindow = &H80
        TopMost = &H8
        Transparent = &H20
        WindowEdge = &H100
    End Enum

    <Flags()> Public Enum WindowStyles As UInteger
        Border = &H800000
        Caption = &HC00000
        Child = &H40000000
        ClipChildren = &H2000000
        ClipBlings = &H4000000
        Disabled = &H8000000
        DlgFrame = &H400000
        Group = &H20000
        HScroll = &H100000
        Maximize = &H1000000
        MaximizeBox = &H10000
        Minimize = &H20000000
        MinimizeBox = &H20000
        Overlapped = &H0
        OverlappedWindow = Overlapped Or Caption Or SysMenu Or SizeFrame Or MinimizeBox Or MaximizeBox
        PopUp = &H80000000UI
        PopUpWindow = PopUp Or Border Or SysMenu
        SizeFrame = &H40000
        SysMenu = &H80000
        TabStop = &H10000
        Visible = &H10000000
        VScroll = &H200000
    End Enum

    <DllImport("user32.dll", SetLastError:=True)> _
    Public Shared Function CreateWindowEx( _
      ByVal dwExStyle As WindowStylesEx, _
      ByVal lpClassName As String, _
      ByVal lpWindowName As String, _
      ByVal dwStyle As WindowStyles, _
      ByVal x As Integer, _
      ByVal y As Integer, _
      ByVal nWidth As Integer, _
      ByVal nHeight As Integer, _
      ByVal hWndParent As IntPtr, _
      ByVal hMenu As IntPtr, _
      ByVal hInstance As IntPtr, _
      ByVal lpParam As IntPtr) As IntPtr
    End Function

Now whenever I do this, it works:
Code:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim newWindow As IntPtr = CreateWindowEx(WindowStylesEx.ToolWindow, "Button", "Button1", WindowStyles.Visible, 0, 0, 150, 150, IntPtr.Zero, IntPtr.Zero, Process.GetCurrentProcess().Handle, IntPtr.Zero)
    End Sub

However, if I don't want any controls I try this and it doesn't work:
Code:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim newWindow As IntPtr = CreateWindowEx(WindowStylesEx.ToolWindow, String.Empty, String.Empty, WindowStyles.Visible, 0, 0, 150, 150, IntPtr.Zero, IntPtr.Zero, Process.GetCurrentProcess().Handle, IntPtr.Zero)
    End Sub

Why is it that? And by doesn't work I mean that there is no exception, no stack errors, no window gets created, just nothing happens.

Viewing all articles
Browse latest Browse all 168

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>