PDA

View Full Version : بستن فولدر



ali190
یک شنبه 31 مرداد 1389, 22:34 عصر
باسلام
یه سورس یا نمونه میخواستم که بتونم با دادن مسیر فولدر مورد نظرم رو ببندم
ممنون از لطفتون

Saman_12
دوشنبه 01 شهریور 1389, 00:22 صبح
سلام.
سورس نمی خواد که .
اینا رو توی جنرال بنویس :


Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Const WM_GETTEXT = &HD
Const WM_DESTORY = 16

اینا رو هم توی یه تایمر با اینتروال دلخواه :


On Error Resume Next
Dim Address As String
Dim hWnd(1) As Long
Dim i As Integer
hWnd(0) = FindWindow("CabinetWClass", vbNullString)
If hWnd(0) <> 0 Then
hWnd(1) = FindWindowEx(hWnd(0), 0, "WorkerW", vbNullString)
hWnd(1) = FindWindowEx(hWnd(0), 0, "ReBarWindow32", vbNullString)
hWnd(1) = FindWindowEx(hWnd(0), 0, "ComboBoxEx32", vbNullString)
Dim R As Long
Dim S As String
S = String(201, Chr(0))
R = SendMessage(hWnd(1), WM_GETTEXT, 200, S)
If Left(S, R) = "My Computer" Then Exit Sub
Address = Left(S, R)
If Address = "c:\" Then
R = SendMessage(hWnd(0), WM_DESTORY, 0, 0)
If R <> 0 Then MsgBox "Close Window", vbInformation, "Close"
End If
End If

دیدی خیلی راحته.☻☺

ali190
دوشنبه 01 شهریور 1389, 00:29 صبح
ممنون از جوابت
من میخوام این کد رو روی یک دکمه قرار بدم
این کار رو کردم ولی ارور داد
نیاز نیست از رفرنس چیزی رو بتیکم؟
ممنون

Saman_12
دوشنبه 01 شهریور 1389, 00:35 صبح
نه احتیاج به رفرنس نیست من خودم الان امتحانش کردم جای Your Path آدرس یه پوشه توی درایو C رو گذاشتم بعد هم بر نامه رو اجرا کردم به محض وارد شدن به پوشه پنجره ی اکسپلورر بسته شد.

ali190
دوشنبه 01 شهریور 1389, 00:41 صبح
این هم نمونه
متاسفانه کار نمیکنه

Saman_12
دوشنبه 01 شهریور 1389, 01:42 صبح
اینو توی جنرال اظافه کن :

Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

کد باتون رو هم با این کد عوض کن کن :


On Error Resume Next
Dim Address As String
Dim hWnd, hwnd1 As Long
Dim i As Integer
hWnd = FindWindow("CabinetWClass", vbNullString)
hwnd1 = hWnd
If hWnd <> 0 Then
hWnd = FindWindowEx(hWnd, 0, "WorkerW", vbNullString)
hWnd = FindWindowEx(hWnd, 0, "ReBarWindow32", vbNullString)
hWnd = FindWindowEx(hWnd, 0, "ComboBoxEx32", vbNullString)
Dim R As Long
Dim S As String
S = String(201, Chr(0))
R = SendMessage(hWnd, WM_GETTEXT, 200, S)
If Left(S, R) = "My Computer" Then Exit Sub
Address = Left(S, R)
If Address = "C:\" Then
ShowWindow hwnd1, 0
If R <> 0 Then MsgBox "Hide Window", vbInformation, "Hide"
End If
End If

حالا حتما می شه!