您的位置:首页 > 其它

怎么自动把窗体显示出来?

2008-11-27 21:10 288 查看
怎么自动把窗体显示出来? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061119181326198.html

当窗体当前没有焦点,或者窗体被最小化了,在该窗体得到某一事件怎么显示窗体呀?让窗体得到焦点。我用以下代码不行:
procedure TForm1.WndProc(var message: TMessage);
var
dataStruct: PCOPYDATASTRUCT;
passingMessage: PMessage;
begin
inherited;
if message.Msg = WM_COPYDATA then begin
dataStruct := PCOPYDATASTRUCT(message.LParam);
passingMessage := PMessage(dataStruct.lpData);
if (passingMessage^.Msg = WM_KEYDOWN) then begin
//listBox1.Items.Add('message=' + IntToStr(passingMessage^.WParam));
if (passingMessage^.wParam = VK_HOME) then
begin
ShowWindow(self.Handle, SW_SHOWNORMAL or SW_RESTORE);
BringWindowToTop(self.Handle);
SetForegroundWindow(self.Handle);
end;
end;
end;
end;

窗体在任务栏一闪一闪得,就是不提前现实。

试下:
ShowWindow(Application.Handle, SW_SHOWNORMAL or SW_RESTORE);

帮顶

试了ShowWindow(Application.Handle, SW_SHOWNORMAL or SW_RESTORE);
也是一样,就是不提前显示出来

有用了,我发现如果最小化得时候采用Application.Handle就行了,哈哈,我再试试
目前处于别得窗体之后还不行

加上BringWindowToTop和SetForegroundWindow呢?用Application.Handle

我也是都在后面2函数上加上才能在最小化状态把窗体置前得。但是处于别得窗体之后还是不行。不知道怎么回事

不是你想SetForegroundWindow谁就可以SetForegroundWindow谁的。

(msdn只说win98/me是这样,其实2k/xp也一样)
the system restricts which processes can set the foreground window. A process can set the foreground window only if one of the following conditions is true:

The process is the foreground process.
The process was started by the foreground process.
The process received the last input event.
There is no foreground process.
The foreground process is being debugged.
The foreground is not locked (see LockSetForegroundWindow).
The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).
No menus are active.
不信可以自己试验,
搞一个程序只有:
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
SetForegroundWindow(Handle);
}
保存起来,运行它然后把窗体放在后面,这时它只能在任务栏里闪。

再搞一个程序:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
WinExec("C:\\Documents and Settings\\Ray\\桌面\\新建文件夹\\project1.exe",SW_SHOW);//运行上一个程序
}
这时按Button1就可以调到前面来。

学习接分;;;;;;;;;;;

leonatcs(LeonKennedy)(时常逛一逛csdn,有益身心健康。)
真是这样,只在任务栏里闪,但是有没有办法直接掉到前面来?如果不开新进程。因为这个进程要一直开着,比如游戏外挂。我看到别得游戏外挂可以做到。

谢谢
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐