皆さん、こんにちは。
まとまった量のデータ処理をしている途中のプログラムを、古のBREAKキーを押して強制終了させる如く、ウィンドウ右上のXマークを押しても「反応してません」と出てくるのが気に入らず、懊悩してました。
皆さんにアドバイスを頂き、「オフィシャルユーザーズガイド」の「マルチスレッド」の真似で、落ち着きました。
アドバイスありがとうございました。
-----------------------------
Dim status As long
Dim hThread As DWord
Function MainWndProc(hWnd As DWord, dwMsg As DWord, wParam As DWord, lParam As DWord) As DWord
MainWndProc=EventCall_MainWnd(hWnd,dwMsg,wParam,lParam)
End Function
Sub MainWnd_Destroy()
loop_DestroyObjects()
PostQuitMessage(0)
End Sub
Function DDD(hWnd As DWord) As DWord
Dim i As DWord
Dim hDC As DWord
Dim buffer0 As String
i=0
Do
SetWindowText(GetDlgItem(hMainWnd,Static1),Str$(i))
i=i+1
If i>100 Then
i=0
End If
if status=0 Then
Exit Do
End If
sleep(100)
Loop
ReleaseDC(hWnd,hDC)
CloseHandle(hThread)
End Function
Sub MainWnd_CommandButton1_Click()
Dim dwDummy As DWord
If status=0 Then
status=1
SetDlgItemText(hMainWnd,CommandButton1,"Stop")
hThread=CreateThread(ByVal 0,0,AddressOf(DDD),_
GetDlgItem(hMainWnd,Static1),0,VarPtr(dwDummy))
Else
status=0
SetDlgItemText(hMainWnd,CommandButton1,"Start")
End If
End Sub
|