¥¥¥高分求救,一个窗口的调用的API问题!!!解决了继续加分。¥¥¥(200分)

Z

zitai

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟在主控程序中调用了一个窗口A(动态库文件),当调用其他窗口后(未释放窗口A的dll),窗口失去了焦点,<br>但是我已经记录了该窗口的handle ,再调用窗口A时只想将将它从后台移到前台就可以了。但是bringwindowtotop,<br>setwindowpos,showwindow全部没法实现目的。不知该怎么办!!!<br><br>下面是其中的代码:<br>{<br>funname ----------------功能名称<br>filename ---------------文件名称<br>type TDllArray=array [0..9] of Record<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Winhand:Thandle;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;funcname:string;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;filename:string;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>dllarray:TDllArray;<br>}<br><br>procedure ExcuteFunc(FuncName,filename:string;param:shortstring);<br>var<br>MKfound:Boolean; //-------------模块发现标志<br>GNfound:Boolean; //-------------功能发现标志<br>Foundindex:integer; //----------发现位置<br>index:integer; &nbsp; &nbsp;//循环变量<br>minnull:integer; &nbsp; //-----------最小空位置<br>begin<br>minnull:=10;<br>foundindex:=0;<br>MkFound:=False;<br>GnFound:=False;<br>for &nbsp;index:=0 to 9 do<br>begin<br>&nbsp; &nbsp;if dllarray[index].Winhand &lt;&gt; 0 then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp;if dllarray[index].filename = filename &nbsp;then<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;foundindex:=index;<br>&nbsp; &nbsp; &nbsp; &nbsp;MKfound:=True;<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp;if (dllarray[index].filename = filename) and &nbsp;(dllarray[index].funcname = funcname) then<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;foundindex:=index;<br>&nbsp; &nbsp; &nbsp; &nbsp;Gnfound:=True;<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp;end<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp;if minnull&gt; index then<br>&nbsp; &nbsp;minnull:=index;<br>&nbsp; &nbsp;end;<br>end;<br>if minnull =10 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; application.MessageBox('请关闭掉一些窗口','出错信息!',MB_OK);<br>&nbsp; &nbsp; &nbsp; exit<br>&nbsp; &nbsp; end;<br>if NOT MKFOUND and (minnull &lt; 10 ) THEN<br>begin<br>&nbsp; &nbsp; &nbsp;DllHandle:=loadlibrary(pchar(filename));<br>&nbsp; &nbsp; &nbsp; if DllHandle&lt;&gt;0 then<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; @DllMain:=getprocaddress(DllHandle,'ModMain');<br>&nbsp; &nbsp; &nbsp; if @DllMain&lt;&gt;nil then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; DllMain(operation,Frame.handle,pchar('NJ_SCGDB'),pchar('userid'),pchar('userid'),param);<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; application.MessageBox('没有对应的函数','程序出错!',MB_OK);<br>&nbsp; &nbsp; &nbsp; except<br>&nbsp; &nbsp; &nbsp; freelibrary(Dllhandle);<br>&nbsp; &nbsp; &nbsp; operation:=0;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; application.messagebox('没有找到对应的DLL','出错信息',MB_OK);<br>&nbsp; &nbsp; &nbsp; dllarray[minnull].Winhand :=dllhandle;<br>&nbsp; &nbsp; &nbsp; dllarray[minnull].funcname :=funcname;<br>&nbsp; &nbsp; &nbsp; dllarray[minnull].filename :=filename;<br>end;<br>if MkFOUND AND not GNFOUND and (minnull &lt;10 )then<br>begin<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; @DllMain:=getprocaddress(DllArray[foundindex].Winhand,'ModMain');<br>&nbsp; &nbsp; &nbsp; if @DllMain&lt;&gt;nil then<br>&nbsp; &nbsp; &nbsp; DllMain(operation,Frame.handle,pchar('NJ_SCGDB'),pchar('userid'),pchar('userid'),param)<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; application.MessageBox('没有对应的函数','程序出错!',MB_OK);<br>&nbsp; &nbsp; &nbsp; except<br>&nbsp; &nbsp; &nbsp; freelibrary(Dllhandle);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; dllarray[minnull].Winhand :=dllarray[foundindex].Winhand ;<br>&nbsp; &nbsp; &nbsp; dllarray[minnull].funcname :=funcname;<br>&nbsp; &nbsp; &nbsp; dllarray[minnull].filename :=filename;<br>end;<br>if GnFound then &nbsp; <br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; bringwindowtotop(dllarray[foundindex].winhand);//问题出现的位置<br>&nbsp; &nbsp; &nbsp; setwindowpos(dllarray[foundindex].winhand,HWND_TOP,1,1,400,600,SWP_DRAWFRAME);<br>&nbsp; &nbsp; &nbsp; setactivewindow(dllarray[foundindex].winhand);<br>// &nbsp; &nbsp; &nbsp;showwindow(dllarray[foundindex].winhand,SW_SHOWNORMAL);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; // &nbsp; &nbsp;clinttoscreen();<br>end;<br>
 
Y

YB_unique

Unregistered / Unconfirmed
GUEST, unregistred user!
试试!<br>SetactiveWindow(Handle);
 
Y

yanlei

Unregistered / Unconfirmed
GUEST, unregistred user!
SetForegroundWindow
 
K

kthy

Unregistered / Unconfirmed
GUEST, unregistred user!
在win98SE以后,MS将SetForegroundWindow函数改成只将该窗口的标题闪烁,而不是原来<br>的功能。请使用以下函数代替:<br><br>function ForceForegroundWindow(hwnd: THandle): boolean;<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; &nbsp; end<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; Result := SetForegroundWindow(hWnd);<br>end; { ForceForegroundWindow }<br>
 
Z

zitai

Unregistered / Unconfirmed
GUEST, unregistred user!
谢谢二位,我已经试过了,先给你们各20分吧
 
J

jqw

Unregistered / Unconfirmed
GUEST, unregistred user!
sendmessage(yourform.handle,WM_SYSCOMMAND,...)
 
Z

zitai

Unregistered / Unconfirmed
GUEST, unregistred user!
首先谢谢kthy君,问题没有解决,在执行了SetForegroundWindow(hWnd)后result为false;<br>没有能够成功。不过,我相信你的方法应该可以的,不知道为什么。<br>然后谢谢jqw君,我的问题有许多的dll中实现接受你的说明的消息?这在程序的稳定性方面不可靠。谢谢当然应该加分!<br>我想尽快能将分数送出去!当然了,我更想将问题解决。西西西西~~~~~~<br>谢谢各位兄台!!!
 
K

kthy

Unregistered / Unconfirmed
GUEST, unregistred user!
可能与你将form放在dll中有关,这里牵涉到一些其他问题。<br>事实上,我所有的软件都是这么用的,一切正常!我再看看。
 
Z

zitai

Unregistered / Unconfirmed
GUEST, unregistred user!
但是我将主控最小化时又可以看到隐藏在后面的窗口A。
 
K

kthy

Unregistered / Unconfirmed
GUEST, unregistred user!
应该将主控程序的application对象传递给dll中,作为application对象。详细请<br>在大富翁查找相关主题。
 
Z

zitai

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 
Z

zitai

Unregistered / Unconfirmed
GUEST, unregistred user!
分数已经发出了,问题未能解决,我将继续加分!!!有劳各位兄台!
 
顶部