调整静态ctrl的大小和内容的窗口大小 [英] Ajusting size of static ctrl and window size to content

查看:110
本文介绍了调整静态ctrl的大小和内容的窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




atm我尝试将非常小的linux和mac程序移植到Windows,
我确实使用gtk进行了某种方式的管理,但是依赖性太大了,对于我只有一个静态控件才能显示文本的简单无边界透明窗口来说,编译就不必要了.

我有透明窗口,但我不知道如何根据我要显示的文本调整其大小.

整个过程都是开源的,因此(凌乱的)测试代码是在线的,可以在以下位置查看:
https://github.com/boscowitch/wadoku-notify/blob/master/src -win/clipboard. [ ^ ]

Hi,


atm i try to port a very small linux and mac programm to windows,
i did manage somehow with gtk but the dependencys are far too big and compilation unnecessary complicated for my simple borderless transparent window that has only one static control to show text.

i got the transparent window but i can''t figure out how to ajust its size to the text i want to display.

the whole thing is opensource and the (messy) testing code is therefore online and can be viewed at:
https://github.com/boscowitch/wadoku-notify/blob/master/src-win/clipboard.[^]

推荐答案

使用GetTextExtentPoint32()函数.实际上,这是为了计算您自己的文本图形中容纳文本所需的面积.它采用HDC,并根据字体&给出尺寸. HDC中选择了其他因素.
您可以检索静态的HDC和传递下去.

如果您要计算一行的大小,那就足够了.
如果您想换行&计算所需矩形的高度,可以使用DrawTextEx()函数.您可以在dwDTFormat参数中传递DT_CALCRECT.完成后,它将计算所需的矩形而不是图形.

这些是唯一(非凌乱的)方式:)
Use GetTextExtentPoint32() function. It''s actually meant to calculate area required to hold text for your own text drawing. It takes in a HDC and gives out the size depending on the font & other factors selected into the HDC.
You could retrieve your static''s HDC & pass it on.

That''s good enough if you want to calculate size for a single line.
In case you want to wrap text & calculate height of the required rectangle, you may use DrawTextEx() function. You may pass DT_CALCRECT in the dwDTFormat parameter. When you do, it''ll calculate the required rect instead of drawing.

These are the only (non-messy) ways :)


这篇关于调整静态ctrl的大小和内容的窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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