使用C和Win32 API将文件内容打印到Win32窗口中 [英] print contents of a file onto a win32 window using C and Win32 api

查看:327
本文介绍了使用C和Win32 API将文件内容打印到Win32窗口中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我要做的就是以下操作.

问题:
-------
打开文件,
读取前30个字符,
显示在窗口上(WM_PAINT处理程序)

问题:
-----
当我在输出窗口上看到...时,它会打印一些中文文本.

您能否建议一种打开文本文件,然后在Win32 GUI窗口上打印前10个字符的方法.

根据情况,我正在执行以下任务.

1.创建一个GUI窗口
2.在LRESULT CALLBACK WndProc中的WM_CREATE处理程序中,我正在尝试打开文本文件.
3.在WM_PAINT处理程序中,我试图使用ReadFile函数读取文件以获取数据的前10个字节
4.最后,我尝试将其打印在屏幕上.

出于学习目的,我正在尝试进行这些活动.

请帮忙.

Hi ,
All I am trying to do is the following.

Problem:
-------
Opening a file,
read first 30 characters,
display on to a window (WM_PAINT handler)

Issue:
-----
When i see on the output window....it prints some chinese text.

Can you please suggest a method of opening a text file and then print first 10 characters onto a win32 GUI window.

According to the situation, I am doing the following tasks.

1. Create a GUI window
2. in LRESULT CALLBACK WndProc, in WM_CREATE handler, I am trying to open the text file.
3. in WM_PAINT handler, I am trying to read file using ReadFile function to fetch first 10 bytes of data
4. finally I am trying to print it on screen.

For learning purpose I am trying to do these activities.

Please help.

推荐答案

2.不要在WM_CREATE处理程序中打开文件,但稍后再执行此操作,或者响应用户命令(菜单或工具栏按钮)打开文件.当您打开文件时,您应该将数据读入程序内部的某个结构,然后关闭文件-不再需要它.您还应该确保正确处理了文本编码.参见我的提示 [
2. Don''t open your file in the WM_CREATE handler, but do this later, or in response to a user command (menu or toolbar button). When you open the file you should read the data into some structure internal to the program, and then close the file - it''s no longer needed. You should also ensure that you are handling the text encoding properly; see my tip[^] for more details.

3. In your WM_PAINT handler you should only paint the text that you have captured from the file; do not try reading the file in this handler. Again you should be using the correct text encoding and fonts to paint your text.


这篇关于使用C和Win32 API将文件内容打印到Win32窗口中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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