CCM_DPISCALE common control message - winapi

I've been updating an existing Win32 app to be DPI aware. Following various guides on MSDN and other sites, I manually scale my coordinates and font sizes according to the current monitor DPI.
I just stumbled upon this message: CCM_DPISCALE. The docs say:
Enables automatic high dots per inch (dpi) scaling in Tree-View
controls, List-View controls, ComboBoxEx controls, Header controls,
Buttons, Toolbar controls, Animation controls, and Image Lists
But what does it actually do? I try sending the message to my control like so:
SendMessage(hWnd, CCM_DPISCALE, (WPARAM) TRUE, 0);
But it has no discernible effect on font, size, layout - anything, at any DPI.
I am using Comclt32.dll version 6.0, as per the documentation.
The only reference I can find to this message when Googling it is that MSDN page, and a link from the LVCOLUMNA documentation.
What is this message actually supposed to do?

I figured out at least a small part of what this does.
In a ListView control, if columns are created with fixed width (LVCFMT_FIXED_WIDTH) and as long as you don't specify LVCFMT_NO_DPI_SCALE, CCM_DPISCALE will scale the column width according to the current DPI.
If you have a grouped LVS_REPORT style ListView, and the group header contains an image (LVGF_TITLEIMAGE) that image will also be scaled (but not the group text (LVGF_HEADER))
I didn't test if this scaling is per monitor or not, and I didn't find anything else that this message does (although as per my question, it is documented to effect multiple controls). I am interested in finding out what else this message does!

Related

VSTO Outlook: Setting custom task pane height based on the screen resolution

I have an VSTO Outlook Add-in which shows a custom task pane (ctp). This ctp embeds a usercontrol which in turn contains an elementhost. The elementhost hosts an WPF user control.
At Add-in startup I create the ctp and I set it a fixed height, e.g. 120 points. I have noticed that depending on the screen resolution the ctp height gets smaller or bigger.
So I would like to know if there is a way to set the ctp height according to the current screen resolution so it does not get smaller or bigger.
For example some formula:
ctp.Height = Default_Height * Y_Scaling_Factor
I have tried setting the autoscalemode to font and dpi and it does not work.
You need to set the AutoScaleMode property to None if you don't want to get the container scaled according to the screen resolution.
The AutoScaleMode property specifies the current automatic scaling mode of this control. Scaling by Font is useful if you want to have a control or form stretch or shrink according to the size of the fonts in the operating system, and should be used when the absolute size of the control or form does not matter. Scaling by Dpi is useful when you want to size a control or form relative to the screen. For example, you may want to use dots per inch (DPI) scaling on a control displaying a chart or other graphic so that it always occupies a certain percentage of the screen.
For more information about automatic scaling, see Automatic Scaling in Windows Forms.
Also you may take a look at the AutoSize and AutoSizeMode properties that resize the form according to the setting of AutoSizeMode.

how to make a bitmap to fit to the static picture control of a property sheet?

I am having a property sheet and added three pages.In the first page I added a picture control and in the properties of that picture control for "Image" property I am setting a bitmap.And was able to load very successfully.But,the problem here I faced when I run my exe then I am getting bitmap on the page header(which is some kind of banner for the page.)But what I noticed is there is some gap between the banner bitmap and the frame edge (which is occurring at the right top corner). And when I ran my xxx.exe on a Japanese machine then I had observed like the sheet is somewhat stretched and banner bitmap is not stretched completely till the edge of the sheet (top right corner)for Instance if we take a dialog on load a bitmap on it then we can observe that it is entirely got stretched till the edge.
So how can we avoid this issue like whatever the operating system it is and whatever the resolution it might be that banner should get stretched till the edge of the sheet.The gap has to be removed.
I am not loading the bitmap dynamically (setting in the properties.)
Can anyone please help me ti achieve this
The reason you get different results on different systems is that dialogs and controls are sized using "dialog units" which are based on the average size of the font, rather than an absolute number of pixels.
By default a static image control will resize itself to the size of the bitmap it's displaying. So if the dialog itself ends up bigger than normal (because the font is physically bigger), the picture control will appear to have shrunk, leaving a gap.
You could try setting the SS_REALSIZECONTROL style on the static control. The normal behavior of the static control (when displaying a picture) is to resize itself to the size of the bitmap, however the SS_REALSIZECONTROL style overrides that behavior and instead causes the bitmap to be resized to the size of the control. However the results of that may be less than optimal (e.g. the aspect ratio will probably be wrong), so instead you may want to look into scaling the bitmap yourself.

Notification area flyout link area

I made a flyout window in the notification area using WinAPI and my goal was to make it similar to the flyout windows that show up when you click some of the icons in the notification area, like the Volume icon.
I already succeeded in making it look and behave similar to the other ones, but there is one thing I can't seem to figure out. The link area of the flyout windows has a darker blueish background and there is a subtle difference in the look between Windows 7 and Windows 8. A picture of it in Windows 7 can be seen here
http://msdn.microsoft.com/en-us/library/windows/desktop/aa511448.aspx#flyouts
I achieved this by painting this link area of my flyout window manually in the right colors (including the gradient at the topmost part of the section) using the WM_PAINT message, but I just feel like it's too much of a hack, especially because it's not affected by changing themes in Windows. For example, if I set the "Windows Classic" theme this area should be grey and not blue.
So, my question is, am I missing something in how this can be achieved without painting the window manually. I noticed that the details pane in Explorer windows in Win 7 has the same look. I've searched quite a bit for answers but I haven't found anything yet. This is my first time doing a GUI using the WinAPI so I have very little experience, and therefore I'm assuming there is something that I just don't know about.
UPDATE:
I did manage to figure out how to draw this area without painting it manually. It can be drawn by using the OpenThemeData and DrawThemeBackground functions
HTHEME aeroTheme = OpenThemeData(hWnd, L"FLYOUT");
DrawThemeBackground(aeroTheme, hdc, FLYOUT_LINKAREA, 0, &rect, &rect);
This obviously only works when themes are enabled, so for non-themed cases I draw a normal rectangle with the appropriate color.
I'm not an expert in WinAPI so I can't offer any advice on achieving the look you want without manual painting.
However, if you're successfully achieving the appearance for a particular color theme, I'd suggest you look at the GetSysColor function and use this when creating your brushes for painting. This should allow you to get the correct colors based on the theme that has been set. More info (including a swatch table) can be found here.
Hope this helps.

Aligning text boxes

I'm have some data output text boxes (text boxes with no border and with the same background as the rest of the window) that I'm trying to align with a standard edit control + spin button, to represent a column of numbers, one of which can be edited:
I can manually align these in the Delphi / C++Builder form designer, but when I then view the form on a different version of Windows or at a different DPI, the text is no longer right-justified, presumably because of differences in the spin button spacing, borders, etc.
I can use EM_GETMARGINS to determine the width of the spin button, but how can I determine the size of the edit control's margins and borders? I've tried various combinations of EM_POSFROMCHAR, ClientToScreen, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CXEDGE), and GetThemeMargins, but so far, I can't find a combination that works and makes sense.
More details:
Environment is Delphi / C++Builder XE2.
The data output controls are TEdits with BorderStyle bsNone.
The edit + spin button is a TJvSpinEdit. From viewing its source, it uses EM_SETMARGINS to allow space for its spin button.
Use the Win32 API GetWindowRect() and GetClientRect() methods. The bordering will be the difference between the two rectangles. That will only give you the bordering, though. There could be extra spacing inside the client area.

How to position/resize VB6 controls for different dpi settings?

In a VB form, I am placing controls(image controls), like a banner image, a logo in an image, and a an image list for an animated circle to representing processing.
When I position these controls at 96 dpi, they are perfect. But once the dpi setting is changed to 120dpi, the controls get resized and repositioned.
How do have the same positions of the controls, over different dpi settings?
ActiveResize is a great tool for resizing controls automagically. It costs money, but it's definitely worth checking out.

Resources