在winapi中将字符串打印到屏幕 [英] printing string to the screen in winapi

查看:77
本文介绍了在winapi中将字符串打印到屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅能与winapi一起工作,我不确定如何处理某些东西.我在这里的目标是拥有一个控件,该控件可以像命令提示符一样简单地将内容打印到屏幕上.例如,我希望能够拥有一个仅将字符串添加到打印输出上而不是在每次调用时替换文本的功能.第一个问题,我应该只是尝试制作一个全新的控件来将文本打印到屏幕上的行,还是应该尝试修改或子类化EDIT控件?第二个问题,我宁愿不要只输入一个大字符串,每次输入文本时我都会将其连接并重绘,但是还有其他方法吗?

另外,我是不是从积雪堆里爬山,而只是忽略了一个能做到这一点的通用控件?

just working stuff with winapi, and i''m not sure how to approach something. my goal here is to have a control that will simply print things to the screen just like a command prompt would. for example, i would like to be a able to have a function that would very simply just add a string onto a printout rather than replace the text every call. first question, should i just try to make a brand new control that prints text to the screen in lines, or should i try modifying or subclassing the EDIT control? second quesiton, I would rather not do this with just one massive string which i would concat strings to and redraw everytime text is entered, but is there any other way?

Also, am i making mountains out of molehills and just overlooking a common control that does just this?

推荐答案

不,我认为您不会发现一些问题众所周知的控件可以执行此操作,仅因为此任务是非常不寻常的.您需要从头开始.对于任何Windows对象,都没有所谓的屏幕"术语.您必须输入桌面,这是一个普通的窗口.您列出的方法均无济于事.如果使用EDIT控件,那将是一个非常普通的Windows应用程序的开发.如果这是您需要的,请在这里停止.

如果您真的想使用台式机;这不是那么容易.首先,使用功能GetDesktopWindow找到桌面的HWND.比使用SetWindowLong以及桌面HWND的第一个参数和GWL_WNDPROC的第二个参数注入新的Windows过程.不要忘记使用SetWindowLong获取所有Windows过程-您将需要它来实现您的过程.修改消息WM_PAINT的处理.现在,您需要组织一些虚拟屏幕",以反映命令解释器的所有文本输入/输出.在WM_PAINT的处理程序中,将虚拟屏幕"渲染到桌面图形上.模拟文本插入符;您可能需要使用计时器来模拟闪烁.每次更改都需要调用Invalidate,这将触发发送新的WM_PAINT并重新渲染.您可能想使用InvalidateRectInvalidateRgn通过仅使一部分场景无效来提高性能.

对于命令解释器,您可以使用可用的"CMD.EXE",只有您需要将所有输出(stderrstdoutput)重定向到自定义流,以便在桌面渲染过程中对其进行处理.您可以简单地回显您的输入,并通过Invalidate将其放置到重定向的stdoutput中.

这一切都是可行的,但需要足够的耐心和对细节的关注.好运动!

—SA
No, I don''t think you will find some well-known control to do this, simply because this task is quite unusual. You need to do it from scratch. There is no such thing as "screen" it terms of any Windows object. You have to type in the desktop, which is a normal window. None of the approaches you listed can help. If you use EDIT control, it would be pretty much developing of a quite usual Windows application. If this is what you need, stop here.

If you really want to work with the desktop; it''s not so easy. First, find the HWND of the desktop using the function GetDesktopWindow. Than inject new Windows procedure using SetWindowLong with the first parameter of desktop HWND and second parameter of GWL_WNDPROC. Don''t forget to get all Windows procedure using SetWindowLong — you will need it to implement yours. Modify processing of the message WM_PAINT. Now, you need to organize some "virtual screen" which will reflect all text input/output of your command interpreter. In your handler of WM_PAINT provide rendering of your "virtual screen" onto desktop graphics. Simulate text caret; you may need to use timer to simulate blinking. Every change will need a call to Invalidate which will trigger sending of new WM_PAINT and re-rendering. You may want to use InvalidateRect or InvalidateRgn to improve performance by invalidating only a part of the scene.

For a command interpreter you can use available "CMD.EXE", only you will need to redirect all output (stderr and stdoutput) to your custom streams to process them in your desktop rendering procedure. Your input you can simply echo and put to redirected stdoutput via Invalidate.

This is all is quite doable but will take good amount of patience and attention to detail. Good exercise!

—SA


这篇关于在winapi中将字符串打印到屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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