在windows中,怎样使自己的程序的到聚焦呢?

解决方案 »

  1.   

    Application.Restore;
    setForegroundow(form1.handle);
      

  2.   

    可以啊,用上面的方法就可以啊。以下例程当窗口在背后时且极小化是,按下Ctrl+Alt+shift+B 将其弹出来。unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, AppEvnts, StdCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
        Label1: TLabel;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        procedure wmhotkey(var _message:TMessage);message WM_HOTKEY;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    var
      id:atom;
    begin
      id:=globalAddAtom('zjs');
      registerHotkey(form1.Handle,id,MOD_CONTROL or MOD_ALT OR MOD_SHIFT,ord('B'));  // Ctrl+Shift+Alt+B
    end;procedure TForm1.wmhotkey(var _message:TMessage);
    begin
      //showWindow(form1.Handle,sw_show);   //虽然可以激活最小化的窗口,但最小化按钮失效,而且窗口在背后
      //form1.WindowState:=wsNormal;        //没有效果
      Application.Restore;
      //setWindowPos(FORM1.Handle,HWND_TOP,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW);  //同 showWindow  //setActiveWindow(form1.Handle);      //needn't
      setForegroundWindow(form1.Handle);  //必须,否则窗口未极小化时,窗口不会提到前面来
      edit1.SetFocus;
    end;end.
      

  3.   

    由于我的操作系统是windows2000,所以可能调用setforegroundwindow可能不能实现,不知道还有没有其他的办法。
      

  4.   

    setforegroundwindow(form1.handle);
    application.restore;
    application.bringwindowtofront;
    memol.lines.append(socket.receivwtext);这是serversocketclientread事件,想使这个窗口从一切窗口中弹出来,得到聚焦,但事实上这代码只是象qq一样,来了消息之后,任务栏上的窗口闪几下,并没有跳出来,得到聚焦,古木,你真是个好人,呵呵^_^!
      

  5.   

    好像顺序有误,你改成这样试试:
    Application.Restore;
    SetForegroundWindow(form1.handle);
    memol.lines.append(socket.receivwtext);
      

  6.   

    还是不行哦,古木,我有一个例子,不过他是用vb实现的,我就是想实现那个样子,你把qq告诉我,我发给你看看,好不好?记住,我是2000的操作系统。
      

  7.   

    我也是2000的操作系统啊。
    发到我邮箱吧; [email protected]
      

  8.   

    没收到啊,换个邮箱试试。[email protected]
      

  9.   

    我看了vb的源代码,它也就是在Timer的触发事件中使用SetForegroundWindow来设置焦点的,要不我用Delphi给你写一个同样功能的东东?以下是VB的源代码。Option ExplicitPrivate Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
    Private Sub Command1_Click()
       Me.Caption = "Waiting..."
       Me.WindowState = vbMinimized
       Timer1.Enabled = True
    End SubPrivate Sub Command2_Click()
       Me.Caption = "Waiting..."
       Timer1.Enabled = True
    End SubPrivate Sub Form_Load()
       Timer1.Interval = 3000
       Set Me.Icon = Nothing
    End SubPrivate Sub Timer1_Timer()
       Timer1.Enabled = False
       If Check1.Value = vbChecked Then
          Me.WindowState = vbNormal
          Call SetForegroundWindow(Me.hWnd)
          Me.Caption = "Can't see me?"
       Else
          Call ForceForegroundWindow(Me.hWnd)
          Me.Caption = "Here I am!"
       End If
    End Sub
      

  10.   

    Private Sub Timer1_Timer()
       Timer1.Enabled = False
       If Check1.Value = vbChecked Then
          Me.WindowState = vbNormal
          Call SetForegroundWindow(Me.hWnd)  '<<<<<==========就是这里
          Me.Caption = "Can't see me?"
       Else
          Call ForceForegroundWindow(Me.hWnd) 
          Me.Caption = "Here I am!"
       End If
    End Sub
      

  11.   

    好的,当然,我就是想用delphi来实现这个啊,