-
December 8th, 2008, 07:28 AM
#1
using handles to get RichEdit text
Hi there,
I'm trying to get the text from two RichEdit controls which are located in external application, but I can't get the the text with GetWindowText. What is my mistake?
Any help would be much appreciated... Thanks in advance.
Here's the code:
#include <iostream>
#include <fstream>
#include <Windows.h>
#include <Winuser.h>
using namespace std;
HWND hwndApp;
HWND hwndRichEditControl1 ;
HWND hwndRichEditControl2;
void GetWindowAndControls(){
// get the handle for the application, works fine
hwndApp= FindWindow(NULL, L"MyExternalApplication");
// get the handles for the two RichEdit controls, works ok (tested with winID).
hwndRichEditControl1 = FindWindowEx(hwndApp, NULL, L"WindowsForms10.RichEdit20W.app.0.33c0d9d", NULL);
hwndRichEditControl2= FindWindowEx(hwndApp, hwndRichEditControl1, L"WindowsForms10.RichEdit20W.app.0.33c0d9d", NULL);
}
void main()
{
// declare the strings
TCHAR txtApp[10], txt1[10], txt2[10];
// get the application handle and the rich edit handles
GetWindowAndControls();
// this works fine, and get the text from main window
::GetWindowText(hwndApp, txtApp, 10);
// this doesn't work - doesn't get text from RichEdit controls inside main window
//Why? How can I make it work?
::GetWindowTextW(hwndRichEditControl1 , txt1, 10);
::GetWindowTextW(hwndRichEditControl2 , txt2, 10);
}
-
December 8th, 2008, 08:11 AM
#2
Re: using handles to get RichEdit text
Read MSDN on GetWindowText () ...
-
December 8th, 2008, 09:41 AM
#3
Re: using handles to get RichEdit text
I know GetWindowText doesn't work with controls.
That's why I'm asking what function I CAN use for this purpose.
-
December 8th, 2008, 10:09 AM
#4
Re: using handles to get RichEdit text
Originally Posted by fred100
Read MSDN on GetWindowText () ...
I tried using the SendMessage:
char txt[512]="";
::SendMessage(hwndRichEditControl1 ,WM_GETTEXT,512,(LPARAM)txt);
But even this doesn't work.. any ideas?
I'm using winID to watch this control and I can see the text under "Title" property.
Its class is WindowsForms10.RichEdit20W.app.0.33c0d9d.
Why can't I retrieve the text with SendMessage(..., WM_GETTEXT, ...)??
-
December 11th, 2008, 03:24 AM
#5
Re: using handles to get RichEdit text
I solved the problem with
TCHAR txt[32]=L"";
::SendMessage(hwndRichEdit, WM_GETTEXT, 32, (LPARAM)txt);
It seems that the class type wasn't correct:
It suppose to be TCHAR and not char class, and must be converted to LPARAM.
Ok, the thread can be closed now.
-
December 11th, 2008, 09:37 AM
#6
Re: using handles to get RichEdit text
You may want to change the method that you are using to declare your txt variable. You are mixing the TCHAR support (a Microsoft invention which allows building applications which support multiple character set widths) with a direct literal wide string.
You used the following to declare txt:
TCHAR is substituted with either wchar_t or char (depending on what the character set option is for the project). The right side (L"") requests an empty wide string (each character is a wchar_t).
Since this compiles, your character set must be set to Unicode. If you set your character set to Multi-Byte, this would produce a compile error.
If you need to support building the source using both settings, then the following could be used:
Code:
#include <tchar.h>
TCHAR txt[32]=_T("");
If you are only going to build the source with one setting for character set, then the following would work for unicode:
Code:
wchar_t txt[32]=L"";
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|