将数据发送到桌面上打开的记事本文件 [英] sending data to opened notepad file in desktop

查看:71
本文介绍了将数据发送到桌面上打开的记事本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以mfc应用程序,将文本数据发送到桌面上打开的记事本文件吗?(实时

传输数据)。任何人都可以提供帮助

can mfc application, send text data to opened notepad file in desktop?(live
transfer of data) . can anybody help

推荐答案

" Sandy" <萨*** @ discussions.microsoft.com>在消息中写道

新闻:FD ********************************** @ microsof t.com ...
"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
可以mfc应用程序,在桌面上发送文本数据到打开的记事本文件吗?(实时传输数据)。任何人都可以帮忙
can mfc application, send text data to opened notepad
file in desktop?(live transfer of data) . can anybody help




我不确定我是否理解你问题的关键所在。是如何操作记事本或如何进行数据传输?


前一个问题很容易回答。这个小黑客将完成这项工作。它是
是一个命令行应用程序,其第一个参数是你想要传递文本的记事本实例的标题(标题)



秒是文本本身。如果其中任何一个包含空格你需要引用

它。


#include< windows.h>

#包括< iostream>


int main(int argc,char ** argv)

{

HWND hNotepad,hEdit;


if(argc!= 3)

{

std :: cout<< 输入xxx \title \" \" text\"" << std :: endl;

std :: cout<< "其中title是记事本窗口的标题 <<

std :: endl;

std :: cout<< "和text是要插入的文本 << std :: endl;

}


hNotepad = FindWindow(" Notepad",argv [1]);


if(hNotepad == 0)

{

std :: cout<< 无法找到记事本的主窗口 << std :: endl;

退出(0);

}


hEdit = FindWindowEx(hNotepad,NULL," edit" ;,NULL);


if(hEdit == 0)

{

std :: cout<< 无法找到记事本的编辑控件 << std :: endl;

退出(0);

}


SendMessage(hEdit,WM_SETTEXT,0,(LPARAM) argv [2]);


返回0;

}


如果您询问实时数据传输一般来说,答案可能是b $ b(并且已经)填满整本书。上面的例子使用Windows来完成

繁重的工作 - 它的WM_SETTEXT消息用于将字符数据

移动到一个Window中。如果你想将除文本以外的东西移动到某个窗口以外的某些东西,那么除了窗口之外还会发布一些更多细节。


问候,





I''m not sure if I understand what the crux of your question is. Is it how to
manipulate Notepad or how to do data transfer?

The former question is easy to answer. This little hack will do the job. It
is a command line application whose first parameter is the title (caption)
of the instance of Notepad to which you want to deliver the text and the
second is the text itself. If either contains spaces you''ll need to quote
it.

#include <windows.h>
#include <iostream>

int main(int argc, char **argv)
{
HWND hNotepad, hEdit;

if ( argc != 3 )
{
std::cout << "Enter xxx \"title\" \"text\"" << std::endl;
std::cout << " where title is the caption of Notepad''s window" <<
std::endl;
std::cout << " and text is the text you want to insert" << std::endl;
}

hNotepad = FindWindow("Notepad", argv[1]);

if ( hNotepad == 0 )
{
std::cout << "Failed to find Notepad''s main window" << std::endl;
exit(0);
}

hEdit = FindWindowEx(hNotepad, NULL, "edit", NULL);

if ( hEdit == 0 )
{
std::cout << "Failed to find Notepad''s edit control" << std::endl;
exit(0);
}

SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM) argv[2]);

return 0;
}

If you are asking about live data transfer in general then the answer could
(and has) filled entire books. The example above uses Windows to do the
heavy lifting - its WM_SETTEXT message is designed to move character data
into a Window. If you want to move something other than text to something
other than a window post some more details for some ideas.

Regards,
Will


亲爱的威廉


1.假设abc.txt(记事本)文件已经在桌面上打开了。

2.我的VC ++ 6 mfc,应用程序想要在abc.txt中写入数据。


示例...当你打开abc.txt然后...在记事本中有5行文字,

然后新数据应显示在第6行...第6行进来

记事本被用户看到。第6行数据来自你的vc ++ appln。


谢谢


" William DePalo [MVP VC ++]"写道:
Dear William

1. Suppose "abc.txt"(notepad) file is already open in desktop.
2. My VC++6 mfc, application wants to write the data in abc.txt.

example...when u open abc.txt then... in notepad there are 5line of text ,
then new data should be display in 6th line... that 6th line coming in
notepad is seen by user. that 6th line data is coming from your vc++ appln.

Thanks

"William DePalo [MVP VC++]" wrote:
" Sandy" <萨*** @ discussions.microsoft.com>在消息中写道
新闻:FD ********************************** @ microsof t.com。 ..
"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
可以mfc应用程序,在桌面上发送文本数据到打开的记事本文件吗?(实时传输数据)。任何人都可以帮忙
can mfc application, send text data to opened notepad
file in desktop?(live transfer of data) . can anybody help



我不确定我是否理解你问题的症结所在。是如何操作记事本或如何进行数据传输?

前一个问题很容易回答。这个小黑客将完成这项工作。它是一个命令行应用程序,其第一个参数是您要传递文本的记事本实例的标题(标题)
,其次是文本本身。如果任何一个包含空格,你需要引用它。

#include< windows.h>
#include< iostream>
int main(int argc,char ** argv)
{
HWND hNotepad,hEdit;

if(argc!= 3)
{
std :: cout<< 输入xxx \title \" \" text\"" << std :: endl;
std :: cout<< "其中title是记事本窗口的标题 <<
std :: endl;
std :: cout<< "和text是要插入的文本 << std :: endl;
}

hNotepad = FindWindow(" Notepad",argv [1]);

if(hNotepad == 0)
{
std :: cout<< 无法找到记事本的主窗口 << std :: endl;
exit(0);
}

hEdit = FindWindowEx(hNotepad,NULL," edit",NULL);
if(hEdit == 0)
{
std :: cout<< 无法找到记事本的编辑控件 << std :: endl;
exit(0);
}
发送消息(hEdit,WM_SETTEXT,0,(LPARAM)argv [2]);

返回0;
}
如果您一般都在询问实时数据传输,那么答案可以(并且已经)填满整本书。上面的例子使用Windows来进行繁重的工作 - 它的WM_SETTEXT消息用于将字符数据移动到Window中。如果你想将除文本以外的东西移动到窗口以外的其他东西上,可以发布一些想法的更多细节。

问候,



I''m not sure if I understand what the crux of your question is. Is it how to
manipulate Notepad or how to do data transfer?

The former question is easy to answer. This little hack will do the job. It
is a command line application whose first parameter is the title (caption)
of the instance of Notepad to which you want to deliver the text and the
second is the text itself. If either contains spaces you''ll need to quote
it.

#include <windows.h>
#include <iostream>

int main(int argc, char **argv)
{
HWND hNotepad, hEdit;

if ( argc != 3 )
{
std::cout << "Enter xxx \"title\" \"text\"" << std::endl;
std::cout << " where title is the caption of Notepad''s window" <<
std::endl;
std::cout << " and text is the text you want to insert" << std::endl;
}

hNotepad = FindWindow("Notepad", argv[1]);

if ( hNotepad == 0 )
{
std::cout << "Failed to find Notepad''s main window" << std::endl;
exit(0);
}

hEdit = FindWindowEx(hNotepad, NULL, "edit", NULL);

if ( hEdit == 0 )
{
std::cout << "Failed to find Notepad''s edit control" << std::endl;
exit(0);
}

SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM) argv[2]);

return 0;
}

If you are asking about live data transfer in general then the answer could
(and has) filled entire books. The example above uses Windows to do the
heavy lifting - its WM_SETTEXT message is designed to move character data
into a Window. If you want to move something other than text to something
other than a window post some more details for some ideas.

Regards,
Will



你好!


有一个小小的误解。将数据写入''abc.txt''与将数据写入记事本的编辑控件是不一样的。


要破解记事本,使用William发布的代码片段。但在发送

WM_SETTEXT之前,请发送WM_GETTEXT,它将在记事本的编辑控件上检索当前写入的文本

。然后到这个本地字符串,附加你想要写的结果(第6行)并使用WM_SETTEXT来更新

记事本中的更改。这个结果是记事本中出现的新行的效果,

虽然你实际做的是重写编辑

控件的全部内容。


请注意,记事本不会将更改保存到''abc.txt'中,除非您单独指定(通过UI或发送其他消息)
来保存文件。

上面概述的过程只会更新记事本的

编辑控件中显示的文字。除非明确保存更改,否则它不会影响实际文件。


-Antti Keskinen

" Sandy" <萨*** @ discussions.microsoft.com>在消息中写道

新闻:79 ********************************** @ microsof t.com ...
Hello !

There is a small misunderstanding. Writing data to ''abc.txt'' is not the same
thing as writing data to Notepad''s edit control.

To hack Notepad, use the code piece that William posted. But before sending
WM_SETTEXT, send WM_GETTEXT, which will retrieve the currently written text
on Notepad''s edit control. Then to this local string, append the results you
want to write (the 6th line) and use WM_SETTEXT to update changes in
Notepad. This result is an effect of ''new line appearing in Notepad'',
although what you actually did was rewrite the entire contents of the edit
control.

Note that Notepad will not save the changes into ''abc.txt'' unless you
command it seperately (via UI or sending another message) to save the file.
The process outlined above will only update the text displayed in Notepad''s
edit control. It will not affect the actual file unless changes are
explicitly saved.

-Antti Keskinen
"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
亲爱的威廉

1.假设桌面已打开abc.txt(记事本)文件。
2.我的VC ++ 6 mfc,应用程序想在abc.txt中写入数据。

例子......当你打开abc.txt然后...在记事本中有5行文字

然后新数据应显示在第6行...用户可以看到记事本中的第6行。第6行数据来自您的vc ++
应用程序。

William DePalo [MVP VC ++]"写道:
Dear William

1. Suppose "abc.txt"(notepad) file is already open in desktop.
2. My VC++6 mfc, application wants to write the data in abc.txt.

example...when u open abc.txt then... in notepad there are 5line of text
,
then new data should be display in 6th line... that 6th line coming in
notepad is seen by user. that 6th line data is coming from your vc++
appln.

Thanks

"William DePalo [MVP VC++]" wrote:
" Sandy" <萨*** @ discussions.microsoft.com>在消息中写道
新闻:FD ********************************** @ microsof t.com。 ..
"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
>可以mfc应用,发送文本数据到打开的记事本
>桌面文件?(实时数据传输)。任何人都可以帮忙
> can mfc application, send text data to opened notepad
> file in desktop?(live transfer of data) . can anybody help



我不确定我是否理解你问题的症结所在。是如何操作记事本或如何进行数据传输?

前一个问题很容易回答。这个小黑客将完成这项工作。
它是一个命令行应用程序,其第一个参数是你想要传递的记事本实例的标题
(标题)
文本和第二个是文本本身。如果任何一个包含空格,你需要引用它。

#include< windows.h>
#include< iostream>
int main(int argc,char ** argv)
{
HWND hNotepad,hEdit;

if(argc!= 3)
{
std :: cout<< 输入xxx \title \" \" text\"" << std :: endl;
std :: cout<< "其中title是记事本窗口的标题 <<
std :: endl;
std :: cout<< "和text是要插入的文本 << std :: endl;
}

hNotepad = FindWindow(" Notepad",argv [1]);

if(hNotepad == 0)
{
std :: cout<< 无法找到记事本的主窗口 << std :: endl;
exit(0);
}

hEdit = FindWindowEx(hNotepad,NULL," edit",NULL);
if(hEdit == 0)
{
std :: cout<< 无法找到记事本的编辑控件 << std :: endl;
exit(0);
}
发送消息(hEdit,WM_SETTEXT,0,(LPARAM)argv [2]);

返回0;
}
如果您一般都在询问实时数据传输,那么答案可能会(或已经)填满整本书。上面的例子使用Windows来进行繁重的工作 - 它的WM_SETTEXT消息用于将字符数据移动到Window中。如果你想将除文本以外的东西移动到窗口以外的其他东西上,可以发布一些想法的更多细节。

问候,



I''m not sure if I understand what the crux of your question is. Is it how
to
manipulate Notepad or how to do data transfer?

The former question is easy to answer. This little hack will do the job.
It
is a command line application whose first parameter is the title
(caption)
of the instance of Notepad to which you want to deliver the text and the
second is the text itself. If either contains spaces you''ll need to quote
it.

#include <windows.h>
#include <iostream>

int main(int argc, char **argv)
{
HWND hNotepad, hEdit;

if ( argc != 3 )
{
std::cout << "Enter xxx \"title\" \"text\"" << std::endl;
std::cout << " where title is the caption of Notepad''s window" <<
std::endl;
std::cout << " and text is the text you want to insert" << std::endl;
}

hNotepad = FindWindow("Notepad", argv[1]);

if ( hNotepad == 0 )
{
std::cout << "Failed to find Notepad''s main window" << std::endl;
exit(0);
}

hEdit = FindWindowEx(hNotepad, NULL, "edit", NULL);

if ( hEdit == 0 )
{
std::cout << "Failed to find Notepad''s edit control" << std::endl;
exit(0);
}

SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM) argv[2]);

return 0;
}

If you are asking about live data transfer in general then the answer
could
(and has) filled entire books. The example above uses Windows to do the
heavy lifting - its WM_SETTEXT message is designed to move character data
into a Window. If you want to move something other than text to something
other than a window post some more details for some ideas.

Regards,
Will



这篇关于将数据发送到桌面上打开的记事本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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