الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

ممكن طريق فتح وغلق برنامج معين .EXE

مغلق
بدأه mr alfox في 23 يوليو 2007 · 2 رد · 936 مشاهدة · في لغة Ms Visual Basic 6 وما قبلها من إصدارات
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

ممكن كود يعمل في الفيجوال بيزك يعمل علي فتح وغلق برنامج

EXE

وشكراااااااا

#2

تشغيل ملف EXE يتم عن طريق الأمر Shell , أما غلقه فممكن عن طريق الحصول على مقبض النافذة بتاعته و أرسال رسالة WM_CLOSE له.

#3

ما ذكره الأخ msayed صحيح و متابعةً لما ذكره:

يمكنك الحصول على مقبض النافذة Window Handle من خلال توابع API و الكود التالي يوضح ذلك:

ضع الكود التالي في موديول Module

Public Const GW_HWNDNEXT = 2

Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _
  ByVal wCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
  (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
  (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" _
  (ByVal hwnd As Long, lpdwprocessid As Long) As Long

Function ProcIDFromWnd(ByVal hwnd As Long) As Long
   Dim idProc As Long

   ' Get PID for this HWnd
   GetWindowThreadProcessId hwnd, idProc

   ' Return PID
   ProcIDFromWnd = idProc
End Function

Function GetWinHandle(hInstance As Long) As Long
   Dim tempHwnd As Long

   ' Grab the first window handle that Windows finds:
   tempHwnd = FindWindow(vbNullString, vbNullString)

   ' Loop until you find a match or there are no more window handles:
   Do Until tempHwnd = 0
      ' Check if no parent for this window
      If GetParent(tempHwnd) = 0 Then
         ' Check for PID match
         If hInstance = ProcIDFromWnd(tempHwnd) Then
            ' Return found handle
            GetWinHandle = tempHwnd
            ' Exit search loop
            Exit Do
         End If
      End If

      ' Get the next window handle
      tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT)
   Loop
End Function

و هذا الكود في زر الحصول على مقبض النافذة:

Private Sub Command1_Click()
   Dim hInst As Long             ' Instance handle from Shell function.
   Dim hWndApp As Long           ' Window handle from GetWinHandle.
   Dim buffer As String          ' Holds caption of Window.
   Dim numChars As Integer       ' Count of bytes returned.

   ' Shell to an application
   hInst = Shell("calc.exe")

   ' Begin search for handle
   hWndApp = GetWinHandle(hInst)

   If hWndApp <> 0 Then
      ' Init buffer
      buffer = Space$(128)

      ' Get caption of window
      numChars = GetWindowText(hWndApp, buffer, Len(buffer))

      ' Display window's caption
      MsgBox "You shelled to the Application: " & Left$(buffer, numChars)
   End If
End Sub

و في حال وجود أي مشاكل يرجى الإفصاح عنها للفائدة العامة.

1

مؤسس شبكة مواقع إجابتي أول شبكة مواقع عربية للأسئلة والأجوبة

هذا الموضوع مغلق.

مواضيع مشابهة