有辦法在程式內再執行指定的程式嗎?
例如:
在寫出之程式視窗中執行"踩地雷"
踩地雷的視窗位置會受到主視窗的限制
而主視窗關閉時內部開啟的程式也會一併關閉
2006-11-04 10:09:57 · 1 個解答 · 發問者 ? 1 in 電腦與網際網路 ➔ 程式設計
感謝WJS回答
但此方法似乎只能應用在部分程式
例如:
media player 會直接跳出新視窗
PCman也是
是否只能用單一執行檔程式才能運作呢?
可以修改嗎?
2006-11-04 16:01:31 · update #1
'原因出在抓到的hWnd是錯誤的,故無法成功,你試試看以下的方式'不過最大問題還是出在關閉程式,PostMessage是強迫關閉程式,非每個程式都賣帳,像MediaPlayer就非要跑出個警告視窗才甘心被關閉,故最好能針對該程式寫才不會有問題.Private Type RECT L As Long T As Long R As Long B As LongEnd TypePrivate Declare Sub SetParent Lib "user32" (ByVal C&, ByVal H&)Private Declare Sub MoveWindow Lib "user32" (ByVal N&, ByVal X&, ByVal Y&, ByVal W&, ByVal H&, ByVal B&)Private Declare Sub PostMessage Lib "user32" Alias "PostMessageA" (ByVal H&, ByVal M&, ByVal W&, P&)Private Declare Sub GetWindowRect Lib "user32" (ByVal H&, R As RECT)Private Declare Function GetForegroundWindow Lib "user32" () As LongConst WM_CLOSE = &H10Dim W&Private Sub Form_Load() Dim P&, I&, J&, R As RECT '啟動MediaPlayer(注意路徑是否正確) P = Shell("C:\Program Files\Windows Media Player\wmplayer.exe", vbNormalFocus) If P Then '因為是以vbNormalFocus啟動,此時MediaPlayer會取得駐點,故利用GetForegroundWindow來取得其hWnd W = GetForegroundWindow SetParent W, Me.hWnd '把它收入表單中 '取得MediaPlayer視窗大小 GetWindowRect W, R '設定MediaPlayer的Left,Top MoveWindow W, 0, 0, R.R - R.L, R.B - R.T, 1 End IfEnd SubPrivate Sub Form_Unload(Cancel As Integer) '關閉MediaPlayer PostMessage W, WM_CLOSE, 0, 0End Sub
2006-11-04 13:08:11 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋