g_Thread:=CreateThread(nil,0,@CloseDialogsThread,nil,0,threadID);
function CloseDialogsThread(Ptr: Pointer):LongInt;stdcall;
begin
  timeSetEvent(50,10,@CloseWindow,0,TIME_PERIODIC);
end;procedure CloseWindow();
var
  hhWnd:THandle;
  CtrlID:THandle;
begin
    hhWnd:=FindWindow(nil,'Microsoft Internet Explorer');
    if hhWnd<> 0 then
    begin
      CtrlID:=GetDlgItem(hhWnd,2);
      PostMessage(CtrlID,BM_CLICK,0,0);
    end;
end;
这样写为什么会造成程序自动关闭,出于原因不能用控件,
现想在不耽误主线程的情况下新开一个线程,用来关闭对话框有什么可行的办法没?