Страница: 1 |
Вопрос: Выделенный текст и работа с ним | Добавлено: 20.02.04 22:52 |
Автор вопроса: ![]() |
Программа на VB6.0 должна получить строку которуя выделили мышью в любом виндовом редакторе (Word, Notepad и др.). В буфер обмена строка не копировалась просто выделялась. |
Ответы | Всего ответов: 6 |
Номер ответа: 1 Автор ответа: ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ICQ: 8068014 Вопросов: 18 Ответов: 817 |
Web-сайт: Профиль | Цитата | #1 | Добавлено: 21.02.04 11:13 |
Самый простой вариант послать нажатия Control+C. Делается так: Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Const KEYEVENTF_KEYUP = &H2 Call keybd_event(vbKeyControl, 0, 0, 0) Call keybd_event(vbKeyC, 0, 0, 0) Call keybd_event(vbKeyC, 0, KEYEVENTF_KEYUP, 0) Call keybd_event(vbKeyControl, 0, KEYEVENTF_KEYUP, 0) Если чё не так напиши, а то я тороплюсь |
Номер ответа: 2 Автор ответа: ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Лидер форума ICQ: 216865379 Вопросов: 106 Ответов: 9979 |
Web-сайт: Профиль | Цитата | #2 | Добавлено: 21.02.04 15:40 |
Используй SendMessage ByVal h, EM_GETSEL, VarPtr(nMin), nMax для получения первой и последней позиции выделения. |
Номер ответа: 3 Автор ответа: ![]() ![]() ![]() ![]() ![]() ![]() Разработчик Offline Client ICQ: 233286456 Вопросов: 34 Ответов: 5445 |
Web-сайт: Профиль | Цитата | #3 | Добавлено: 21.02.04 18:09 |
Как предлгает Sharp, оно конечно правильней, но вот проблемма: Как узнать hWnd/ID того самого контрола, на котором стоит фокус ??? |
Номер ответа: 4 Автор ответа: ![]() ![]() Вопросов: 1 Ответов: 1 |
Web-сайт: Профиль | Цитата | #4 | Добавлено: 22.02.04 07:46 |
Мне обязательно необходимо решение задачи чтобы создать программу для людей с ослабленным зрением. Я попробую все варианты которые мне предложили и еще может предложат.Спасибо. Как опробую обязательно кину сообщение на форум с исходником.Для тех кто только думает помочь мне в решении моей задачи двери всегда открыты принимаю любые варианты.Жду новых решений.Спасибо. |
Номер ответа: 5 Автор ответа: ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ICQ: 8068014 Вопросов: 18 Ответов: 817 |
Web-сайт: Профиль | Цитата | #5 | Добавлено: 22.02.04 12:33 |
Вот пример, как достать текст из любого окна. Сделан не мной. Можно поптаться переделать под свои нужды. Я попробовал, но у меня не получилось. Может sne и Sharp помогут??? 'to get the foreground window Private Declare Function GetForegroundWindow Lib "user32" () As Long 'to send a message system Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long 'to get the cursor position Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long 'to get the window from a point (y,x) Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long 'to get the window text Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long 'to get the class name (edit,combobox etc..) Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long Public strBuffer As String ' the string to append to the file that has all the text "grabed" Public iEnum As Integer ' the file integer to open and write (I/O) Public hJanelaCima As Long ' the window wich the user has the mouse over Public hJanelaAntiga As Long ' the ancient window, to controlo if thereґs a new window or not 'constants to grab the text Private Const WM_GETTEXT = &HD Private Const WM_GETTEXTLENGTH = &HE 'type for the GetCursorPos API Private Type POINTAPI x As Long y As Long End Type Private Sub Form_Load() 'when starting the program, print date and time of the new logging... strBuffer = "=============================================================" & vbCrLf strBuffer = strBuffer & "Date of log: " & Format(Date, "YYYY-MM-DD") & vbCrLf strBuffer = strBuffer & "Started logging at: " & Format(Time$, "HH:MM") & vbCrLf strBuffer = strBuffer & "=============================================================" & vbCrLf iEnum = FreeFile 'append it in the file Open "C:\testes.txt" For Append As #iEnum Print #iEnum, strBuffer Close #iEnum strBuffer = "" 'enable the timer... Timer1.Interval = 100 Timer1.Enabled = True End Sub Private Sub Timer1_Timer() Dim ptCursor As POINTAPI ' the cursor type variable Dim texto_janela As String ' the window text Dim rc As Long Dim nome_classe As String ' the class name Dim fenster As Long ' the foreground window.. in deutsh.. ich wisse deutshe auch... fenster = GetForegroundWindow ' get the window where user is 'create string objects texto_janela = String(100, Chr(0)) nome_classe = String(100, Chr(0)) Call GetCursorPos(ptCursor) ' get the cursor position 'get the window(handle) where the user has the mouse hJanelaCima = WindowFromPoint(ptCursor.x, ptCursor.y) 'get the window text and class name rc = GetWindowText(fenster, texto_janela, Len(texto_janela)) rc = GetClassName(hJanelaCima, nome_classe, 100) 'format the assholes... texto_janela = Left(texto_janela, InStr(texto_janela, Chr(0)) - 1) nome_classe = Left(nome_classe, InStr(nome_classe, Chr(0)) - 1) Debug.Print nome_classe ' check the class names... i tried some like WinWord and VB, but didnґt worked.. 'If nome_classe = "Edit" Or nome_classe = "_WwG" Or nome_classe = "Internet Explorer_Server" Or nome_classe = "RichEdit20A" Or nome_classe = "VbaWindow" Then 'if this is the same window, forget If hJanelaCima = hJanelaAntiga Then Exit Sub 'thereґs no text? Out! If WindowText(hJanelaCima) = Empty Then Exit Sub 'put the ancient window handle, with the current one hJanelaAntiga = hJanelaCima 'build string with time and the text grabed with WindowText strBuffer = Time$ & " - " & texto_janela & vbCrLf strBuffer = strBuffer & WindowText(hJanelaCima) & vbCrLf 'append to the file Open "C:\testes.txt" For Append As #iEnum Print #iEnum, strBuffer Close #iEnum 'End If End Sub 'grab the text window with this function.. argument- the window handle Public Function WindowText(window_hwnd As Long) As String Dim txtlen As Long Dim txt As String If window_hwnd = 0 Then Exit Function 'send the message to get the text lenght txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, 0) If txtlen = 0 Then Exit Function txtlen = txtlen + 1 txt = Space$(txtlen) 'send the message to get the text txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByVal txt) 'put that on the function WindowText = Left$(txt, txtlen) End Function |
Номер ответа: 6 Автор ответа: ![]() ![]() ![]() ![]() ![]() ![]() Разработчик Offline Client ICQ: 233286456 Вопросов: 34 Ответов: 5445 |
Web-сайт: Профиль | Цитата | #6 | Добавлено: 22.02.04 23:21 |
В общем-то пример этот переделать можно без труда, теоретически, но проблемма все же одна всплывает, а именно, этот пример - для текстового поля (Edit'a) но ведь текст так же может содержаться и в RichEdit'e и в ComboBox'e, и т.д., т.е. придется создавать обработчик ошибок и методом тыка исследовать что перед нами, посылая соответствующие константы, вот на пример для RichEdit'a это - EM_GETSELTEXT |
Страница: 1 |
|