Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have been trying to get my buttons to look like the standard buttons shown on the Microsoft page Button Types - Win32 apps | Microsoft Docs[^], but everything I've tried has resulted in 'flat' style buttons. The things I remember doing:

Adding a manifest like the following to my program:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!-- Supports Windows Vista / Server 2008 -->
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
      <!-- Supports Windows 7 / Server 2008 R2 -->
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
      <!-- Supports Windows 8 / Server 2012 -->
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
      <!-- Supports Windows 8.1 / Server 2012 R2 -->
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
      <!-- Supports Windows 10 -->
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
    </application>
  </compatibility>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="Win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
    </dependentAssembly>
  </dependency>
</assembly>


I've done this both by adding the '{MyApp}.exe.manifest' to the executable directory and by embedding it in Visual Studio 2019.

I've also tried adding the following pragma to the program:

#pragma comment(linker,"\"/manifestdependency:type='win32' \
   name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' \
   publicKeyToken='6595b64144ccf1df' language='*'\"")


My button creation function is:

C++
void Button::instantiate(int left, int top, int width, int height, const wString & str) {

   CREATESTRUCT cs = { 0 };
   cs.dwExStyle      = 0;
   cs.lpszClass      = _T("BUTTON");
   cs.lpszName       = c_cast<TCHAR*>(str.c_str());
   cs.style          = BS_PUSHBUTTON | WS_CHILD | WS_TABSTOP;
   cs.x              = left;
   cs.y              = top;
   cs.cx             = width;
   cs.cy             = height;
   cs.hwndParent     = 0;  //Will be set up in ControlWin::instantiate
   cs.hMenu          = (HMENU) idC.id();
   cs.hInstance      = gDwlGlobals->dwlApp->instance();
   cs.lpCreateParams = NULL;

   ControlWin::instantiate(cs, gDwlGlobals->errors()[(int)Error::Button_CreationFailure]);

   if (!hwndC) throw dwl::Exception(_T("Unable to create dwl::Button"));
   SendMessage(hwndC, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT),
               MAKELPARAM(false, 0));
   ShowWindow(hwndC, SW_SHOW);
   }


I've set up Visual Studio to use the latest files (10.0 / v142), but still get flat buttons, although they look better than the buttons that appeared when my settings were WinXP. My current preprocessor defines for the project include:

C++
#pragma comment(lib, "comctl32.lib")
...
#define _WIN32_WINNT 0x0600


Any ideas?

Thanks,
David

What I have tried:

See above. And since this has to be at least 30 characters, see above.
Posted
Updated 31-Aug-20 19:11pm
Comments
David O'Neil 31-Aug-20 20:45pm    
After thinking, I believe my buttons ARE taking on the styling of Windows, but it is the fugly flat styling of Win10. Blech!!! Is there a way to force it to the rounded styling of the glory days of yore?

Depending on how much effort you want to put into this: Owner-draw icon buttons in plain C (no MFC)[^]

Best regards
Espen Harlinn
 
Share this answer
 
Comments
David O'Neil 31-Aug-20 21:35pm    
Thanks. I'll wait before accepting the answer to see if anyone else knows a way to force Win7 behavior through the ways I've tried, but you are probably right.
Sandeep Mewara 1-Sep-20 2:38am    
+5
long time! :)
Espen Harlinn 1-Sep-20 19:50pm    
True - far too long, hope you are doing fine :-)
David : take a look at my post here The Weird and The Wonderful[^]

Near the bottom of the thread an individual mentions the Windows Desktop Manager API : DwmSetWindowAttribute function (dwmapi.h) - Win32 apps | Microsoft Docs[^]

I did some experiments with it trying to get the attributes and it failed most of the time. I didn't get very far with it.
 
Share this answer
 
Comments
David O'Neil 1-Sep-20 20:39pm    
Windows 7 will remain the pinnacle of Microsoft's UI design. So sad that they have gone so far downhill since then. :(
Rick York 2-Sep-20 0:29am    
I couldn't agree more! I liked XP pretty well too though.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900