minigui:基于GetTabbedTextExtentPoint 计算多行文本显示的矩形尺寸

API取字体宽度 取字体宽度,取字体高度,GetTextExtentPoint,GetDC,CreateCompatibleDC,CreateFont,MulDiv,GetDeviceCaps,SelectObject,CloseHandle,ReleaseDC,DeleteDC,DeleteObject 立即下载

当我们想知道一个字符串在屏幕上显示所占的区域大小,该怎么实现呢?
minigui提供了GetTabbedTextExtentPoint函数用于计算一个字符串在屏幕显示的时候实际的显示区域大小.下面是GetTabbedTextExtentPoint 的函数声明(declared in minigui/gdi.h)

MG_EXPORT int GUIAPI GetTabbedTextExtentPoint (HDC hdc, 
                const char* text, int len, int max_extent, 
                int* fit_chars, int* pos_chars, int* dx_chars, SIZE* size);

其中max_extent用于指定显示的最大宽度,如果字符串太长超过这个长度,那么size.cx就是这个值。GetTabbedTextExtentPoint的返回值是实际显示的字符数。
比如字符串”hello,world”,指定max_extent=40,则函数返回值为5,代表对于40像素的宽度限制,只能显示前5个字符。返回的SIZE值为cx=40,cy=16,代表屏幕显示宽度为40,高度为16(一行的高度)。

    HDC hdc = GetDC(HWND_DESKTOP);
    SIZE ls;
    const char*pstr = "hello,world";
    int offset = GetTabbedTextExtentPoint (hdc, "hello,world", strlen(pstr),
                    40, NULL, NULL, NULL, &ls);
    // offset = 5, ls = {40,16}
    ReleaseDC(hdc);

根据这个函数提供的功能,就可以实现计算多行文本显示区域大小(gnu c编译)。

#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
// 计算文本显示需要的屏幕尺寸
// text 显示的文本,不可为NULL
// max_width 显示文本的最大屏幕宽度
// size 返回计算结果
// log_font 指定显示字体,为NULL使用缺省字体
// 计算成功返回值 TRUE,否则返回FALSE
BOOL compute_text_rect(const char*text,int max_width,SIZE *size,PLOGFONT log_font){
    if (!size) {
        return FALSE;
    }
    // 获取屏幕DC
    HDC hdc = GetDC(HWND_DESKTOP);
    PLOGFONT of = NULL;
    // gnu c内置函数用于返回时释放DC
    BOOL do_finally(BOOL ret)
    {
        if( HDC_SCREEN == hdc){
                SelectFont(hdc,of);
            }
        ReleaseDC(hdc); 
        return ret;
    }
    if(log_font){
        // 设置字体
        of =SelectFont(hdc,log_font);
    }
    size->cx=0,size->cy=0;
    // max_width 至少要大于一个字符宽度
    if(!(max_width >= GetMaxFontWidth(hdc))){
        return do_finally(FALSE);
    }
    SIZE ls;
    const char *pstr = text ? text : "";
    int offset = 0;
    while(strlen(pstr += offset)){
        // 计算一行的显示区域输出到ls,offset为实际输出了多少个字符
        offset = GetTabbedTextExtentPoint (hdc, pstr, strlen(pstr),
                max_width, NULL, NULL, NULL, &ls);
        // 显示区域宽度为所有行的最大宽度      
        size->cx = MAX(size->cx,ls.cx);
        // 显示区域高度累加一行的高度
        size->cy += ls.cy;
        // 继续处理剩下的字符
        offset = MIN(offset,strlen(pstr));
    }
    return do_finally(TRUE);
}
【随机过程】Markov Chain的定义及发展历程与实际应用 本模块书写的初衷:由于在学习张波张景肖等学者所著的《应用随机过程》存在着不甚了解的知识点,经过个人查找资料并整理、分享,希望能够为有同样疑惑的读者贡献绵薄之力,同时如果个人编写内容有错误,恳请读者指正。本文为对《应用随机过程》第42页中Markov Chain基本概念的补充。1.Markov Chain的定义俄国数学家 Andrey Andreyevich Markov 研究并提出一个用数学方法就能解释自然变化的一般规律模型,被命名为马尔科夫链(Markov Chain)。 阅读详情

相关推荐

termux 安装 rockylinux

往找最新的文件目录,选择ARM版本的image。或者直接查看目录或者国内阿里云镜像,按照cpu架构(安卓9手机一般是aarch64arm最新架构),获取镜像地址,以及checksum里的SHA256信息更新到以下rocky9.sh脚本,如果不需要直接使用即可。

欢迎来到别往的博客 988

[学习笔记]MFC 中的CDC类

[学习笔记]MFC 中的CDC类 CDC类定义的是设备上下文对象的类。 CDC对象提供处理显示器或打印机等设备上下文的成员函数,以及处理与窗口客户区对应的显示上下文的成员。 通过CDC对象的成员函数进行所有的绘图。 类对设备上下文操作提供了成员函数,处理绘图工具。安全型图形设备接口(GDI)对象收集,以及处理颜色和调色板。 它还为获取和设置绘图属性、映射,处理视点、窗口扩展、转换

congzhao27的专栏 2321

专有钉钉小程序(浙政钉)开发搭建流程总览

最近公司有一个项目要做浙政钉,让我来负责做。靠,我一脸懵,开发了两年多不知道浙政钉是啥,感觉我眼界还是低了。然后就去百度、同事问了一圈才知道就是个钉钉小程序嘛,然后发布到浙政钉上了。就搭建项目跑起来我都肥了很多事,中间走了很多坑。正好领导让我写《钉钉小程序前端开发流程》,这想着也写个博客吧。下面就是整个流程及我所遇到的坑!

m0_53910290的博客 6376

MiniGUI编程速查表

前言 自己学习MiniGui也快一年了,粗浅的学习了一下,本文是根据《MINIGUI-PROG-GUIDE-V3.0-C》中的内容整理而来,根据自己的理解做了一些分类,大部分都是一些函数的说明,方便自己以后学习MiniGui时查阅。现在分享出来,供大家一起学习。当然在学习的过程中也遇到过一些坑,像自定义控件,主窗口透明背景,窗口弹出动画啊,控件动画等等,有时间也会分享出来。 1 窗口的创...

逐梦的博客 6571

基于LabVIEW控制仪器检测与监控 --普源示波器DS1102Z-E

LabVIEW 控制普源示波器 代码实现与解释

s0101100的博客 4241

Dobot Magician机械臂二次开发指南:如何利用Python脚本和I/O接口实现自动化任务

本文详细介绍了Dobot Magician机械臂的二次开发方法,重点讲解如何通过Python脚本和I/O接口实现高级自动化任务。内容包括开发环境搭建、运动控制API解析、I/O接口应用以及典型场景实现,帮助开发者充分发挥Dobot Magician的潜力,适用于工业自动化、教育科研等领域。

weixin_26968079的博客 274

GetTextMetrics与GetTextExtent的区别

GetTextMetrics:获取当前字体的信息 GetTextExtent:获取特定的字符串在屏幕上所占的宽度和高度 对于这两个函数的作用,我在编程的时候,也有一定的困惑。因此,我也想,其他人在编程的时候也肯定有 同样的困惑。所以我把他们解释一下。不足之处,还请大家多多的添加 批评~~其实,我们对什么困惑呢?函数的调用方法,还是在返回值上? CDC::GetTextMetric

gzqhelloworld的专栏 2010

【无机纳米材料科研制图——OriginLab 0205】Origin对BET吸附/脱附曲线及孔径分布制图...

此篇,我们来分享如何对BET数据进行处理和制图。 一、等温吸脱附曲线绘制 1)找到等温吸脱附文件。 一半来说,对一个样品测一次BET,会产生很多数据,具体因仪器而异。我这里的数据主要有两个文件夹,一个脱附,一个吸附,吸附文件夹中多了一个等温吸脱附的文件夹。而这...

XD_Yangf的博客 812

MiniGUI——使用 GDI 函数

简介: 本文讲述 MiniGUI 中 GDI 函数及其使用。主要包括:设备上下文的概念、获取和释放;矩形操作和区域操作;基本绘图函数;位图操作函数;逻辑字体操作函数等。

在不断学习中。。。 5636

【YOLOv11工业级实战】15. YOLOv11海洋监测实战:珊瑚礁健康评估(水下图像增强|机器人搭载)

摘要:本文针对珊瑚礁健康评估的海洋监测需求,基于YOLOv11提出解决方案,聚焦水下色偏、悬浮物干扰、珊瑚形态复杂三大难题。引用全球珊瑚礁监测网络(GCRMN)标准,采用CoralNet数据集,通过Jaffe-McGlamery物理模型引导增强与悬浮物去除算法,在浑浊水域(能见度<5m)实现87.3%的健康珊瑚识别率,藻类误判率低至7.2%。介绍了以BlueROV2水下机器人和Jetson AGX Orin为核心的部署方案,结合水下SLAM定位技术,实现珊瑚健康的实时评估与三维覆盖率计算。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 1653

YOLOv7独家原创改进:多种新颖的改进方式 | 保持原始信息-深度可分离卷积(MDSConv) | 全局感受野的空间金字塔 (Improve-SPPF)算法 | CA注意力改进版

多种新颖的改进方式 | 保持原始信息-深度可分离卷积(MDSConv) | 全局感受野的空间金字塔 (Improve-SPPF)算法 | CA注意力改进版

①订阅者答疑群聊服务;②FDE:工业缺陷检测项目;③paper/创新算法指导;④免费提供YOLO创新涨点推荐顾问Skill和AI小怪兽数字分身; 1675

minigui 抗锯齿 字体抗锯齿 线性抗锯齿 LCD上最明显

minigui点阵字体在显示时存在锯齿的问题,一直没有得到解决,特别是点阵字体放大后更是存在强烈的锯齿现象。 即使是使用ttf字体,取出点阵后,和背景无法融合,所以也是有强烈的锯齿现象。         开始使用自己弄得一个边缘模糊处理,但总感觉效果不是很理想,特别是小字体时效果很差,最近研究了下其他图形库的算法,终于把这个问题解决了,字体、大小可调,效果完全和window一致,而且还可以具有

安防技术 4298

高频注入是否需要对齐和强拖操作?

高频注入技术显著优化了传统FOC启动流程,但仍需部分对齐操作。传统启动必须包含位置检测、对齐和强拖等步骤,而高频注入可实现零速闭环,简化或跳过部分环节。高频注入下的对齐主要用于验证有效性、初始化观测器和建立初始磁链,形式可大幅简化。虽然高频注入基本消除了传统强拖需求,但在重载、弱凸极等特殊情况下仍需辅助。实际应用中可采用自适应混合策略,根据负载和电机类型选择最优启动方案。高频注入使对齐和强拖从"必须"变为"可选优化项",是无传感器控制的重要进步。

汽车软件开发 220

minigui字体居中

GetTextExtent(hdc, SwitchCancel(), -1, &size);这个函数可以得到字的长度TextOut(hdc, rect.right / 4 - size.cx / 2, 222, SwitchCancel());这个算法计算出文字居中位置 转载于:https://www.cnblogs.com/hanrp/p/11378482.html...

weixin_30767835的博客 324

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

GetTextMetrics函数与GetTextExtent函数的区别

GetTextMetrics函数声明如下: BOOL GetTextMetrics(LPTEXTMETRIC lpMetrics)const; 其中参数为一个TEXTMETRIC结构体的指针,TEXTMETRIC结构体定义如下: typedef struct tagTEXTMETRIC { // tm LONG tmHeight; //字符高度 LONG tmAscent

u014723382的博客 824

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

用GetTextExtent取得字符串的宽度和高度

用法:GetTextExtent  函数功能:使用该函数获得所选字体中指定字符串的高度和宽度   函数原型:CSize GetTextExtent(LPCTSTR lpszString, int nCount);   参数:   lpszString是字符串的指针   nCount是所包括的字符数   返回值CSize是包含(cx,cy)2个成员的结构,cx是字符串的宽度,cy是字符串的高度。例子:CString cstr = "Hello";CSize siz = pDC->GetTextExtent(c

蓝蓝的天 1万+

深度学习工具包 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")

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

maoyeahcom的博客 4776

GetTextMetrics 和 GetTextExtent的区别 (c++计算字符串像数)

使用函数GetTextExtent可以计算出一个特定的文本行的宽度和高度,使用函数GetTextMetrics可以得到字符的有关尺寸,这两个函数的使用如下: GetTextExtent 函数用途:该函数使用设备对象dc当前使用的字体计算一个文本行宽度和高度(逻辑单位),在计算时不考虑当前裁剪区。原 型 DWORD GetTextExtent(  HDC hDC 设备对象句柄  LPSTR...

weixin_30300225的博客 371

windows 常用 API

API之消息函数  函数名 作用 BroadcastSystemMessage 将一条系统消息广播给系统中所有的顶级窗口 GetMessagePos 取得消息队列中上一条消息处理完毕时的鼠标指针屏幕位置 GetMessageTime 取得消息队列中上一条消息处理完毕时的时间

KanG 2539
上一篇: minigui:获取屏幕分辨率(GetGDCapability)
下一篇: minigui 3.2.0:基于miniStudio应用TrueType字体的过程(1)
10km
10km 领域专家: 编程技术技术领域 领域专家: 编程技术技术领域
博客等级 码龄26年 1万+粉丝 687原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

10km

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值