这是我以前的程序,可以跳到最前面
你试一下
if (Timer1.Interval<>3000) and (i<10) then
begin
Form1.Visible:=True;
Application.BringToFront;
ShowWindow(Application.Handle,SW_RESTORE); Application.BringToFront;
Timer1.Enabled:=False;
Timer1.Interval:=3000;
Timer1.Enabled:=True;
i:=i+1;
end;
if i>=10 then
begin
i:=0;
Timer1.Enabled:=False;
Timer1.Interval:=24000000;
Timer1.Enabled:=True;
Form1.Visible:=False;
ShowWindow(Application.Handle,SW_Hide);
end;
if Application.MessageBox('You Should Have A Rest','Rest',MB_OKCANCEL )=ID_OK then
begin
i:=0;
Timer1.Enabled:=False;
Timer1.Interval:=24000000;
Timer1.Enabled:=True;
Form1.Visible:=False;
ShowWindow(Application.Handle,SW_Hide);
end;
你试一下
if (Timer1.Interval<>3000) and (i<10) then
begin
Form1.Visible:=True;
Application.BringToFront;
ShowWindow(Application.Handle,SW_RESTORE); Application.BringToFront;
Timer1.Enabled:=False;
Timer1.Interval:=3000;
Timer1.Enabled:=True;
i:=i+1;
end;
if i>=10 then
begin
i:=0;
Timer1.Enabled:=False;
Timer1.Interval:=24000000;
Timer1.Enabled:=True;
Form1.Visible:=False;
ShowWindow(Application.Handle,SW_Hide);
end;
if Application.MessageBox('You Should Have A Rest','Rest',MB_OKCANCEL )=ID_OK then
begin
i:=0;
Timer1.Enabled:=False;
Timer1.Interval:=24000000;
Timer1.Enabled:=True;
Form1.Visible:=False;
ShowWindow(Application.Handle,SW_Hide);
end;
unit MultInst;interfaceconst
MI_QUERYWINDOWHANDLE = 1;
MI_RESPONDWINDOWHANDLE = 2; MI_ERROR_NONE = 0;
MI_ERROR_FAILSUBCLASS = 1;
MI_ERROR_CREATINGMUTEX = 2;// Call this function to determine if error occurred in startup.
// Value will be one or more of the MI_ERROR_* error flags.
function GetMIError: Integer;implementationuses Forms, Windows, SysUtils;const
UniqueAppStr = 'DDG.I_am_the_Eggman!';var
MessageId: Integer;
WProc: TFNWndProc;
MutHandle: THandle;
MIError: Integer;function GetMIError: Integer;
begin
Result := MIError;
end;function NewWndProc(Handle: HWND; Msg: Integer; wParam, lParam: Longint):
Longint; stdcall;
begin
Result := 0;
// If this is the registered message...
if Msg = MessageID then
begin
case wParam of
MI_QUERYWINDOWHANDLE:
// A new instance is asking for main window handle in order
// to focus the main window, so normalize app and send back
// message with main window handle.
begin
if IsIconic(Application.Handle) then
begin
Application.MainForm.WindowState := wsNormal;
Application.Restore;
end;
PostMessage(HWND(lParam), MessageID, MI_RESPONDWINDOWHANDLE,
Application.MainForm.Handle);
end;
MI_RESPONDWINDOWHANDLE:
// The running instance has returned its main window handle,
// so we need to focus it and go away.
begin
SetForegroundWindow(HWND(lParam));
Application.Terminate;
end;
end;
end
// Otherwise, pass message on to old window proc
else
Result := CallWindowProc(WProc, Handle, Msg, wParam, lParam);
end;procedure SubClassApplication;
begin
// We subclass Application window procedure so that
// Application.OnMessage remains available for user.
WProc := TFNWndProc(SetWindowLong(Application.Handle, GWL_WNDPROC,
Longint(@NewWndProc)));
// Set appropriate error flag if error condition occurred
if WProc = nil then
MIError := MIError or MI_ERROR_FAILSUBCLASS;
end;procedure DoFirstInstance;
// This is called only for the first instance of the application
begin
// Create the mutex with the (hopefully) unique string
MutHandle := CreateMutex(nil, False, UniqueAppStr);
if MutHandle = 0 then
MIError := MIError or MI_ERROR_CREATINGMUTEX;
end;procedure BroadcastFocusMessage;
// This is called when there is already an instance running.
var
BSMRecipients: DWORD;
begin
// Prevent main form from flashing
Application.ShowMainForm := False;
// Post message to try to establish a dialogue with previous instance
BSMRecipients := BSM_APPLICATIONS;
BroadCastSystemMessage(BSF_IGNORECURRENTTASK or BSF_POSTMESSAGE,
@BSMRecipients, MessageID, MI_QUERYWINDOWHANDLE,
Application.Handle);
end;procedure InitInstance;
begin
SubClassApplication; // hook application message loop
MutHandle := OpenMutex(MUTEX_ALL_ACCESS, False, UniqueAppStr);
if MutHandle = 0 then
// Mutex object has not yet been created, meaning that no previous
// instance has been created.
DoFirstInstance
else
BroadcastFocusMessage;
end;initialization
MessageID := RegisterWindowMessage(UniqueAppStr);
InitInstance;
finalization
// Restore old application window procedure
if WProc <> Nil then
SetWindowLong(Application.Handle, GWL_WNDPROC, LongInt(WProc));
if MutHandle <> 0 then CloseHandle(MutHandle); // Free mutex
end.
1:用一个SwitchToThisWindow() 未公开的API可以做到。
2:修改系统规则。代码?我忘记了~~~~~~~~~~~~~~~
上面的说明里明明说可以是itself的啊?
不行把下面两条合起来试试:
SetForegroundWindow(TargetWnd);
SetActiveWindow(TarGetWnd);
bringwindowtotop之类的代码,谢谢.
upupup
欢迎各位前来捧场,
SwitchToThisWindow(Application.handle);
EnableWindow(Application.Handle,True);注:其中SwitchToThisWindow函数的声明为:
procedure SwitchToThisWindow(handle:THandle);cdecl;external 'user32.dll' name 'SwitchToThisWindow';
很奇怪的是,这里CloseWindow一句是必须的,如果没有这一句,当有其他窗口在前面的时候
就不行了。
见鬼了,在我的机上还是不行,先是最小化了窗口,然后再打开窗口,然后就一个劲的在任务栏上闪呀闪的,就是switch不了它自己.会不会跟我的系统有关?我的系统是2000+ie6+sp2+visual .net studio+visual studio+delphi6+office xp+其他
ie6很变态,有时会莫名其妙的自动关闭,清华紫光输入法使用时,屏幕有时候会一闪一闪的
能否指点指点?
Stadio6+Rose+PhoteShop5+Oracle+Informix+XMLSpy+Project98+ErWin+PowerDVD+金山结巴2000...
唉,全是老掉牙的东西....:(
function AllowSetForegroundWindow( dwProcessId:DWORD): BOOL; stdcall;implementation
function AllowSetForegroundWindow; external 'user32.dll' name 'AllowSetForegroundWindow';具体看一下 MSDN上的帮助,以前没有看,偶然一看,上面的道理讲的正是透彻,呵呵
状态栏中应用按钮闪烁,并没有将应用调到最前面。请使用下列函数:function ForceForegroundWindow(hwnd: THandle): boolean;
const
SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
var
timeout: DWORD;
begin
if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion
> 4)) or
((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
((Win32MajorVersion > 4) or ((Win32MajorVersion = 4) and
(Win32MinorVersion > 0)))) then begin
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout,
0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
TObject(0), SPIF_SENDCHANGE);
Result := SetForegroundWindow(hWnd);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
TObject(timeout), SPIF_SENDCHANGE);
end
else
Result := SetForegroundWindow(hWnd);
end; { ForceForegroundWindow }