كيف؟ اجعل النافذة المطلوبة ابن لإحدى نوافذك عبر دالة الـ SetParent بكل بساطة.
مثال: في هذا المثال سنقوم بسرقة نافذة الآلة الحاسبة و جعلها ابناً لنافذتنا و كأنها أداة داخل النافذة.
كود
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Const GWL_STYLE = (-16)
Private Const WS_CLIPSIBLINGS = &H4000000
Private Const WS_VISIBLE = &H10000000
Private Sub Form_Load()
Dim Handle As Long, Ret As Long
'شغلنا البرنامج
Shell "calc", vbHide + vbMinimizedNoFocus
'نبحث عن مقبض نافذة البرنامج
Handle = FindWindow(vbNullString, "Calculator")
'إن لم تعمل معك الوظيفة السابقة فاحذف السطر السابق و فعل السطر التالي
'سنحصل على مقبض النافذة العليا
'Handle = GetForegroundWindow
'-
'نغير شكل النافذة لنزيل الشريط العلوي أي عنوان النافذة و أزرار التحكم
'لا حظ أننا نغير شكل النافذة العادي و ليس المطوّر الـ Extended
Ret = SetWindowLong(Handle, GWL_STYLE, WS_VISIBLE Or WS_CLIPSIBLINGS)
'ننقل النافذة إلى نافذة البرنامج بأن نجعلها ابناً لنافذتنا
SetParent Handle, Me.hWnd
End Sub
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Const GWL_STYLE = (-16)
Private Const WS_CLIPSIBLINGS = &H4000000
Private Const WS_VISIBLE = &H10000000
Private Sub Form_Load()
Dim Handle As Long, Ret As Long
'شغلنا البرنامج
Shell "calc", vbHide + vbMinimizedNoFocus
'نبحث عن مقبض نافذة البرنامج
Handle = FindWindow(vbNullString, "Calculator")
'إن لم تعمل معك الوظيفة السابقة فاحذف السطر السابق و فعل السطر التالي
'سنحصل على مقبض النافذة العليا
'Handle = GetForegroundWindow
'-
'نغير شكل النافذة لنزيل الشريط العلوي أي عنوان النافذة و أزرار التحكم
'لا حظ أننا نغير شكل النافذة العادي و ليس المطوّر الـ Extended
Ret = SetWindowLong(Handle, GWL_STYLE, WS_VISIBLE Or WS_CLIPSIBLINGS)
'ننقل النافذة إلى نافذة البرنامج بأن نجعلها ابناً لنافذتنا
SetParent Handle, Me.hWnd
End Sub
ملاحظة: عندي الوندوز بالأنكليزي Enabled لذلك عنوان نافذة الآلة الحاسبة هو Calculator لذلك غير السطر الثاني من البرنامج الذي يتم البحث عبره عن نافذة الآلة الحاسبة إلى عنوان نافذة الألة الحاسبة على نظامك.
لتحريك النافذة الابن التي تم الاستيلاء عليها استخدم دالة الـ MoveWindow .
مثال: MoveWindow Handle, 0, 0, Me.Width, Me.Height, 1