| Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате |
| Форум программистов > Delphi: WinAPI и системное программирование > WM_GETTEXT |
| Автор: fishca 13.8.2002, 02:18 |
| var lpszText : string; В программе создаю текстовое поле FileNameText := CreateWindowsEx(...); Потом пытаюсь написать SendMessage(FileNameText,20,LPARAM(lpszText)); т.е. пытаюсь получить текст текстового поля, врезультате Access Violation, что не так подскажите пожалуйста! |
| Автор: FdX 13.8.2002, 02:39 |
| Если мне не изменяет память, начиная с Дельфи 2.0 string очень похож на LPSZ, но там ещще хранится гдето длина строки. Пиши так: var Text:Array[0..MaxLengthOfYourText] of Char; lpszText:String; дальше пишешь примерно так: SendMessage(FileNameText,20,LPARAM(@Text)); lpzsText:=StrPas(@Text); @Text представляет из себя PChar я это не проверял, но должно работать |
| Автор: Fantasist 13.8.2002, 03:17 |
| Что-то у вас в SendMessage параметров мало. Ну это не главное. String в Delphi это Ansi строка, а ее начало находиться в первом символе этой строки. SetLength(s,20); SendMessage(Handle,WM_GETTEXT,20,Longint(@s[1])); |
| Автор: rhf 13.8.2002, 07:43 |
| а лучше все делать точно, сначала проверить длину текста setLength(lpszText,sendMessage(h,WM_GETTEXTLENGTH,0,0)+1); или setLength(lpszText,getWindowTextLength(handle)+1); а затем получить текст sendMessage(h,WM_GETTEXT,wParam(length(lpszText)),lParam(@lpszText[1])); или sendMessage(h,WM_GETTEXT,wParam(length(lpszText)),lParam(pChar(lpszText)); |
| Автор: skinny 19.2.2004, 15:03 |
| Спасибо пацаны мне вы очень помогли |
| Автор: Guest 18.10.2004, 09:49 |
| Хм. Если я не ошибаюсь, то у функции SendMessage 4 параметра, здесь ( "SendMessage(FileNameText,20,LPARAM(lpszText));" ) я вижу только 3 The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message. The PostMessage function, in contrast, posts a message to a thread's message queue and returns immediately. LRESULT SendMessage( HWND hWnd, // handle of destination window UINT Msg, // message to send WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ); Parameters hWnd Identifies the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows. Msg Specifies the message to be sent. wParam Specifies additional message-specific information. lParam Specifies additional message-specific information. Return Values The return value specifies the result of the message processing and depends on the message sent. Remarks Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a unique message for inter-application communication. If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, Windows switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The sending thread is blocked until the receiving thread processes the message. Как говорится "все это и многое другое" Вы найдете в файле "win32.hlp", там описано все, что связано с Win32 API! |