我看了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
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
setForegroundow(form1.handle);
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.
application.restore;
application.bringwindowtofront;
memol.lines.append(socket.receivwtext);这是serversocketclientread事件,想使这个窗口从一切窗口中弹出来,得到聚焦,但事实上这代码只是象qq一样,来了消息之后,任务栏上的窗口闪几下,并没有跳出来,得到聚焦,古木,你真是个好人,呵呵^_^!
Application.Restore;
SetForegroundWindow(form1.handle);
memol.lines.append(socket.receivwtext);
发到我邮箱吧; [email protected]
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
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