4

One of our legacy project uses API calls to draw custom controls using the current visual style of the OS (some code can be found in this question I asked). We detected that the classic push button is drawn with a 1-pixel indent instead of occupying the whole specified rectangle. For example, if we need a button of 17x17 pixels:

Push button in Windows 10 (1)

, actually we get a button of 15x15 pixels:

Push button in Windows 10 (3)

Other similar controls like the combo button are drawn exactly with the requested size:

Combo button in Windows 10 (3)

Our goal is to draw the push button to occupy the whole specified rectangle. Yes, I do know that if we draw with visual styles, that surrounding space can be used for semitransparent effects for the main drawn control, but all our checks confirm that this 1-pixel margin is not used at all - neither in Windows 10 nor in Windows 7. The simplest and 'rude' solution would be to specify an rectangle inflated by 1 pixel to draw the push button in, but this approach may conflict if something will be changed in a future implementation of visual styles in Windows.

So the question is: can we detect anyhow programmatically that the push button drawn with the current visual style uses a margin and thus we can take this into account when specify the rectangle to draw the button in?

An idea. Perhaps, we can get this information from API calls that request low-level visual style part properties like this:

Theme Explorer push button low-level properties


EXTRA INFO. Here is a screenshot of the combo button and normal push button drawn in a rectangle of 17x17 pixels in Windows XP with the Silver Luna theme:

WinXP Silver Luna Buttons - zoom 1000%

As you can see, both buttons are drawn exactly with the given size:

Below you see the same buttons drawn with the same code in Windows 7:

Windows 7 Aero Buttons - zoom 1000%

Now the push button at the right occupies a 15x15 pixel rectangle.

TecMan
  • 2,743
  • 2
  • 30
  • 64
  • I think it's just part of the bitmap and not a metric that you can query for. In XP (when visual styles were introduced) and Vista they did use it to provide a blended edge but now that the style has gone back to flat controls my guess is they left the edge there (invisible) so that UIs that had lined the XP buttons up with other controls wouldn't suddenly start looking out of whack. – Jonathan Potter May 31 '19 at 23:03
  • 1
    @JonathanPotter, in my archive I found a screen of the combo button and push button drawn with the Silver Luna theme in Windows XP (see this picture at the bottom of my question). These buttons both occupy the whole rectangle of 17x17 pixels. It's an incomprehensible secret why Microsoft decided to decrease the actual push button size in Windows 7. – TecMan Jun 03 '19 at 06:52
  • I can't reproduce this issue on Windows 10 1903 using a customer draw push button. ([snapshot](https://github.com/luyaok/images/blob/master/20190613_1.PNG)). If you can show a mini, complete and reproducible sample I can do more investigation. – Rita Han Jun 13 '19 at 07:39
  • @RitaHan-MSFT, this happens on Windows 10 1809. Can you test it on this version? Perhaps, it would be better if we continue this discussion in a private correspondence. Tell me how I can contact you. – TecMan Jun 13 '19 at 11:47
  • @RitaHan-MSFT, can you show us your code? And you can also experiment with [mCtrl Theme Explorer](https://github.com/mity/theme-explorer/releases) (found it in [this question](https://stackoverflow.com/questions/4009701/windows-visual-themes-gallery-of-parts-and-states/) on StackOverflow). This Theme Explorer app reports the size of a push button as 13x11 (retrieved from the part properties), but the actual push button on the screen is drawn as 11x9. – TecMan Jun 13 '19 at 14:22
  • @TecMan I upload my code [here](https://github.com/luyaok/test/blob/master/CustomDrawPushButton.cpp) you can have a check. – Rita Han Jun 14 '19 at 01:10
  • @RitaHan-MSFT, you use [DrawFrameControl](https://learn.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-drawframecontrol). But we all, I think, use [DrawThemeBackground](https://learn.microsoft.com/en-us/windows/desktop/api/Uxtheme/nf-uxtheme-drawthemebackground) to draw the push button frame as suggested in the [Using Visual Styles with Custom and Owner-Drawn Controls](https://learn.microsoft.com/en-us/windows/desktop/Controls/using-visual-styles) article in the Microsoft Visual Styles documentation. What is the right way? – TecMan Jun 14 '19 at 06:04
  • @TecMan I can reproduce the similar effect with yours after use visual on Windows 10. Please check my answer to see if it helps. – Rita Han Jun 14 '19 at 09:38

0 Answers0