Windows API——TextOut()函数学习

三、C语言创建桌面程序:文字的输出 TextOut 和 DrawText 一、BeginPaint 和 EndPaint 函数 当发生 WM_PAINT事件时,应用程序开始绘图。绘图之前需要先调用 BeginPaint 函数通知 Windows,告诉它当前程序需要使用显示器,你安排一下吧。BeginPaint 函数执行完毕就返回设备环境句柄,接下来就可以使用 GDI函数绘图了。 绘图结束后,也需要调用 EndPaint 函数通知Windows,告诉它绘图结束了,你可以... 阅读详情

1.函数功能

The TextOut function writes a character string at the specified location, using the currently selected font, background color, and text color.

TextOut函数使用当前选定的字体、背景颜色和文本颜色在指定位置写入字符串。

2.函数原型

BOOL TextOutA( HDC hdc, int x, int y, LPCSTR lpString, int c );(普通字符)

BOOL TextOutW( HDC hdc, int x, int y, LPCWSTR lpString, int c );(宽字符)

参数:

hdc:当前DC句柄。

x:指定用于字符串对齐的基准点的逻辑x坐标

y:指定用于字符串对齐的基准点的逻辑y坐标

lpString:A pointer to the string to be drawn. The string does not need to be zero-terminated(不必以\0结尾), because cchString specifies the length of the string.

c:指定字符串的长度。

返回值:

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.

3.备注

The interpretation of the reference point(基准点) depends on the current text-alignment mode(文本对齐模式). An application can retrieve this mode by calling the GetTextAlign function; an application can alter this mode by calling the SetTextAlign function. 

可以使用以下值进行文本对齐。 (只能从影响水平和垂直对齐的标志中选择一个标志。只能选择改变当前位置的两个标志中的一个。)

参数值描述
TA_BASELINE参考点将位于文本的基线上。
TA_BOTTOM参考点将位于边界矩形的底部边缘。
TA_TOP参考点将位于边界矩形的顶部边缘。
TA_CENTER参考点将与边界矩形的中心水平位置对齐。
TA_LEFT参考点将位于边界矩形的左边缘。
TA_RIGHT参考点将位于边界矩形的右边缘。
TA_NOUPDATECP每次文本输出调用后,当前位置不会更新。 参考点传递给文本输出函数。
TA_RTLREADINGWindows的中东语言版本:文本按从右到左的阅读顺序排列,而不是默认的从左到右的顺序。 仅当选择到设备上下文的字体是希伯来语或阿拉伯语时才适用。
TA_UPDATECP每次文本输出调用后更新当前位置。 当前位置用作参考点。

4.VS2010字符集的选择

#ifdef UNICODE
#define TextOut  TextOutW
#else
#define TextOut  TextOutA
#endif // !UNICODE

35.文本输出函数TabbedTextOut、ExtTextOut、TextOut、SetBkColor TextOut和TabbedTextOut的区别 TabbedTextOut 功能为该函数将一个字符串写到指定的位置,并按制表位位置数组里的值展开制表符。正文以当前选择的字体、背景色和字体写入。 TabbedTextOut函数定义 WINUSERAPI LONG WINAPI TabbedTextOutW( __in HDC hdc, //绘图设备上下文 __in int x, /... 阅读详情

相关推荐

[Win32]重绘的基本概念以及简单的文本输出文本输出

1. 客户区的完整概念: 即

Lirx_Tech的专栏 3767

向窗口输出文字--TextOut和DrawText函数

在《一个完整的Windows程序框架》一节中,我们使用 DrawText() 向客户区的中间位置输出了一段文本,但并没有详细解释,这节我们来重点说一下文字的输出。 设备环境(DC) 在Windows中,一切能在显示器上看到的都是图形,不但包括点、线、矩形、圆等,也包括文字、字体。对用户来说文字和图片是不同的,但它们在本质上都是图形,都需要在显示器上画出来。这也是Windows被称作图形

芝麻软件工作室的专栏 3万+

LAMMPS实操系列(四): 高熵合金FCC-CoCrCuFeNi的退火模拟

我们对FCC-CoCrCuFeNi的退火模拟思路主要是,首先将材料以均匀的速率用100 ps从300 K升温至1000 K,然后在1000 K的温度下平衡100 ps,随后以均匀的速率用100 ps从1000 K降温至300 K,随后通过共轭梯度下降法做静力学结构优化得到退火后的结构。由于FCC-CoCrCuFeNi高熵合金被认为是潜在的工程结构材料[1],接下来我们将对退火前后的结构进行压缩模拟,对比退火前后FCC-CoCrCuFeNi高熵合金的力学性能变化,敬请各位读者关注我们的更新。

Ceshigo_CD的博客 4837

8.向窗口输出文字 : TextOut 和 DrawText 函数

使用 DrawText() 向客户区的中间位置输出了一段文本,说一下文字的输出。 设备环境(DC) 在Windows中,一切能在显示器上看到的都是图形,不但包括点、线、矩形、圆等,也包括文字、字体。对用户来说文字和图片是不同的,但它们在本质上都是图形,都需要在显示器上画出来。这也是Windows被称作图形操作系统的原因。 Windows不允许我们直接访问硬件,如键盘、显示器、打印机等,在与这些硬件...

y果子 6887

CVPR 2027 投稿规划:基于近3年录用率与截稿周期的5步时间管理法

本文为计算机视觉研究者提供CVPR 2027投稿的完整规划指南,基于近三年录用率与截稿周期数据,提出五步时间管理法。涵盖选题策略、实验设计、论文写作、同行评审到最终提交的全流程优化,特别针对CVPR日益激烈的竞争环境(2024年投稿量达11532篇,录取率仅23.6%)提供实用解决方案,帮助研究者提升投稿成功率。

weixin_34079177的博客 1143

Linux显卡管理避坑指南:为什么Xorg总是占用你的NVIDIA GPU?

本文深入解析了在Linux系统上,尤其是双显卡笔记本中,Xorg显示服务器进程占用NVIDIA GPU的根本原因。文章从Xorg的驱动加载机制和NVIDIA驱动的独占性入手,详细对比了禁用配置文件、手动配置xorg.conf、使用官方PRIME方案以及切换到Wayland等主流解决方案的优缺点与适用场景,旨在帮助用户有效释放GPU资源,确保深度学习、游戏等计算任务能独占显卡性能。

xgboost6farmer的博客 267

Windows API一日一练(22)TextOut函数

文本输出,从来就是比较常用的方式,自从发明文字以来,就应缺少不了文字的显示了。在以前,是书写到白纸上,让别人看懂它。现在到了信息的时代,当然是显示在屏幕上,即使你是不懂书法的,也可以显示出惊人的书法文字出来。在窗口里显示文字出来,就可以使用TextOut函数,当然不只这一个API函数可以显示字符了。TextOut函数是使用当前设备的属性来显示文字的,比如设备属性有字体类型,字体的颜色,字...

anjichan4261的博客 890

uniapp原生安卓插件开发之路

声明: 我的功能需求:全局悬浮框,也就是在其他应用上依旧能悬浮。查遍uni文档,无法实现,甚至native.js也无法实现,无奈只能走上原生插件开发这条不归路了。(吐槽:天天写前端js,突然写了下android简直要炸,public static String啥的,var不香嘛,不过别人严谨肯定还是有别人道理的,加油吧,争取能入个门!) 本人不懂安卓开发,完全安卓小白,所以安卓方面可能表达的不是很好,安卓代码可能写的不优美,但我功能最终还是实现了。但是为了需求,能力总能被“逼”出来。有描述错误的还望指正

Jone's Area 1万+

Windows API一日一练 22 TextOut函数

Windows API一日一练 22 TextOut函数

uytrrfg的博客 588

深入浅出:CosineLRScheduler 调度器的原理与实战应用

本文深入解析了CosineLRScheduler调度器的核心原理与实战应用,详细介绍了余弦退火算法及其在深度学习模型训练中的优势。通过参数配置建议、PyTorch实现示例和常见问题解决方案,帮助开发者高效应用该调度器提升模型性能,特别适用于计算机视觉和自然语言处理任务。

sss66的博客 859

实战避坑:泛微E9流程接口与单点登录(SSO)开发全解析(含自定义Action、Restful API与免密登录)

本文深入解析泛微E9流程接口与单点登录(SSO)开发中的关键技术与避坑指南,涵盖自定义Action开发、Restful API鉴权机制及跨系统单点登录实现。通过实战案例与代码示例,帮助开发者高效完成二次开发,解决系统集成中的数据孤岛问题,提升企业信息化建设效率。

weixin_42549451的博客 672

游戏——TextOut函数

用当前选择的字符、背景颜色和正文颜色将一个字符串写道指定位置 原型: BOOL TextOut( HDC hdc, //需要进行的文本输出的DC的句柄 int nXStart, //开始书写的位置的X坐标 int nYStart, //开始书写的位置的Y坐标 LPCTSTR lpString, //指向字符串的指针,文本默认黑色,背景为白色 int cbString //字符串的字符数 ); 调用实例: wchar_t text1[]=L"要有最朴素的生活

maxkd的博客 1891

局域网tcp通信实验

IPv4 地址 . . . . . . . . . . . . : 192.168.92.79。IPv4 地址 . . . . . . . . . . . . : 192.168.92.59。子网掩码 . . . . . . . . . . . . : 255.255.255.0。子网掩码 . . . . . . . . . . . . : 255.255.255.0。使用这篇文章的小工具。

weixin_51883798的博客 433

文本输出API函数:TextOut,ExtTextOut,DrawText,DrawTextEx,PolyTextOut,TabbedTextOut

前阵子由于做一个软件需要用Detour库HOOK其它程序的文本输出,以实现对第三方程序文字的监控。         对这六个文本输出API函数:TextOut,ExtTextOut,DrawText,DrawTextEx,PolyTextOut,TabbedTextOut,作了一番学习。         以前只是使用,HOOK以后才发现它们有很大的不同。 // TextOut(分为TextO

Reviter的专栏 8187

2023.03.27更新大麦网PC端抢购软件和使用教程

近期发现大麦网页端抢购页面悄然发生变化,之前可以在页面选择票价、档次,并且点击按钮进行购票,现在不行了,新的页面如下图所示。已经安全没有了点击按钮,因此,但是并不代表不能像以前之前那样。

猫敷雪 1万+

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

MFC—使用DrawText和TextOut编辑文字

MFC使用DrawText和TextOut编辑文字 一、DrawText函数 1、函数定义,这里引用一篇博客 https://blog.youkuaiyun.com/by_mxy/article/details/9932967 2、引用一个函数实现的demo void CMFCTestDlg::OnPaint() { CRect rect; GetClientRect(&rect)...

仰望星空的博客 6634

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

MFC 和Windows API的TextOut输出文字

void CTest1Dlg::OnButton1() {  // TODO: Add your control notification handler code here  /*  //MFC输出  CDC* pDC = this->GetDC();  char buffer[] = "千万里,千万里我追寻着你!";  pDC->TextOut(100,100, buf

蚂蚁搬家 1万+

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

TextOut显示多行文本的方法

发信人: enjoysoft(Enjoy — 享受生活), 信区: VC标  题: Re: 请教SetDlgItemText与TextOut的用法区别发信站: 饮水思源 (2006年10月12日21:55:43 星期四)这个做法比较妥当,因为一旦窗口被重画,你用CClientDC画的字符串就不见了。响应WM_PAINT才是正道!TextOut不支持换行的,反而可以把Tab、Enter之类的字符直接

ponydph的专栏 6630
上一篇: Windows API——SetBkMode()函数学习
下一篇: 《MFC程序开发参考大全》学习笔记_3
LemonnnLee
博客等级 码龄9年 8粉丝 14原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值