English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

我有一個執行檔開啟後(不是我自己的程式)我不想讓他的表單能移動我用vb應該要如何寫才能夠固定別人的表單呢?

2006-03-25 13:55:22 · 1 個解答 · 發問者 Nick 5 in 電腦與網際網路 程式設計

1 個解答

'先以一個未命名的記事本為例,表單放1個Timer,Interval=50Private Type RECT    Left As Long    Top As Long    Right As Long    Bottom As LongEnd TypePrivate Declare Sub SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As LongDim B As Boolean, R As RECT, X&, Y&Private Sub Timer1_Timer()Dim H As Long, P As RECT'找到記事本的HwndH = FindWindow(vbNullString, "未命名 - 記事本")If H Then   If B = False Then      GetWindowRect H, R '先記錄記事本的方位      X = R.Left: Y = R.Top      B = True   Else      GetWindowRect H, P '檢查方位是否不同      If X <> P.Left Or Y <> P.Top Then         SetWindowPos H, 0, R.Left, R.Top, 0, 0, 1 '若不同則修正      End If   End IfEnd IfDoEventsEnd Sub

2006-03-25 19:35:04 · answer #1 · answered by W.J.S. 7 · 0 0

fedest.com, questions and answers