怎么能控制窗体的显示位置(30分)

  • 主题发起人 主题发起人 hhnick
  • 开始时间 开始时间
H

hhnick

Unregistered / Unconfirmed
GUEST, unregistred user!
用shellexcute调用外部程序,比如:计算器,但是每回它的显示位置是随机的,我想控制它显示的位置,该怎么办?
 
用findWindow得到程序handle, 再用 SetWindowPos 設置位置!<br><br>BOOL SetWindowPos(<br>&nbsp; HWND hWnd, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // handle to window<br>&nbsp; HWND hWndInsertAfter, &nbsp;// placement-order handle<br>&nbsp; int X, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // horizontal position<br>&nbsp; int Y, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // vertical position<br>&nbsp; int cx, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// width<br>&nbsp; int cy, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// height<br>&nbsp; UINT uFlags &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// window-positioning options<br>);<br>
 
var<br>&nbsp; MyHand : THandle;<br>&nbsp; MyRect : TRect;<br>begin<br>&nbsp; &nbsp;ShellExecute(0, 'Open', 'Calc.exe', nil, nil, SW_SHOWNORMAL);<br>&nbsp; &nbsp;MyHand := FindWindow('','计算器');<br>&nbsp; &nbsp;if MyHand &gt; 0 then<br>&nbsp; &nbsp; &nbsp; GetWindowRect(MyHand,MyRect);<br>&nbsp; &nbsp;SetWindowPos(MyHand,HWND_TOP,MyRect.Left,MyRect.Top,MyRect.Bottom-MyRect.Top,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyRect.Right-MyRect.Left,SWP_SHOWWINDOW);<br>end;<br>这是我的程序,但是我自己就觉得有问题,各位可以来看看。
 
各位帮帮忙。
 
在MyHand := FindWindow('','计算器');前面, 要加個<br><br>for I:= 0 to 5000 do Application.ProcessMessage;<br>MyHand := FindWindow('','计算器');<br>這樣比較保險點!<br>
 
加这个也控制不了计算器窗体的显示位置呀?
 
这个问题可能跟要shellexecute本身有关,还可能跟操作系统有关
 
应该是,操作系统本身就知道窗体的位置,它是怎么做的,我想知道,用注册表?
 
接受答案了.
 

Similar threads

后退
顶部