السلام عليكم ورحمة الله وبركاته
احاول الحصول على تابع نافذة باستخدام SetWindowLong وكانت هذه الشيفرة على أيام VB6 تعمل بشكل جيد أما الان
فلا تعمل الا على نافذة ضمن التطبيق أو برنامج مصنوع بالدت نت
هل من أحد يعلم شي عن الموضوع علما اني بحثت كثيرا في المنتدى ولم أعثر على شي
Imports System.Runtime.InteropServices PublicClass Main '--------------------------------------------------------------------------------- PrivateDeclareFunction SetWindowLong Lib"user32.dll"Alias _ "SetWindowLongA" (ByVal hwnd AsInteger, ByVal nIndex AsInteger, ByVal dwNewinteger AsInteger) AsInteger '--------------------------------------------------------------------------------- PrivateDeclareFunction FindWindow Lib"user32.dll"Alias _ "FindWindowA" (ByVal lpClassName AsString, ByVal lpWindowName AsString) AsInteger '--------------------------------------------------------------------------------- PrivateDeclareFunction CallWindowProc Lib"user32.dll"Alias _ "CallWindowProcA" (ByVal lpPrevWndFunc AsInteger, ByVal hwnd AsInteger, ByVal msg AsInteger, ByVal wParam AsInteger, ByVal lParam AsInteger) AsInteger '--------------------------------------------------------------------------------- PrivateConst GWL_WNDPROC AsInteger = -4 '--------------------------------------------------------------------------------- PublicDelegateFunction Proc _ (ByVal hwnd As IntPtr, ByVal msg AsInteger, _ ByVal wparam AsInteger, ByVal lparam AsInteger) AsInteger '--------------------------------------------------------------------------------- PrivateSub Form1_FormClosing(ByVal sender AsObject, _ ByVal e As System.Windows.Forms.FormClosingEventArgs) HandlesMe.FormClosing SetWindowLong(hwnd, GWL_WNDPROC, PrevProc) EndSub '--------------------------------------------------------------------------------- Dim hwnd As IntPtr PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ HandlesMyBase.Load Dim ProcDel AsNew Proc(AddressOf WindProc) ' Now try to change the next line to 'hwnd = me.handle 'or make another application with .NET with any Form it will works 'hwnd = FindWindow(vbNullString, "Form1") hwnd = FindWindow(vbNullString, "Calculator") PrevProc = SetWindowLong(hwnd, GWL_WNDPROC, _ Marshal.GetFunctionPointerForDelegate(ProcDel)) EndSub '--------------------------------------------------------------------------------- Dim PrevProc AsInteger '--------------------------------------------------------------------------------- PublicFunction WindProc(ByVal hwnd As IntPtr, _ ByVal msg AsInteger, ByVal wparam AsInteger, ByVal lparam AsInteger) AsInteger Debug.Print(msg.ToString) Return CallWindowProc(PrevProc, hwnd, msg, wparam, lparam) EndFunction EndClass