Form and RenderLoop

All controls are automatically redrawn in Net. For a RenderLoop, of course, this is not desirable. The graphic engine controls the drawing procces.

You have to create your own control and RenderLoop.  Here’s how to do this.

Inizialize Class

_RenderForm = New Renderform(AddressOf GameLoop)

Private Sub GameLoop()
End sub

Renderform Class

Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Public Class Renderform : Inherits Form

 <StructLayout(LayoutKind.Sequential)> _
 Public Structure Message
     Public hWnd As IntPtr
     Public msg As UInteger
     Public wParam As IntPtr
     Public lParam As IntPtr
     Public time As UInteger
     Public p As System.Drawing.Point
 End Structure

 Delegate Sub MsgLoop()
 Private _Loop As MsgLoop

 <DllImport("User32.dll", CharSet:=CharSet.Auto)> _
 Public Shared Function PeekMessage(ByRef msg As Message, hWnd As IntPtr, messageFilterMin As UInteger, messageFilterMax As UInteger, flags As UInteger) As Boolean
 End Function

Public ReadOnly Property AppStillIdle() As Boolean
       Dim msg As Message
       Return Not PeekMessage(msg, IntPtr.Zero, 0, 0, 0)
   End Get
End Property

Public Sub New(RendeLoop As MsgLoop)
   Me.Size = New Drawing.Size(New Drawing.Point(640, 480))
   Me.StartPosition = FormStartPosition.CenterScreen
   _Loop = RendeLoop
End Sub

Public Sub Run()
   Me.SetStyle(ControlStyles.UserPaint, True)
   Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
   Me.SetStyle(ControlStyles.CacheText, True)
   AddHandler Application.Idle, AddressOf Application_Idle
End Sub

Private Sub Application_Idle(s As Object, e As EventArgs)
   While (AppStillIdle)
   End While
End Sub

End Class


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s