分类广告


推荐文章

  • 没有找到任何内容!
您当前的位置:中国站长下载网络编程ASP专区 → 文章内容

窗口如何激活自己

  • 作者:不详    来源:网络转载    发布时间:2007-6-1 8:52:59
  • 字体大小:

在Window98以下,如果程序要激活自己,只需要简单的调用SetForegroundWindow即可达到目的。但到Win98以后,再也没有这么简单了。

    Window98以下,如果程序要激活自己,只需要简单SetForegroundWindow即可到目的。但到Win98以后,再也这么简单了。

新建一个简单的工程,加Timer控件,时间间3秒,接着在时间事件中SetForegroundWindow(Handle),好,行程序,窗口切到后台,3之后,看到的只是任务栏,窗口仍然在后面。

怎么回事呢,原Win98以后,窗口要使用SetForegroundWindow激活自己,必得到允许的方式有很多种,我只介绍最简单的一种,就是利用这个APILockSetForegroundWindow先解锁Foreground的窗口,然后再调用SetForegroundWindow

LockSetForegroundWindowDelphiWindows单元中并没有声明,需要自己声明,我将激活的函数重新封装如下,需要的朋友直接用就可以了:

const
  LSFW_LOCK     = 1;
  LSFW_UNLOCK   = 2;
function LockSetForegroundWindow(uLockCode: DWORD): BOOL; stdcall;

implementation

function LockSetForegroundWindow; external  'user32.dll' name 'LockSetForegroundWindow';

function wdSetForegroundWindow(Handle: THandle): Boolean;
begin
//-----------------------------------------------------
//作者:linzhenqun
//时间:2006-11-1
//说明:使Win98以上的窗口都可以设置Foreground的函数
//-----------------------------------------------------
  if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion> 4))//up win 2000
    or ((Win32Platform = VER_PLATFORM_WIN32_WINDOWSand  //up win 98
    ((Win32MajorVersion > 4or
    ((Win32MajorVersion = 4and
    (Win32MinorVersion > 0)))) then
    LockSetForegroundWindow(LSFW_UNLOCK);
  Result := SetForegroundWindow(Handle);
end;

现在你在时间事件中写下如下代码:

Application.Restore;

wdSetForegroundWindow(Handle);

那么,窗口就可以自己激活自己了,爽吧!