JosephE
25-08-2010, 21:01
I'm rather new to window message handling, and I'm working on making a simple modeless dialog.
I'm curious as to why it keeps processing messages after I close the window. See the example code. On my system, I get about 38 WM_CLOSE messages every time. And thinBASIC doesn't throw an error every time I end the dialog that doesn't exist, either. Am I missing something?
Note that I have a simple While Loop running while the window is open, this represents what my program is doing in the background while the user is staring at my window.
Uses "UI"
Uses "Console"
Dim hWin As DWord
Dim hWinStyle As DWord = %WS_DLGFRAME Or %DS_CENTER Or %WS_CAPTION Or %WS_SYSMENU Or %WS_OVERLAPPEDWINDOW
Dim Title As String = "Test Window"
Dim Alive As Boolean
Dim Closed As Integer = 0
Function TBMain()
Dim test As Integer = 0
Dialog New Pixels, 0, Title, -1, -1, 800, 600, hWinStyle To hWin
Dialog Show Modeless hWin, Call Messages()
Alive = TRUE
While Alive
test+=1
PrintL "Up and running... "&test
Dialog DoEvents 0
Wend
PrintL "Press any key to quit..."
WaitKey
End Function
CallBack Function Messages()
' Message handler for window.
Select Case CBMSG
Case %WM_INITDIALOG
Case %WM_COMMAND
Select Case CBCTL
Case %bClose
End Select
Case %WM_CLOSE
Dialog End hWin
Alive = FALSE
Closed+=1
PrintL "Closing: " & Closed
End Select
End Function
I'm curious as to why it keeps processing messages after I close the window. See the example code. On my system, I get about 38 WM_CLOSE messages every time. And thinBASIC doesn't throw an error every time I end the dialog that doesn't exist, either. Am I missing something?
Note that I have a simple While Loop running while the window is open, this represents what my program is doing in the background while the user is staring at my window.
Uses "UI"
Uses "Console"
Dim hWin As DWord
Dim hWinStyle As DWord = %WS_DLGFRAME Or %DS_CENTER Or %WS_CAPTION Or %WS_SYSMENU Or %WS_OVERLAPPEDWINDOW
Dim Title As String = "Test Window"
Dim Alive As Boolean
Dim Closed As Integer = 0
Function TBMain()
Dim test As Integer = 0
Dialog New Pixels, 0, Title, -1, -1, 800, 600, hWinStyle To hWin
Dialog Show Modeless hWin, Call Messages()
Alive = TRUE
While Alive
test+=1
PrintL "Up and running... "&test
Dialog DoEvents 0
Wend
PrintL "Press any key to quit..."
WaitKey
End Function
CallBack Function Messages()
' Message handler for window.
Select Case CBMSG
Case %WM_INITDIALOG
Case %WM_COMMAND
Select Case CBCTL
Case %bClose
End Select
Case %WM_CLOSE
Dialog End hWin
Alive = FALSE
Closed+=1
PrintL "Closing: " & Closed
End Select
End Function