Font size from screen resolution ? portable C++? - c++

I have a C++ application and I use ImGUI for building my UI !
The problem is that on my laptop the default font size is good (default is 13 pixels), but on another computer (with bigger resolution), the text is so small that I can't read it !
I notice that other applications have a "bigger" font in this situation.
So, is there a way to compute a "scale factor" for my font depending of the monitor resolution ?
I'm looking for a portable C++ solution !
Thanks for your help

Related

GetTextExtentPoint32W returns different values in different computers

I'm trying to adjust button width depending on the current language that is set in comboBox. For some language like spanish some of the texts are just too long to be fitted into PUSHBUTTON. All controls are in .rc file. To calculate PUSHBUTTON width I'm using RECT (rect.right - rect.left) and to calculate text widht I'm using GetTextExtentPoint32W but unfortunately this method is giving me different values depending in what PC is running. In my laptop where resolution is set to 1920x1080 and scalling100% (recommended is 125%) text width is around 25% bigger than in PC with the same configuration
It depends on the Device Context which may be different across PCs.
Also, you need to be DPI-Aware (since your scalling is not 100%) and GDI isn't.
Suggestion: move to Direct2D.

Create X11 Window with a fixed size

For a C++ Vulkan application with X11, I need to create a window with a fixed size that cannot be maximized or scaled by the user. Reason is that the application is written for that size and just doesn't scale.
Is there an easy way to achieve this? A parameter to XCreateWindow maybe?
Regards

Borland C++ Builder 6 resize output executable to fit screen

In Borland C++ Builder 6 is it possible to customize the resolution of the output executable to fit any screen?
I built an executable at my laptop (1366x768) but I want to use it at another computer with lower resolution.
The reason I want to do that is because the destination computer has smaller touchscreen and I don't want to use scroll-bars.
You should design your UI with a smaller resolution in mind to begin with and then design it to stretch to higher resolutions when needed. You are trying to do the opposite, which won't work as well. It is easier to stretch a UI than to shrink it. With that said, the Anchors and Constraints properties on individual controls, and the Scaled property on Forms, are your friends, you should use them if you are not already. Anchors in particular, because it allows you to stretch and shrink a Form while maintaining the relative layout of its controls.

How to scale font sizes based on current DPI settings in VC++/MFC applications?

How to scale font sizes based on current DPI settings in VC++/MFC applications ?
As of now when I change the DPI from 100% yo 150% the font sizes remain the same, although the icons will scale down based on the current dpi ..
Please suggest the best way for above problem.
In Windows Vista and 7, the OS tries to hide the DPI from your program and does adjustments behind the scenes. If you want your program to react properly to DPI changes you must follow the guidelines from Microsoft titled Creating a DPI-Aware Application.
By specifying the text and control sizes in DLU's. That happens by default though, so I assume you are generating dialogs dynamically or from a memory-based DLGTEMPLATE. If you, you're (pardon my French) screwed, because you'll have to muck about with converting DLU's to pixels, a very painful and tedious process. Read the following KB articles:
http://support.microsoft.com/default.aspx?scid=kb;en-us;125681
http://support.microsoft.com/default.aspx?scid=kb;en-us;145994
Don't use DPI for font scaling. Instead, use the settings the user has configured in the "Appearance" section of Control Panel.
You might also want to consider making the font size configurable for just your application.

Supporting different monitor resolutions

I have a MFC application with some bitmaps, dialog boxes and menus. Currently it supports only one monitor resolution (1280x1024). I am planning to add different monitor resolution support to it. To do that I guess I have to load different resolution bitmaps, change the font size etc. My question is, how these are handled in a typical windows application? Do they use a single bitmap and stretch/shrink it according to monitor resolution or actually have different set of bitmaps in the resource and load them dynamically depending on the resolution? Is there any standard solution to this?
In the past I have used one large image and scaled accordingly.
Making sure that the menus and dialogs resize is tricky but there are helper codes on CodeProject that could help.
I would say to use multiple resources with different resolutions. While you can scale the icons dynamically, they'll probably look better if you resize them in a proper image-editing program.
Menu and toolbar icons are normally displayed with the same number of pixels regardless of screen resolution. Thus menus and toolbars take up a smaller proportion of the screen as the resolution increases.
I don't think there's any standard way of handling different resolutions where bitmaps are concerned.
I would also make sure your application works with Windows DPI scaling. That might be a better alternative when running on higher resolution displays rather than having to redesign the application to meet a specific resolution.
Scaling bitmaps will look bad (making them bigger will always look bad, making them smaller kind of depends on the source). If possible, see if you can compose your big bitmap of several smaller bitmaps that can scale nicely. Lots of times it is fairly easy to make a bitmap that can scale in one direction nicely. For example, if you want to make a frame around something, instead of using one bitmap, cut it up like a tic-tac-toe board into 9 pieces. the four corner pieces stay their original size, the top and bottom pieces stretch horizontally, the left and right vertically, and the center goes both directions (if it is used at all).