MFC icon works on Windows 7, not on Windows 8.1 - c++

I have a MFC/C++ application that is built on a Windows 7 system, where it works fine, and I want to use it on a Windows 8.1 system. It also works on Windows 8.1, but the taskbar icon is the MFC default icon (3 blocks with "M", "F" and "C"), rather than the one I designed for the app.
My icon file includes 16 x 16, 32 x 32, 24 x 24, 32 x 32, 48 x 48, all in 4-bit, 8-bit and 32-bit color--BMP format, and 256 x 256, 32-bit color--PNG format.
The app is being built with Visual Studio 2010.
What do I need to do to get the taskbar (and other icons) to work on Windows 8.1 as well? I can't find any MS documentation on the icon requirements; a pointer to these would also be helpful.
UPDATE: When Windows 8.1 was rebooted, one of my icons appeared in the task bar (don't know which resolution or color depth), so, immediate problem solved. However, I'd still like to know why icon didn't appear immediately, and which format icon is used.

Related

C++ Windows API - How to retrieve font scaling percentage on Windows 10

My goal is to be able to adjust the font size at runtime in a C++ app, based on the monitor resolution.
In this question, it's explained how to get the font scaling percentage, but the suggested function GetScaleFactorForMonitor requires Windows 8.1. My C++ app must run on Windows 7 or higher. I have tried several proposed solutions based on getting the ratio of device caps parameters, but they all get 1.0 on a Windows 10 system where the Windows "Make everything bigger" setting is 150%.
Per the MS docs, Visual Studio is adding "dpiAware" to the manifest (this is a setting I can change). Probably because the app is being built on a Windows 7 system, the VS-generated manifest does not include Windows 10 as a supported O/S. If I add the lines
<!--This Id value indicates the application supports Windows 10, Windows Server 2016 and Windows Server 2019-->
<supportedOS Id="{{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
to the manifest, when I run the app on Windows 10, I get a "side-by-side" error.
How can I get this "make everything bigger" and the "make text bigger" settings on a Windows 7 or 10 system?
Build system: 64-bit Windows 7, Visual Studio 2019 16.7.7 Run system: Windows 7 or later
After discussing in the comments, it turns out your actual problem is that you don't declare DPI awareness in your manifest correctly.
You need to merge this into your manifest:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
</windowsSettings>
</application>
</assembly>
Explanation:
dpiAware true is recognized by Windows 7 and Windows 10, and declares system-wide DPI awareness (DPI_AWARENESS_SYSTEM_AWARE). System-wide means that it assumes that all applications on all monitors use the same DPI setting).
dpiAwareness is recognized by Windows 10 (Windows 7 ignores it) and, if present, supersedes dpiAware. It declares per-monitor DPI awareness (DPI_AWARENESS_PER_MONITOR_AWARE), which means that each monitor can have different DPI settings and your application must handle that correctly.(2)
If you do not include this manifest, Windows will virtualize the DPI, meaning it will act as if the DPI setting is always at 96 (100%), and then Windows merely scales the bitmaps (blurry). This is a compatibility measure that ensures that applications which do not implement DPI code can still appear bigger.
Then, on Windows 7, you get the scaling factor using the GetDeviceCaps function with LOGPIXELSX and LOGPIXELSY, and dividing the result by 96 (because 96 dpi is "100%").(1) This will give you the DPI setting of the main monitor. GetDeviceCaps has been the way to get this setting since Windows XP. This will also do fine on Windows 10 if and only if you do not declare DPI awareness per monitor.
On Windows 10, if you declare DPI awareness per monitor, GetDeviceCaps will not suffice because it only returns the DPI setting for the main display. But if you declare PerMonitorV2, then you are obliged to implement per-monitor DPI correctly. To do this, you can call GetDpiForWindow, or MonitorFromWindow + GetDpiForMonitor.
Since you want your executable to run on both Windows 7 and Windows 10, you cannot link against GetDpiForWindow and GetDpiForMonitor because those functions do not exist in Windows 7. You will need manually link at runtime using GetProcAddress.
To merge the manifest, you can use the Manifest Tool in Visual Studio (Project Properties -> Manifest Tool). Put the entire manifest XML text from above into a file (e.g. DpiAwareness.manifest), and specify that under Manifest Tool -> Input and Output -> Additional Manifest Files.
As for the "Make text bigger" accessibility setting: It is a relatively new WinRT setting that is meant for UWP apps. You're not really expected to use it in Win32 applications, so it's going awkward in Win32. I can't help you there because I hate all things UWP. UWP can go die in a fire.
(1) I have never seen a DISPLAY device with a non-1:1 aspect ratio though. It is probably only useful for printers. The fact that GetDpiForWindow, which is the most modern of the mentioned functions, only returns one number, suggests that it is probably safe to assume that the DPI in X direction will always be equal to the DPI in Y direction (on DISPLAY devices).
(2) Note that there is also dpiAwareness PerMonitor (without V2). This is more or less a now-obsolete hack that came with Windows 8. Don't bother with it.

AddFontResource does not install the font correctly

I use AddFontResourceW(_T("C:\Program Files\MyApp\MyFont.ttf")); to install 2 fonts from my 64-bit C++ app.
The return value is 1, but in the app the font is displayed 10 times smaller and look like Sans Serif (not my font).
If I manually install the font in Windows, then it is displayed correctly in the app.
I have tried AddFontResourceEx, but the same result. I also have tried to copy the TTF font file in C:\Windows\Fonts with my app installer and then call AddFontResource(_T("myfont.ttf")); and the same result.
If I don't call the AddFontResource at all, then the font is substituted with Arial with the correct size.
Tested in 64-bit Windows 7, 10 and Windows 2012 Server.
I have tried with Oswald font and Ubuntu, but I get the same results.
I have solved the problem by copying the font to C:\Windows\Fonts then add it to registry and then AddFontResource, otherwise it does not display the font correctly. Using it as a temporary font resource it does not work.

why does my wxwidgets app get distorted in windows 8.1

Hi I developed an app that works great in windows xp and windows 7. However once on a Windows 8 64 BIT pc the interfave becomes distorted. Tab heading
s are not fully visible and buttons that were next to each other overlap.
What can I do to sort this out?

MFC program in Windows 7 not changing icon in taskbar

I am creating an app for a client. It is written in 32 bit MFC using Visual Studio 2010 and run on 64 bit Windows 7 (compatibility with other versions of windows not required, it's for a very closed system on limited machines) The program will be started automatically in minimized mode when the machine boots.
The program collects data from a bunch of serial ports, and if restored, shows specifics and allows the user to change or fix things, but when minimized should just show a single "red LED" icon to show something is amiss, or a "green LED" icon to show everything is OK, no user intervention is required.
On my development machine (also Win 7-64), running the program from within Visual Studio or directly from Windows Explorer, when I change the icon using CWnd::SetIcon it changes in the window and in the taskbar, just as I want it to. If I make a shortcut to the program and start it with the shortcut, the default icon is displayed in the taskbar and will not change. Fine, it's taking the icon from the shortcut, that is explained.
The odd part is that on the target machine, no matter how I start it, including clicking on in using Windows Explorer in it's folder (like I did on my development machine), or using the Windows Registry "Run", it always uses the default icon, and never changes in the taskbar. I expected that when I used a shortcut on the desktop or in the Startup folder, since that was the behavior on my development machine.
So why would it work on one machine, when run directly from the exe, and not on another of the same windows version?
More to the point, how can I make it work on the target system? I also need to make sure that solution will work when autostarted on power-up/login.

Why same font style show different on windows and linux by QT

I do not use linux x11 windows system, and keep same font family on these two OS, and turn the text to image then save it.I use tahoma.ttf font in QT,set styleStrategy to NoAntialias and set font point size to 7, but on windows
"e""a" looks pretty good on windos.
But on linux :
I am pretty sure the font size is same, because if set pointsize to 8, e will cost 5x6 pixel.
I try the freetype lib on windows not using QT. The result is almost the same with QT in window, so I wonder how to make text the same with windows style.
It looks like that QT 4.7.4 have did included freetype lib, and I try the freetype interface in Qt lib, it shows the same effect with original no modifed Qt qfontengine_ft.cpp.