解决问题,高分相赠!(100分)

  • 主题发起人 主题发起人 zzutrain
  • 开始时间 开始时间
Z

zzutrain

Unregistered / Unconfirmed
GUEST, unregistred user!
我想控制两个窗口,达到的效果为:<br><br>如:两个应用程序ap1,ap2,这两个程序可能都不能最小化,也不能最大话。在任务栏中可能连标题都没有.<br>我要求屏幕最前端为ap1,那么屏幕最前端就为ap1, &nbsp;最前端为ap2,那么最前端就为ap2.<br>就像在任务栏上点击ap1或ap2标题时显示的效果一样。<br><br>如果大家调程序不方便,可以用Timer控件来实现.<br>我用showwindow函数试过,不可以.<br>是不能用任务栏的消息函数?该函数应该怎样调用呢?<br>举例而言:我运行了两个软件,WPS2000,Delphi50.现在我需要把Delphi50显示到最前端.过一会把WPS2000显示到最前端.不需要人去控制,就像在Windows任务栏上点击了WPS2000或者Delphi50以后出现的效果.<br><br>所以大家不要想着用Application的任何函数来实现<br>
 
是不是有个叫SetWindowLong的函数,试试看
 
1、在Win2000下是不可能实现的。<br>2、在Win98下可以试试SwitchToWindow这个函数,以下是从前面的帖子里抄来的:<br>//首先,在你的FORM的PRIVATE里,定义相关procedure与变量:<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp;...<br>&nbsp; &nbsp;...<br>&nbsp; private<br>&nbsp; &nbsp; hooklib: thandle;<br>&nbsp; &nbsp; switchwin: procedure(hwnd:thandle;brestore:boolean);stdcall; &nbsp; <br>//第一个参数传递你要SHOW的窗口句柄,第二个参数是TRUE时如果窗口是最小化状态,就恢复最小化前状态<br>&nbsp; ...<br>&nbsp; ...<br>&nbsp; end; <br>//再在FORM的oncreate事件里写入两行代码:<br>&nbsp; hooklib:=getmodulehandle('USER32');<br>&nbsp; @switchwin := getprocaddress(hooklib, 'SwitchToThisWindow');<br><br>//最后,在你要用到的地方调用switchwin,比如这样:<br>switchwin(w_HidedWindow,true)就可以了
 
SetWindowPos(...);
 
NT下面SetForegroundWindow API函数有小小问题,只能够让窗口闪烁而已,你可以使用下面的<br>函数,不是我写的,摘抄自 Kingron 的猛料。<br><br>procedure ForceForegroundWindow(hwnd: THandle); <br>begin<br>&nbsp; &nbsp; mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTDOWN,0,0,0,0);<br>&nbsp; &nbsp; mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP,0,0,0,0);<br>&nbsp; &nbsp; SetForegroundWindow(hwnd);<br>end;<br><br>procedure ForceTopmostWindow(hwnd: THandle); <br>begin<br>&nbsp; &nbsp; SetWindowPos(hwnd, HWND_TOPMOST,Form.Left,Form.Top,Form.Width,Form.Height,0);<br>end;<br><br><br>该方法通过模拟鼠标按键来实现激活窗口并最前显示。<br>***********************************************************************************************************<br><br>function ForceForegroundWindow(hwnd: THandle): boolean;<br>const<br>&nbsp; &nbsp;SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;<br>&nbsp; &nbsp;SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;<br>var<br>&nbsp; &nbsp;timeout: DWORD;<br>begin<br>&nbsp; &nbsp;if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion &gt; 4)) or<br>&nbsp; &nbsp; &nbsp; ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and<br>&nbsp; &nbsp; &nbsp; ((Win32MajorVersion &gt; 4) or ((Win32MajorVersion = 4) and (Win32MinorVersion &gt; 0)))) then begin<br>&nbsp; &nbsp; &nbsp; SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0);<br>&nbsp; &nbsp; &nbsp; SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(0), SPIF_SENDCHANGE);<br>&nbsp; &nbsp; &nbsp; Result := SetForegroundWindow(hWnd);<br>&nbsp; &nbsp; &nbsp; SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(timeout), SPIF_SENDCHANGE);<br>&nbsp; &nbsp;end else<br>&nbsp; &nbsp; &nbsp; Result := SetForegroundWindow(hWnd);<br>end; { ForceForegroundWindow }<br><br>***********************************************************************************<br><br>function ForceForegroundWindow(hwnd: THandle): boolean; <br>const <br>&nbsp; SPI_GETFOREGROUNDLOCKTIMEOUT = $2000; <br>&nbsp; SPI_SETFOREGROUNDLOCKTIMEOUT = $2001; <br>var <br>&nbsp; ForegroundThreadID: DWORD; <br>&nbsp; ThisThreadID &nbsp; &nbsp; &nbsp;: DWORD; <br>&nbsp; timeout &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : DWORD; <br>begin <br>&nbsp; if IsIconic(hwnd) then ShowWindow(hwnd, SW_RESTORE); <br><br>&nbsp; if GetForegroundWindow = hwnd then Result := true <br>&nbsp; else begin <br>&nbsp; &nbsp; if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion &gt; 4)) or <br>&nbsp; &nbsp; &nbsp; ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and <br>&nbsp; &nbsp; &nbsp; ((Win32MajorVersion &gt; 4) or ((Win32MajorVersion = 4) and <br>&nbsp; &nbsp; &nbsp; (Win32MinorVersion &gt; 0)))) then <br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; Result := false; <br>&nbsp; &nbsp; &nbsp; ForegroundThreadID := GetWindowThreadProcessID(GetForegroundWindow,nil); <br>&nbsp; &nbsp; &nbsp; ThisThreadID := GetWindowThreadPRocessId(hwnd,nil); <br>&nbsp; &nbsp; &nbsp; if AttachThreadInput(ThisThreadID, ForegroundThreadID, true) then begin <br>&nbsp; &nbsp; &nbsp; &nbsp; BringWindowToTop(hwnd); // IE 5.5 related hack <br>&nbsp; &nbsp; &nbsp; &nbsp; SetForegroundWindow(hwnd); <br>&nbsp; &nbsp; &nbsp; &nbsp; AttachThreadInput(ThisThreadID, ForegroundThreadID, false); <br>&nbsp; &nbsp; &nbsp; &nbsp; Result := (GetForegroundWindow = hwnd); <br>&nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; &nbsp; if not Result then begin <br>&nbsp; &nbsp; &nbsp; &nbsp; SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0); <br>&nbsp; &nbsp; &nbsp; &nbsp; SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(0), SPIF_SENDCHANGE); <br>&nbsp; &nbsp; &nbsp; &nbsp; BringWindowToTop(hwnd); // IE 5.5 related hack <br>&nbsp; &nbsp; &nbsp; &nbsp; SetForegroundWindow(hWnd); <br>&nbsp; &nbsp; &nbsp; &nbsp; SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(timeout), SPIF_SENDCHANGE); <br>&nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; end <br>&nbsp; &nbsp; else begin <br>&nbsp; &nbsp; &nbsp; BringWindowToTop(hwnd); // IE 5.5 related hack <br>&nbsp; &nbsp; &nbsp; SetForegroundWindow(hwnd); <br>&nbsp; &nbsp; end; <br><br>&nbsp; &nbsp; Result := (GetForegroundWindow = hwnd); <br>&nbsp; end; <br>end; { ForceForegroundWindow } <br>
 
他们说的好像都不好用..<br>我前两天也做了一个类似的程序..一个Mp3播放器..<br>我的做法是在窗口上放一个按钮,VISIBLE:=FALSE;<br>在ONCLICK 事件中写入代码, 我的是判断是不WIDTH&lt;1,因为我在最小化时把它的WIDTH设<br>为0了所以.<br>if width&lt;1 then <br>&nbsp;begin<br>&nbsp; mainform.width:=200;<br>&nbsp; mainform.height:=150;<br>&nbsp;end<br>else <br>&nbsp;begin<br>&nbsp; mainform.width:=0;<br>&nbsp; mainform.height:=0;<br>&nbsp;end;<br>在程序中写入:<br>Application.OnMinimize:=minbutton.OnClick(Self);<br>Application.OnRestore:=minbutton.OnClick(Self);<br>在程序中要最小化的时候调用Application.Minimize;<br>恢复时用Application.Restore;
 
使用FINDWINDOW得到两个窗口的HANDLE<br>使用HANDLE控制两窗体
 
谢谢各位的关注!希望大家多多指教!
 
后退
顶部