SIZE m_sizeReset;
TCHAR *szReset = _T("测试按钮");
HDC dc = GetDC();
::GetTextExtentPoint32(dc,szReset,strlen(szReset),&m_sizeReset);
ReleaseDC(dc);相关推荐
C++原生GUI开发:从零实现Win32 API控件系统与事件驱动架构
图形用户界面(GUI)是软件与用户交互的核心层,其底层原理基于事件驱动编程模型和消息循环机制。在Windows平台,Win32 API提供了最接近系统底层的GUI开发接口,通过窗口过程、消息分发和GDI绘图等核心概念,开发者能够深入理解界面渲染与用户交互的完整流程。掌握这些技术不仅有助于排查界面卡顿、控件无响应等常见问题,更能为学习Qt、MFC等高级框架打下坚实基础。本文以C++和Win32 API为例,通过实现按钮、文本框等基本控件,系统讲解了消息循环、面向对象控件树设计以及焦点管理等关键技术,帮助开发者
GetTextExtent、GetTextExtentPoint32 精确无误差的使用注意【vc++ / MFC】
网上有大量的有关“获取字符串的显示宽度”的文章,基本都是用 GetTextExtent 或 GetTextExtentPoint32,但大多数都没说字体的影响,直接结果是误差很大,包括MSDN上的示例: MSDN这段示例原代码: // Pointer to the myListBox. extern CListBox* pmyListBox; // Find the longest string in the list box. CString str; CSize sz; int dx=0
AI视频生成成本优化实战:混合架构与硬件选型
AI视频生成技术正面临效果与成本的二元博弈,其核心挑战在于高昂的推理算力消耗与黑箱服务的不确定性。从技术原理看,视频生成依赖扩散模型等深度学习架构,通过多轮迭代实现像素级合成,这导致GPU显存占用和电力消耗呈指数级增长。在工程实践中,采用混合推理架构能有效平衡成本与质量,例如云端处理关键帧配合本地渲染过渡帧,实测可降低58%支出。硬件选型方面,消费级显卡魔改与边缘计算设备为中小企业提供了可行方案,如RTX 3090显存扩容或Jetson AGX边缘部署。当前AI视频应用已渗透电商直播、新闻制作等领域,但需警
GetTextExtentPoint32
GetTextExtentPoint32 函数功能:该函数计算指定的正文字符串的高度和宽度。 函数原型:BOOL GetTextExtentPoint32(HDC hdc, LPCTSTR lpString, int cbString, LPSIZE lpSize); 参数: hdc:设备环境句柄。 lpString:指向正文字符串的指针。此字符串不必以/0结束,因为cbString
Multisim14安装失败?手把手教你彻底清理残留文件(附专用卸载工具)
本文针对Multisim14安装失败问题,提供了一套从根源解决的完整方案。文章详细分析了安装失败的三大元凶——文件残留、注册表残留和隐藏组件,并手把手指导用户使用专用卸载工具进行标准化清理,再结合手动深度清理文件系统和注册表,最终实现彻底卸载和完美重装,有效解决Multisim14安装问题。
新手如何学习车载底层嵌入式软件开发(AutoSar)
汽车嵌入式开发
GetTextExtentPoint32() 判断一个字串的大小(范围)
GetTextExtentPoint32 (2006-07-18 11:16:29) 转载▼ 分类: 学习日志 【别名】 GetTextExtentPoint32A 【说明】 判断一个字串的大小(范围)。在Win32环境中,最好使用GetTextExtentPoint32,它提供了更精确的计算结果 【返回值】 Lon
数字IC后端项目典型问题之后端实战项目问题记录
数字IC后端培训教程之数字后端实战项目问题debug及解决方案记录
详细介绍 GetTextExtent()
书籍:《Visual C++ 2017从入门到精通》的4.2环境:visual studio 2022内容:[例 4.4]实现一个三角按钮说明:以上内容大部分来自腾讯元宝。
kaggle项目:纽约出租车行程时间NYC Taxi Trip Duration
纽约出租车形成时间预测(NYC Taxi Trip Duration)是Kaggle中的一个Playground竞赛。比赛数据集基于2016年纽约市黄色出租车行程记录数据,需要建立一个模型,根据单个行程属性,预测测试集中每次行程的持续时间。Kaggle项目模型XGBoost,评价指标RMSLE。
基于OpenSSL的CA建立及证书签发(签发多域名/IP)
自签SSL证书(多域名/IP) 本文基于以下环境: 内核信息:Linux zabbix 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux 系统版本:CentOS Linux release 7.6.1810 (Core) OpenSSL版本:OpenSSL 1.0.2k-fips 26 Jan 2017 【前言】 在基于OpenSSL的CA建立及证书签发一文中(后面统.
VC中获取单个字体尺寸和字符串尺寸
2019独角兽企业重金招聘Python工程师标准>>> ...
ABtest描述统计功效
我们在面试数据分析时,常常会问到如何确定样本量的问题,会有一个指标:统计功效(power),或者是1-β 统计功效会影响实验的可信度,甚至会影响实验所需的样本量,要了解统计功效,首先要理解两类统计错误 假如我们做了一个AB实验,且两组用户的数据均值为μ1和μ2,我们会有两个初始假设: H0:两个实验组的数据没有差别(μ1=μ2),这个假设也叫“零假设”,也叫原假设 H1:两个实验组之间的数据存在差别(μ1≠μ2),这个假设也叫“非零假设”,也叫备择假设 定义两类错误: 实验本身没有效应,但我们觉
[WTL/Win32]_[初级]_[如何在工作线程计算文本的宽高]
1. 在开发`WTL/Win32`程序时,有些界面绘制的元素比较多,内容多的时候还需要使用进行滚动显示; 比如在显示聊天气泡是,需要先计算气泡的个数并算好它的位置; 在使用滚动条时可以在滑条停止位置显示对应的气泡内容; 如果气泡上万个之后,在主线程计算就会卡,怎么解决?
免费教你快速学会分析运算放大器电路(保证学会)
本文旨在学习如何快速简单地对运算放大器进行分析
华为的C语言编程规范.pdf
华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。
关于怎样获得字符串在DrawText时矩形的宽度
今天在写一窗口图片编辑工具时发现字符串的大小不能确定,但程序中因为会移动字符串,为了不刷新整个窗口而只刷新字符串所在处的矩形就必须知道字符串的宽度,在网上搜索良久,终于在一论坛上找到合适的解决办法,记录下来以备自己以后使用,或是哪位仁兄需要时尽可参详。LPCTSTR RankpszString = TEXT("10590394756265"); CFont fon
Devexpress16.2.6破解工具
Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具
通用GUI编程技术——Win32 原生编程实战(二十一)——GDI 文字渲染:TextOut、DrawText 与文字度量
本文介绍了Win32 GDI文字渲染的基础知识和技术要点,主要包括: GDI文字渲染的基本原理和设备上下文(HDC)与字体的关系 字体创建方法(CreateFont)及使用注意事项 TextOut函数的使用细节,包括坐标系统、字符编码和文本对齐方式 设备上下文的文字属性设置(文本颜色、背景颜色、背景模式等) 文章通过实际代码示例展示了如何在Windows窗口上绘制文字,并解释了相关概念如"基线"在文字渲染中的重要性。作者指出虽然GDI文字渲染系统设计较早,但在简单场景中仍是最快速、兼容性
深度学习工具包 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');```[](https://bitdeli.com/free "Bitdeli Badge")
【MFC】字体类CFont——文本输出
01、目录 文章目录01、目录02、文本输出过程2.1、 确定字体信息2.2、 格式化文本2.3、 执行文本输出操作03、文本输出实例04、小结 02、文本输出过程 在上一节字体类——CFont中讲了字体类的基础知识,现在我们就用基础知识来做一点小东西。 在文本输出到设备以前,我们需要确定字体、字体颜色和输出的文本内容等信息。Windows窗口的客户区由应用程序管理,所以我们还要在应用程序中控制输出文本的格式,例如后续字符的位置、换行等格式。 由此,文本的输出过程大致包括确定字体信息、格式化文本和执行输
Windows GDI文本绘制:TextOut与DrawText的核心原理与实战选择
在Windows桌面应用开发中,图形设备接口(GDI)是界面渲染的基石,其文本绘制功能直接影响用户体验与性能。GDI通过设备上下文(DC)管理字体、颜色等绘制状态,开发者需理解其模型才能有效控制文本输出。TextOut函数提供像素级精准控制,如同狙击步枪,适合高性能场景,但需手动处理换行与对齐;而DrawText则集成自动换行、对齐等排版功能,如同瑞士军刀,简化了多行文本与动态布局的实现。两者分别代表了底层控制与开发效率的不同取舍,其选择需基于绘制性能、排版复杂度等具体需求。本文聚焦Windows GUI编
系统API的简记
系统API的简记本篇主要用于记录在PC客户端开发时使用过的系统API: GetCursorPos SetWindowPos GetTextExtentPoint32 SetTimer GetWindowRect GetSystemMetrics ClientToScreen ScreenToClient 鼠标指针位置转换成鼠标坐标ClientToScreen(m_hWnd, &point); 鼠标
17.5 设置段落格式
摘录于《Windows程序(第5版,珍藏版).CHarles.Petzold 著》P816 我们已经学会了如何选择和创建逻辑字体,显示是时候来尝试如何进行设置文本格式了。这一过程包括将分别使用以下四个对齐方式在边界范围内进行文本对齐:左对齐、右对齐、居中或两端对齐(即从一端的边界到另一端排列文本,平均分配字符间的空白)。对于前三种情况,可以使用 DrawText 函数的 DT_W
VS2010-MFC(字体和文本输出:文本输出)
转自:http://www.jizhuomi.com/software/241.html 上一节讲了CFont字体类,本节主要讲解文本输出的方法和实例。 文本输出过程 在文本输出到设备以前,我们需要确定字体、字体颜色和输出的文本内容等信息。Windows窗口的客户区由应用程序管理,所以我们还要在应用程序中控制输出文本的格式,例如后续字符...
VC技巧--02
101 怎样取得程序自己占用的内存和CPU占用率:GetProcessMemoryInfo和GetPerformanceInfo 102 如何让你的程序运行在release模式下:build->set active configuration 103 监视文件夹是否被更新:FindFirstChangeNotification、FindNextChangeNotification、FindC...
为何我用GetTextExtentPoint32这个API总是得不到正确的文本长度?
原文转载自:http://bbs.youkuaiyun.com/topics/80515448 呵呵,偶问题解决了,不能独享,贴出来,楼主看一下,有一个步骤是必须的,就是取得主窗口的FONT,然后设置DC的FONT,然后再计算,这样才正确,参考下面的代码 CSize s; CFont *font = this->GetFont(); CFont *def_font = NULL;
389



被折叠的 条评论
为什么被折叠?



