想写一个提示窗口(放在dll中), 由主程序调用后显示出来, 但主程序执行查询之类的操作,提示窗就死掉了, 只有查询完成了才能恢复. 
请问: 如何做能让提示窗在主程序运行时不受影响的显示?谢谢.

解决方案 »

  1.   

    调用的时候用Synchronize试一下,
    另外,如果线程执行的时间很长,在一定时间后,
    用Application.ProcessMessages响应一下消息队列,
    不然提示窗刷新的消息收不到,程序就像死了一样
      

  2.   

    比如有二个窗口A和B, A调用Dll中的B, B显示实时查询时间, 然后A执行查询(这个时候B就"死"掉了). 我想B能够不受影响的显示时间.
      

  3.   

    要不就自定义一个消息吧,让A定时的发给B,然后B来刷新。
      

  4.   

    创建B的时候,其Sender用application,不要用其创建的窗体
      

  5.   

    可以在B中起线程;把线程级别设到最低
    Priority := tpLowest
    在适当的地方应用application.ProcessMessages;
      

  6.   

    procedure TInitThread.CreateForm;
    begin
      Screen.Cursor:=crHourGlass;
      Application.CreateForm(TFrmTest, FrmTest);
      FrmTest.Show;
      self.Terminate;
      FrmMain.WindowState:=wsMaximized;
      FrmMain.Caption:='.....';
      Screen.Cursor:=crDefault;
    end;procedure TInitThread.Execute;
    begin
      FreeOnTermiNate:=True;
      Synchronize(CreateForm);
    end;
      

  7.   

    chenylin(陈SIR): 
       你的方法虽然可以在线程中建立窗口,但窗口在查询结束后才出现....仍然是串行运行的, 我的目的是同时运行...难道只能写线程查询,无法写线程的提示窗口?
      

  8.   

    没实现过,我说一点看法
    最起码要实现取消息以及派发消息的消息循环吧
    PeekMesssage
    DispatchMessage
    不然难到使用主线程的消息派发循环?
      

  9.   

    1.定义一个procedure of object -TProc
    2.写一个线程接受传入TProc参数
    3.execute方法
      showform;
      proc;
      freeform;
      terminate;
    3.主代码
      threada.Create(theProc);
      

  10.   

    下面的代码,应该与你要的类似paint a moving progress bar using a background thread?
     
    {
      Question:  I am trying query to display records in a dbgrid.however, due to size
      of tables and joins takes a while for the query to Execute.is
      there any way to Show a prorgess bar with a timer that increments
      position but continues to work while the query is being executed.BTW,
      using access so BDE is not used.  Answer:
      
      A progress bar would not be an ideal choice since you cannot determine up
      front how long the query will take, so you do not know the range the progress
      bar has to cover.A simple kind of animation that tells the user basically
      only that the application is not hung would be more appropriate.One could do
      such a thing in a secondary thread but it would have to be done using the
      plain Windows API and * no * Synchronize calls (since the main thread is
      blocked in the BDE call).Here is an example: unit anithread;
    }interfaceuses
      Classes, Windows, Controls, Graphics;type
      TAnimationThread = class(TThread)
      private
        { Private declarations }
        FWnd: HWND;
        FPaintRect: TRect;
        FbkColor, FfgColor: TColor;
        FInterval: integer;
      protected
        procedure Execute; override;
      public
        constructor Create(paintsurface : TWinControl; {Control to paint on }
          paintrect : TRect;          {area for animation bar }
          bkColor, barcolor : TColor; {colors to use }
          interval : integer);       {wait in msecs between
    paints}
      end;implementationconstructor TAnimationThread.Create(paintsurface : TWinControl;
      paintrect : TRect; bkColor, barcolor : TColor; interval : integer);
    begin
      inherited Create(True);
      FWnd := paintsurface.Handle;
      FPaintRect := paintrect;
      FbkColor := bkColor;
      FfgColor := barColor;
      FInterval := interval;
      FreeOnterminate := True;
      Resume;
    end; { TAnimationThread.Create }procedure TAnimationThread.Execute;
    var
      image : TBitmap;
      DC : HDC;
      left, right : integer;
      increment : integer;
      imagerect : TRect;
      state : (incRight, incLeft, decLeft, decRight);
    begin
      Image := TBitmap.Create;
      try
        with Image do 
        begin
          Width := FPaintRect.Right - FPaintRect.Left;
          Height := FPaintRect.Bottom - FPaintRect.Top;
          imagerect := Rect(0, 0, Width, Height);
        end; { with }
        left := 0;
        right := 0;
        increment := imagerect.right div 50;
        state := Low(State);
        while not Terminated do 
        begin
          with Image.Canvas do 
          begin
            Brush.Color := FbkColor;
            FillRect(imagerect);
            case state of
              incRight: 
              begin
                Inc(right, increment);
                if right > imagerect.right then 
                begin
                  right := imagerect.right;
                  Inc(state);
                end; { if }
              end; { Case incRight }
              incLeft: 
              begin
                Inc(left, increment);
                if left >= right then 
                begin
                  left := right;
                  Inc(state);
                end; { if }
              end; { Case incLeft }
              decLeft: 
              begin
                Dec(left, increment);
                if left <= 0 then 
                begin
                  left := 0;
                  Inc(state);
                end; { if }
              end; { Case decLeft }
              decRight: 
              begin
                Dec(right, increment);
                if right <= 0 then 
                begin
                  right := 0;
                  state := incRight;
                end; { if }
              end; { Case decLeft }
            end; { Case }
            Brush.Color := FfgColor;
            FillRect(Rect(left, imagerect.top, right, imagerect.bottom));
          end; { with }
          DC := GetDC(FWnd);
          if DC <> 0 then
            try
              BitBlt(DC,
                FPaintRect.Left,
                FPaintRect.Top,
                imagerect.right,
                imagerect.bottom,
                Image.Canvas.handle,
                0, 0,
                SRCCOPY);
            finally
              ReleaseDC(FWnd, DC);
            end;
          Sleep(FInterval);
        end; { While }
      finally
        Image.Free;
      end;
      InvalidateRect(FWnd, nil, True);
    end; { TAnimationThread.Execute }end.{Usage:
     Place a TPanel on a form, size it as appropriate.Create an instance of the
     TanimationThread call like this: procedure TForm1.Button1Click(Sender : TObject);
    }
    var
      ani : TAnimationThread;
      r : TRect;
      begin  
      r := panel1.clientrect;
      InflateRect(r, - panel1.bevelwidth, - panel1.bevelwidth);
      ani := TanimationThread.Create(panel1, r, panel1.color, clBlue, 25);
      Button1.Enabled := False;
      Application.ProcessMessages;
      Sleep(30000);  // replace with query.Open or such
      Button1.Enabled := True;
      ani.Terminate;
      ShowMessage('Done');
    end;