Add the XP/Vista look to the tiny sample, please. (For WTL experts.)

Posted on 2009-04-23
Last Modified: 2013-12-14

I am facelifting the old, Windows, C++ (native) application compiled via VC++ 9 (Visual Studio 2008).

The goal is to give it the "XP look" or "Vista look" depending on what machine it runs.

I do observe the two basic problems:

- I am doing something wrong with the manifest of with the project. The application that runs fine on Vista does not run on XP.
- I do not know how to make the GUI elements having the same background color as the parent window -- see the related http:Q_24344219.html

This way I have decided to write a tiny application (source, .vcproj, and .sln files attached; full source shown below as the snippet. I am asking you to show what manifest and how should be added, and how to solve the problem with the background color of the static text control.


P.S. Using VS 2008 may be important here. If I recall correctly, I have just placed the manifest near the .exe and the look was added in Windows XP (when doing some experiments in the past).
#include <atlbase.h>

CComModule _Module;

#include <atlapp.h>    // WTL (required)

#include <atlctrls.h>  // WTL controls

class CNormalWnd : public CWindowImpl<CNormalWnd, 


                                      CWinTraits<WS_OVERLAPPEDWINDOW | WS_VISIBLE> > 



    CNormalWnd() {}

    virtual ~CNormalWnd() {}

    static LPCTSTR GetWndClassName() { return TEXT("CNormalWnd"); }

    DECLARE_WND_CLASS_EX(GetWndClassName(),                    \

                         CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS, \

                         COLOR_3DFACE)   // background as of a dialog

    // Message map to process the events.






    WTL::CButton m_btn;

    WTL::CStatic m_static;

    LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)


        RECT rc = {10, 10, 100, 35 };

        m_btn.Create(m_hWnd, &rc, "Press me", WS_CHILD | WS_VISIBLE);
  = rc.bottom + 20;

        rc.bottom = + 25;

        rc.right = 300;

        m_static.Create(m_hWnd, &rc, "This is a static text control via WTL.", 

                        WS_CHILD | WS_VISIBLE);

        return 0;



    LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)



        return 0;




int APIENTRY WinMain(HINSTANCE hInstance,

                     HINSTANCE hPrevInstance,

                     LPSTR     lpCmdLine,

                     int       nCmdShow)


    // Inicialize the application module.

    _Module.Init(0, hInstance);

    // Main application window.

    CNormalWnd wnd;

    RECT rc = { 100, 100, 500, 400 };

    HWND hWndParent = wnd.Create(NULL, rc, TEXT("ATL Window."));

    // Main message loop.

    MSG msg;

    while (GetMessage(&msg, NULL, 0, 0)) 






    return 0;


Open in new window
Question by:pepr
    LVL 39

    Accepted Solution

    >>>> I have just placed the manifest near the .exe
    As far as I understand manifest files, they do not change application layouts.

    They simply are a way to support own dll versions with your app thus not being dependent on the dlls - same name -  currently registered on the target system. But even that is not done automatically in Visual Studio. You actually would need to make appropriate settings in the .manifest (e. g. by using MSI) to point to other dlls than that provided with the IDE or with the developing operation system.

    >>>> The application that runs fine on Vista does not run on XP.
    What happens?

    >>>> I do not know how to make the GUI elements having the same background color as the parent window
    The sample you showed has same background color? Right? How does it look when it doesn't work? And what have you done to get the same color? The code you posted doesn't seem to care for colors?
    LVL 28

    Author Comment

    To itsmeandnobodyelse: I probably understand the basic idea of the manifest. I have already tried and been partly successful -- see http:Q_24344219.html.

    For the details how it "does not work on XP", you have to wait to Monday. If I remember well, it simply did not started, but I am not sure if there was cmd-like black window with some message, or what.

    I tried to play with the manifest with earlier version of our application when it was compiled by VS 2005. Also, I did use Windows XP in that time. It was possible just to copy the manifest XML file to the same directory where the .exe was placed and it simply worked. I was not able to do the same with application compiled via VC++ 9 (VS 2008) and on Windows Vista.

    These are the reasons why I decided to create the above "simplest" application that could be compiled at your computer and that could be used for demonstration of how to add the manifest.

    The sample does not contain the manifest. This way, it has very classical look even on Windows Vista. Again, see http:Q_24344219.html for my partial success.
    LVL 28

    Author Closing Comment

    Thanks for trying to help me. The situation was a coincidence of few things. The manifest can be added "normally" and it works also on Windows XP. See also the related article referenced in the question (WM_CTLCOLORSTATIC problem).
    LVL 39

    Expert Comment

    >>>> It was possible just to copy the manifest XML file to the same directory where the .exe was placed and it simply worked.
    Yes, a .manifest file with same name as the application would/could replace any registry entries for registered components of the target system. That way it also could point to different resource dlls than that provided by the target system. The main problem I see is how to use that mechanism beyond of that the project settings of a Visual Studio project were already doing by default at build time. As .manifest files were supported since XP but not by former Windows versions, the default settings can't rely on the .manifest but must work without as well (with update of the target system by installing the appropriate runtime dlls of the VC version).

    I wonder how an update or enhancement of the .manifest, e. g. by MSI setup, can be made without risk to making things worse. I have doubts that it can be done without of deep insight of the dependencies between the modules and - in your case - across Window Versions.

    I used to change .manifest file only once, in order to force the application to use a specific version of a grid control which I provided with the application in the same folder. It worked and never gave problems but I never was sure whether it wasn't luck only ;-)


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    The use of stolen credentials is a hot commodity this year allowing threat actors to move laterally within the network in order to avoid breach detection.
    If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
    The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now