| |

VerySource

 Forgot password?
 Register
Search
View: 1036|Reply: 4

Failed to get text using SendMessage! Please help me look at it

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-20 11:20:02
| Show all posts |Read mode
Part of the code is as follows:

struct CHARRANGE
{
long cpMin;
long cpMax;
}

struct TEXTRANGE
{
CHRANGE chrg;
string lpstrText;
}

CHARRANGE CR;
TEXTRANGE TR = new TEXTRANGE ();

IntPtr hWndOutPut = FindWindowEx (MainWindowHandle, IntPtr.Zero, "RICHEDIT", "");

int lineCount = SendMessage (hWndOutPut, EM_GETLINECOUNT, 0, ref TR);
int lc = SendMessage (hWndOutPut, EM_LINELENGTH, 0, ref TR);
int charFrom = SendMessage (hWndOutPut, EM_LINEINDEX, lineCount-1, ref TR);
int charEnd = charFrom + lc;

CR.cpMin = charFrom;
CR.cpMax = charEnd;
TR.chrg = CR;
TR.lpstrText = new String ('\0', 10240);

SendMessage (hWndOutPut, EM_GETTEXTRANGE, 0, ref TR);

[DllImport ("user32.dll")]
public static extern int SendMessage (IntPtr hwnd, int wMsg, int wParam, ref TEXTRANGE lParam);

Among them, MainWindowHandle is the handle of the main window of another program. After obtaining one of the handles of RichEdit, you want to get the text in it.
But lpstrText in TR is empty after SendMessage is executed. Please help me to find out what is wrong.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-30 19:45:02
| Show all posts
MainWindowHandle
Is it the correct value?
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-31 01:45:01
| Show all posts
Checked with spy ++, it is correct
The number of lines to fetch text is also correct
Reply

Use magic Report

1

Threads

15

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-1-31 17:09:01
| Show all posts
I would like to ask the master, why don't you first overwrite the winproc function, receive the message and then assign it to the place you need?
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-2-1 21:45:01
| Show all posts
Quote: I would like to ask the master, why don't you ask for the message by reloading the winproc function first, and then assign it to the place you need?

Soon after I learned C #, I didn't understand what you meant. How to overload winproc? What's the effect?
Thank you
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list