Hi guys,

I have a little question. When I make a dialog in Visual C++ 2010, with the Dialog Editor, you can Drag and Drop buttons, Edits etc. I can also test my dialog. The buttons and edits look very nice, the Windows 7 style. However, when I compile my progam, the nice part disappears, and the buttons and edits change to Windows 97 (or whatever) style. I've posted a picture.
Is there any way to change that?

Thanks in advance!

Cheers,
Hidde

Dani AI

Generated

Short diagnosis: the designer shows themed controls because the IDE previews dialogs with the newer common-controls, but the built executable is running without the version-6 common-controls (comctl32 v6) enabled. The managed WinForms startup approach suggested by only applies to C++/CLI (CLR) Windows Forms apps; trying to call managed APIs from a native project produces the managed-targeted-code compile error reported by . For a native Win32 dialog the reliable fix is to supply a manifest that requests Microsoft.Windows.Common-Controls v6 and to initialize common controls before any dialogs are created.

Add an application manifest (or embed one) that contains a dependency on the common-controls v6. In Visual Studio: Add -> New Item -> Application Manifest File, then ensure the dependency block below is present in that manifest (the file must be embedded into the EXE):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        processorArchitecture="*"
        publicKeyToken="6595b64144ccf1df"
        language="*"/>
    </dependentAssembly>
  </dependency>
</assembly>

Also call InitCommonControlsEx early (before creating the dialog) so the common-controls DLLs are initialized. Example pattern:

#include <commctrl.h>

INITCOMMONCONTROLSEX ic;
ic.dwSize = sizeof(ic);
ic.dwICC  = ICC_WIN95_CLASSES;
InitCommonControlsEx(&ic);

/* then create the dialog (DialogBoxParam/CreateDialog, etc.) */

Alternatives and troubleshooting: for a managed WinForms UI follow and use a C++/CLI (CLR) Windows Forms project or enable /clr for the startup compilation unit. For MFC/ATL projects the framework usually calls InitCommonControls; if visual styles still do not appear, confirm the manifest is actually embedded (Linker/Manifest settings) and that the system is not set to the Classic theme. 's pointer about System.Windows.Forms is correct — that route requires a managed app.

Recommended Answers

All 8 Replies

Check this is in your main()

// Enabling Windows XP visual effects before any controls are created
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false);

I'm using 2008 and this is inserted automaticly when you create a new project.
Maybe not so for 2010??

Milton

Thanks for your reply, I'll try this when I'm at home.

I think the problem is that I created a blank project, so no default files or headers.
I'll try that as well.

OK, I've tried it. No joy...

My error messages:

1>c:\users\administrator\documents\c++\temp\temp\temp.cpp(22): error C2653: 'Application' : is not a class or namespace name
1>c:\users\administrator\documents\c++\temp\temp\temp.cpp(22): error C3861: 'EnableVisualStyles': identifier not found
1>c:\users\administrator\documents\c++\temp\temp\temp.cpp(23): error C2653: 'Application' : is not a class or namespace name
1>c:\users\administrator\documents\c++\temp\temp\temp.cpp(23): error C3861: 'SetCompatibleTextRenderingDefault': identifier not found

I've also tried making a default project (Win32 Program), and there is a lot of code, but not anything like your code, or anything resembling Visual Styles...

Any other ideas?

Bump!

You should try what Milton said. Application object can be found in System.Windows.Forms namespace.

If you a using a CLR Windows Forms Application you sould have a "YourProjetName".cpp file that resembles this.

// HEXView.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"

using namespace HEXView;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
	// Enabling Windows XP visual effects before any controls are created
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 

	// Create the main window and run it
	Application::Run(gcnew Form1());
	return 0;
}

I dont get it anymore, namespaces never work out with me...
(See image)

Error Messages:

c:\users\administrator\documents\visual studio 2010\projects\rekenmachine\rekenmachine\winmain.cpp(8): fatal error C1190: managed targeted code requires a '/clr' option

Thanks for all your replies!

I am not using a CLR Windows Forms Application. I don't know what that is...
All I know is that I am making a project, in Visual C++ 2010, everything works, but not the nice Windows 7 button/edit styles.
I thought this wouldbe easier...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.