30-10-2009, 03:14 PM
This tutorial is a form that will allow a Yes/No or Okay button to be displayed and allow the game to continue processing while waiting on a response. I would like to thank Robin for the base form that I used to create this.
This works by passing in the memory address of a sub or function to run when the user clicks a button on the frmAlert. I use CallWindowProc to create a sort of call back function, just like the byte array packets.
![[Image: alertMessage.jpg]](http://www.deadnoggin.com/files/images/alertMessage.jpg)
Adding to your project:
Download the following form and add it to your project.
http://www.deadnoggin.com/files/frmAlert.frm
This is the code for the form (just in case anyone would like to see it)
Add the following code to modGameLogic:
This code creates a new form for every alert message. This allows multiple AlertMessages at once.
These consts are used by the form, so make sure you have them in your source somewhere.
How to use:
To use this alertmessage feature, you call the sub as follows:
Example (For MR)
To handle the click event:
All click events HAVE TO HAVE THESE EXACT PARAMETERS OR IT WILL NOT WORK!
Example (For MR)
This works by passing in the memory address of a sub or function to run when the user clicks a button on the frmAlert. I use CallWindowProc to create a sort of call back function, just like the byte array packets.
![[Image: alertMessage.jpg]](http://www.deadnoggin.com/files/images/alertMessage.jpg)
Adding to your project:
Download the following form and add it to your project.
http://www.deadnoggin.com/files/frmAlert.frm
This is the code for the form (just in case anyone would like to see it)
Code:
Option Explicit
Private Declare Function AlertCallBack Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByRef Msg As Byte, ByVal wParam As Long, ByVal lParam As Long) As Long
Public OkayOnly As Boolean
Public sMessage As String
Public YesNo As Byte
Public callBack As Long
Private Sub Form_Load()
If OkayOnly Then
lblOkay.Visible = True
Else
lblYes.Visible = True
lblNo.Visible = True
End If
lblMessage.Caption = sMessage
End Sub
Private Sub lblNo_Click()
YesNo = NO
ProcessClick
End Sub
Private Sub lblOkay_Click()
YesNo = OKAY
ProcessClick
End Sub
Private Sub lblYes_Click()
YesNo = YES
ProcessClick
End Sub
Private Sub ProcessClick()
' Make sure there is something to call back to
If callBack 0 Then AlertCallBack callBack, YesNo, 0, 0, 0
Unload Me
End Sub
Add the following code to modGameLogic:
This code creates a new form for every alert message. This allows multiple AlertMessages at once.
Code:
Public Sub AlertMessage(ByVal message As String, Optional ByRef callBack As Long, Optional ByVal OkayOnly As Boolean = True)
Dim myForm As New frmAlert
myForm.sMessage = message
myForm.OkayOnly = OkayOnly
myForm.callBack = callBack
myForm.Show
End Sub
These consts are used by the form, so make sure you have them in your source somewhere.
Code:
Public Const NO As Byte = 0
Public Const YES As Byte = 1
Public Const OKAY As Byte = 2
How to use:
To use this alertmessage feature, you call the sub as follows:
Code:
AlertMessage "Whatever you want to appear", AddressOf sub/function to run when clicked, only display Okay or Yes/No
Example (For MR)
Code:
AlertMessage Name & " has offered to revive you. Do you accept?", AddressOf Revive_Click, False
To handle the click event:
All click events HAVE TO HAVE THESE EXACT PARAMETERS OR IT WILL NOT WORK!
Code:
Public Sub *_Click(ByVal YesNo As Long, ByRef Data As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
' Check the YesNo for your value then process
End Sub
Example (For MR)
Code:
Public Sub Release_Click(ByVal YesNo As Long, ByRef Data As Byte, ByVal StartAddr As Long, ByVal ExtraVar As Long)
If YesNo = YES Then
SendRelease
End If
End Sub