Hello building a small game here and was having issues making a proper close button for in game windows.. I will post a chunk of code and maybe you can fix my issue..

Code:
        Case MailboxWindow
            With GameWindow.Mailbox
                Engine_Render_Grh .SkinGrh, .Screen.X, .Screen.Y, 0, 1, True, GUIColorValue, GUIColorValue, GUIColorValue, GUIColorValue
                Engine_Render_Text Font_Default, MailboxListBuffer, .Screen.X + .List.X, .Screen.Y + .List.Y, -1
                Engine_Render_Text Font_Default, "Read", .Screen.X + .ReadLbl.X, .Screen.Y + .ReadLbl.Y, -1
                Engine_Render_Text Font_Default, "Write", .Screen.X + .WriteLbl.X, .Screen.Y + .WriteLbl.Y, -1
                Engine_Render_Text Font_Default, "Delete", .Screen.X + .DeleteLbl.X, .Screen.Y + .DeleteLbl.Y, -1
                If SelMessage > 0 Then Engine_Render_Rectangle .Screen.X + .List.X, .Screen.Y + .List.Y + ((SelMessage - 1) * Font_Default.CharHeight), .List.Width, Font_Default.CharHeight, 1, 1, 1, 1, 1, 1, 0, 0, 2097217280, 2097217280, 2097217280, 2097217280, , False   'ARGB: 125/0/255/0
                    If Engine_Collision_Rect(MousePos.X, MousePos.Y, 1, 1, .Screen.X + 325, .Screen.Y + 5, 10, 17) Then
        If MouseLeftDown > 0 Then
            ShowGameWindow(LastClickedWindow) = 0
            LastClickedWindow = 0
            Exit Sub
        End If
    End If
            End With
Now this is what I added extra in that is in the above code...
Code:
  If Engine_Collision_Rect(MousePos.X, MousePos.Y, 1, 1, .Screen.X + 325, .Screen.Y + 5, 10, 17) Then
        If MouseLeftDown > 0 Then
            ShowGameWindow(LastClickedWindow) = 0
            LastClickedWindow = 0
            Exit Sub
        End If
    End If
This where I have issues.. It works fine closes no problem.. But when I click somewhere on the screen and hold down the mouse button right to this X in this window in the main game window it crashes...

So I get a error 9 and debugs goes to this:
Code:
LastClickedWindow = 0
I am a n99b and learning.. If you can give me a snip of code to try or know how to fix the issue that would be great..