主题:关于多线程问题
请问:
我现在在用IVF写一个基于对话框的windows应用程序,我现在要实现的一项功能,具体如下:
~首先创建一个对话框;
~其次,我在创建对话框的程序中创建一个线程,用来调用另外一个程序进行计算;在计算过程中,对话框提示用户计算正在进行
~最后,在计算完成后,对话框退出,程序结束。
我想问的问题有两个:
1.我想在对话框上加一个取消按钮,当用户点击取消按钮时候,对话框结束,线程也结束。但是我发现我的对话框退出的时候,我创建的线程还在跑;不知道怎么关闭?
2.我想在对话框上加一个进度条,但是不知道怎么更新进度条?
请诸位网络高人帮帮忙,予以指导指导,不甚感激!下面是我的程序:
===========================================================================
!Pre:
! Call FDTD program to calculate
!Post:
! Show a window to prompt user if the calculation has been finished
!Date: 2010.5.10
Subroutine CalProgressDlg()
use Globals
implicit none
include 'resource.fd'
integer(kind=4) :: retint = 0
integer(kind=4) :: retlog
logical(kind=INT_PTR_KIND()) :: iThread , iDThread=0
type (dialog) :: dlg
type (T_SECURITY_ATTRIBUTES) lpThreadAttributes
external TerminateCAL,MyCalProc
if ( .not.DlgInit(IDD_PROGRESS, dlg) )then
return
else
retlog = DlgSetSub(dlg, IDCANCEL, TerminateCAL)
retlog = DlgSetSub(dlg, IDC_FINISHED, TerminateCAL)
retlog = DlgSetSub(dlg, IDC_DOING, TerminateCAL)
retlog = DlgSetSub(dlg, IDC_PROGRESS, TerminateCAL)
retlog = DlgSet(dlg, IDC_PROGRESS, 0, DLG_RANGEMIN)
retlog = DlgSet(dlg, IDC_PROGRESS, 100, DLG_RANGEMAX)
retlog = DlgSet(dlg, IDC_PROGRESS, 20)
iThread = CreateThread( lpThreadAttributes , 0 , loc(MyCalProc) , LOC(dlg) , 0 , iDThread )
retint = DLGMODALWITHPARENT(dlg,GetForeGroundWindow())
CALL DlgUninit( dlg )
end if
END SUBROUTINE CalProgressDlg
!------线程的回调例程------
Subroutine MyCalProc(dlg)
use Globals
implicit none
Integer(kind=4) :: retInt
logical(kind=4) :: retlog
character(256) :: msg0,msg1
type(dialog) :: dlg
!call CalUnmag
call sleep(2000)
call DLGEXIT(dlg)
retint = MessageBox(GetForegroundWindow(),"hello"C,"nihao"C,MB_OK)
Call ExitThread( 0 )
End Subroutine MyCalProc
Subroutine TerminateCAL(dlg, control_name, callbacktype)
use Globals
implicit none
include 'resource.fd'
integer(kind=4) :: control_name
integer(kind=4) :: callbacktype, local_callbacktype
type(dialog) :: dlg
local_callbacktype = callbacktype
if (control_name == IDCANCEL)then
call DLGEXIT (dlg)
endif
End Subroutine
我现在在用IVF写一个基于对话框的windows应用程序,我现在要实现的一项功能,具体如下:
~首先创建一个对话框;
~其次,我在创建对话框的程序中创建一个线程,用来调用另外一个程序进行计算;在计算过程中,对话框提示用户计算正在进行
~最后,在计算完成后,对话框退出,程序结束。
我想问的问题有两个:
1.我想在对话框上加一个取消按钮,当用户点击取消按钮时候,对话框结束,线程也结束。但是我发现我的对话框退出的时候,我创建的线程还在跑;不知道怎么关闭?
2.我想在对话框上加一个进度条,但是不知道怎么更新进度条?
请诸位网络高人帮帮忙,予以指导指导,不甚感激!下面是我的程序:
===========================================================================
!Pre:
! Call FDTD program to calculate
!Post:
! Show a window to prompt user if the calculation has been finished
!Date: 2010.5.10
Subroutine CalProgressDlg()
use Globals
implicit none
include 'resource.fd'
integer(kind=4) :: retint = 0
integer(kind=4) :: retlog
logical(kind=INT_PTR_KIND()) :: iThread , iDThread=0
type (dialog) :: dlg
type (T_SECURITY_ATTRIBUTES) lpThreadAttributes
external TerminateCAL,MyCalProc
if ( .not.DlgInit(IDD_PROGRESS, dlg) )then
return
else
retlog = DlgSetSub(dlg, IDCANCEL, TerminateCAL)
retlog = DlgSetSub(dlg, IDC_FINISHED, TerminateCAL)
retlog = DlgSetSub(dlg, IDC_DOING, TerminateCAL)
retlog = DlgSetSub(dlg, IDC_PROGRESS, TerminateCAL)
retlog = DlgSet(dlg, IDC_PROGRESS, 0, DLG_RANGEMIN)
retlog = DlgSet(dlg, IDC_PROGRESS, 100, DLG_RANGEMAX)
retlog = DlgSet(dlg, IDC_PROGRESS, 20)
iThread = CreateThread( lpThreadAttributes , 0 , loc(MyCalProc) , LOC(dlg) , 0 , iDThread )
retint = DLGMODALWITHPARENT(dlg,GetForeGroundWindow())
CALL DlgUninit( dlg )
end if
END SUBROUTINE CalProgressDlg
!------线程的回调例程------
Subroutine MyCalProc(dlg)
use Globals
implicit none
Integer(kind=4) :: retInt
logical(kind=4) :: retlog
character(256) :: msg0,msg1
type(dialog) :: dlg
!call CalUnmag
call sleep(2000)
call DLGEXIT(dlg)
retint = MessageBox(GetForegroundWindow(),"hello"C,"nihao"C,MB_OK)
Call ExitThread( 0 )
End Subroutine MyCalProc
Subroutine TerminateCAL(dlg, control_name, callbacktype)
use Globals
implicit none
include 'resource.fd'
integer(kind=4) :: control_name
integer(kind=4) :: callbacktype, local_callbacktype
type(dialog) :: dlg
local_callbacktype = callbacktype
if (control_name == IDCANCEL)then
call DLGEXIT (dlg)
endif
End Subroutine