ورود

View Full Version : سوال: بدست آوردن متن جایی که موس روی آن کلیک می کند



exirius
چهارشنبه 28 مهر 1389, 21:09 عصر
سلام دوستان من یه مشکلی دارم که فکر میکنم با استفاده از توابع api حل میشه .
من می خام یه برنامه درست کنم که وقتی موس روی هر قسمتی از ویندوز کلیک شد متن اون قسمتو داشته باشم .مثل برنامه بابیلون
اگه از دوستان کسی اطلاعاتی در این مورد داره ممنون میشم منو راهنمایی کنه .
مر30

i2ib4sunshine
چهارشنبه 28 مهر 1389, 22:19 عصر
دوست عزیز این کار اصلا به اون سادگی که شما فکر می کنید،نیست !

اگر کمی دقت کنید خود Babylon هم تو ویندوز ویستا و 7 با این قضیه مشکل داره

exirius
چهارشنبه 28 مهر 1389, 23:00 عصر
البته اگه توی xp هم باشه مشکلی نداره .
اگه چیزی در موردش می دونید منو راهنمایی کنید .
من این کدو دارم ولی فقط کپشن پنجره ها رو میده :
'System & API - How to get Caption and Thread ID of Window under cursorOption Explicit Const WM_COMMAND = &H111Const MAX_PATH = 260Const SW_SHOW = 5Const SW_RESTORE = 9Const SW_SHOWMINIMIZED = 2Const SW_SHOWMAXIMIZED = 3Const SW_SHOWNORMAL = 1Private Type POINTAPI x As Long y As LongEnd TypePrivate Type RECT Left As Long Top As Long Right As Long Bottom As LongEnd TypePrivate Type WINDOWPLACEMENT Length As Long flags As Long showCmd As Long ptMinPosition As POINTAPI ptMaxPosition As POINTAPI rcNormalPosition As RECTEnd TypePrivate lpwndpl As WINDOWPLACEMENTPrivate CursorLoc As POINTAPIPrivate Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPrivate Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As LongPrivate Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, _ ByVal lpString As String, ByVal cch As Long) As LongPrivate Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, _ lpdwProcessId As Long) As LongPrivate Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, _ lpwndpl As WINDOWPLACEMENT) As LongPrivate Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As LongPrivate Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _ ByVal lpWindowName As String) As LongPrivate Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long 'Add a Text Box, a Command Button, two Labels, and a Timer Control to your Form.'Set Timer Interval property to 500.'Label1 will display the caption of the window under the cursor.'Label2 will display the window's thread ID.'Insert window's caption to Text1 and press the button to activate it.Private Sub Command1_Click() Dim sAppName As String Dim lState As Long, lHandle As Long sAppName = Trim$(Text1) If sAppName = "" Then Exit Sub 'Find the window with the current caption. lpwndpl.Length = 44 lHandle = FindWindow(vbNullString, sAppName) If lHandle = 0 Then Exit Sub 'Get the window's state and activate it. lState = GetWindowPlacement(lHandle, lpwndpl) Select Case lpwndpl.showCmd Case SW_SHOWMINIMIZED Call ShowWindow(lHandle, SW_RESTORE) Case SW_SHOWNORMAL, SW_SHOWMAXIMIZED Call ShowWindow(lHandle, SW_SHOW) End Select Call SetForegroundWindow(lHandle)End Sub Private Sub Timer1_Timer() Dim lHandle As Long, lProcessId As Long, lThreadId As Long, lStrLen As Long Dim sText As String ' Get the cursor's coordinates. ' Get the handle of the window at those coordinates. lStrLen = MAX_PATH Call GetCursorPos(CursorLoc) lHandle = WindowFromPoint(CursorLoc.x, CursorLoc.y) ' Get the window's caption. sText = Space$(MAX_PATH) Call GetWindowText(lHandle, sText, lStrLen) Label1 = Left$(sText, lStrLen) ' Get the window's process and thread ID. lThreadId = GetWindowThreadProcessId(lHandle, lProcessId) Label2 = CStr(lProcessId)End Sub