function SetSysFocus(hwnd: integer): integer; var hOtherWin,OtherTHreadID,hFocusWin:integer; begin hOtherWin:=GetForegroundWindow; OtherThreadID:=GetWindowThreadProcessID(hOtherWin,nil); if AttachThreadInput(GetcurrentThreadID,OtherThreadID,True) then begin hFocusWin:=GetFocus; windows.SetFocus(hwnd); //SendMessage(hwnd,WM_COPY,0,0); if hFocusWin<>0 then try //SendMessage(GetFocus,WM_COPY,0,0); finally AttachThreadInput(GetCurrentTHreadID,OtherTHreadID,False); end; end else result:=Windows.SetFocus(hwnd); end; 这样用SetSysFocus(Application.Handle); 就会在最前面了 这里是以前的代码 功能是使窗体得到焦点.这与此同时,如果你能将窗体设为最上,那你的窗体因为得到焦点,就一定在最上了. 你可以这样写! SetSysFocus(Application.Handle); showmessage('...');
ShowModal, FormStyle:=fsStayOnTop 试试。
SetWindowPos(Form1.Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE Or SWP_NOSIZE); SetWindowPos(Form1.Handle,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE Or SWP_NOSIZE); 第一句把Form1置为总在最前的窗口,第2句取消,这样窗口就跑到前面来了.
Application.BringToFront;
Application.ProcessMessage;
ShowMessage(.....
你的方法不行!刚试了
难道非得再做一个窗体吗?
var
hOtherWin,OtherTHreadID,hFocusWin:integer;
begin
hOtherWin:=GetForegroundWindow;
OtherThreadID:=GetWindowThreadProcessID(hOtherWin,nil);
if AttachThreadInput(GetcurrentThreadID,OtherThreadID,True) then
begin
hFocusWin:=GetFocus;
windows.SetFocus(hwnd);
//SendMessage(hwnd,WM_COPY,0,0);
if hFocusWin<>0 then
try
//SendMessage(GetFocus,WM_COPY,0,0);
finally
AttachThreadInput(GetCurrentTHreadID,OtherTHreadID,False);
end;
end
else result:=Windows.SetFocus(hwnd);
end;
这样用SetSysFocus(Application.Handle);
就会在最前面了
这里是以前的代码
功能是使窗体得到焦点.这与此同时,如果你能将窗体设为最上,那你的窗体因为得到焦点,就一定在最上了.
你可以这样写!
SetSysFocus(Application.Handle);
showmessage('...');
SetWindowPos(Form1.Handle,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE Or SWP_NOSIZE);
第一句把Form1置为总在最前的窗口,第2句取消,这样窗口就跑到前面来了.
还想讨论一下如何能实现金山毒霸的整点报时类似的功能(提示比较美观,目前的方案比较死板)
明晚结帖!!!