从其他应用程序获取文本.文本框EM_GETLINE返回0 [英] Getting text from another apps. textbox EM_GETLINE returns 0

查看:135
本文介绍了从其他应用程序获取文本.文本框EM_GETLINE返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我对EM_GETLINE有问题.我有一个文本框,我想从中提取文本.该框始终保持更新(它是一个日志文件,然后不断更新,最后一条消息位于底部).我只想要最后一行.

我的代码:




Hello !

I''m having a problem with EM_GETLINE. I have a textbox I want to extract the text from. The box keeps updating all the time (it''s a log file thet keeps updating, last message at the bottom). All I want is that very last line.

My code:




HWND hwnd = (HWND)0x00050440;
		char display[256];
	    LONG lResult;
		TCHAR  tszString[256];
	    
		/*
		TCHAR param[256];
		lResult = SendMessage( hwnd, WM_GETTEXT, 500, (LPARAM)param);
		*/
		
		//Find out the number of lines in the textbox
		int nLines = SendMessageW(hwnd, EM_GETLINECOUNT, 0, 0)-1;
		
		lResult = SendMessageW( hwnd, EM_GETLINE, nLines, (LPARAM)tszString); 
	    
		//Find out how many characters are collected ERROR: Returns 0 ??
		int nLength = SendMessageW(hwnd, EM_GETLINE, (WPARAM)nLines, (LPARAM)tszString);
		
		//Adding the string terminating NULL
		tszString[nLength] = ''\0'';  
		
		wcstombs(display, tszString, 256);
	    //wcstombs(display, param, 256);
	    printf( " %s\n", display );




我一直为nLength得到0. MSDN之所以这么说,是因为我处理的行号大于在文本框中找到的行.事实并非如此.
句柄是正确的,当使用GETTEXT时,我从框中获取了所有文本. (在记事本上测试...)
我不确定是否正确初始化了缓冲区.
MSDN:在发送消息之前,将此缓冲区的第一个字设置为该缓冲区的大小(以TCHAR为单位)." :confused:
现在结果是一个空的控制台.无文字...:((<
我在项目中将Unicode设置为字符集,这可能是个问题吗?

问候
SH




I keep getting 0 for nLength. MSDN say thats because I adress a linenumber larger than lines found in the textbox. Thats not the case.
The handle is correct, when using GETTEXT I get all the text from the box. ( Testing it on notepad...)
I''m not sure if I have initialized the buffer correct.
MSDN: "Before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer." :confused:
Right now the result is a empty console. No text... :((

I have Unicode set as characterset in my project, could that be a problem?

Regards
SH

推荐答案

您拥有解决方案:在发送消息之前,将此缓冲区的第一个字设置为TCHAR的大小(以TCHAR为单位).缓冲.

然后,尝试以下操作:

You have the solution in your hands: before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer.

Then, try this:

*reinterpret_cast<WORD *>(tszString) = _countof(tszString);
int nLength = SendMessage(hWnd, EM_GETLINE, nLines, (LPARAM)tszString);


这篇关于从其他应用程序获取文本.文本框EM_GETLINE返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆