自己写代码 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); 然后再messageBox就会在最前面了
自已再畫一個From不就行了,用From來做對話框....
From的FromStyle屬性設為fsStayOnTop
Messagebox(handle,'hello world','test',MB_OK or MB_TOPMOST);
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);
然后再messageBox就会在最前面了