Wednesday, February 18, 2009

New Windows XP look and feel for dialogs in DLL

I have an MFC DLL that displays a dialog, and the DLL is loaded by applications that are developed by third parties. My DLL dialog uses manifest to display the user-controls on the dialog using the new Windows XP look and feel, and it works fine.

Here is the problem: When my DLL is loaded by an older application that does not use the new Windows XP look and feel, my dialog uses that classic appearance for the user-controls like the pushbuttons, combo-boxes and slider-controls.

How should I work around this, so that the dialog in my DLL uses the new Windows XP look for the user-controls irrespective of its support in the application that has loaded my DLL?

Solution: Before displaying the dialog, make this call:

AFX_MANAGE_STATE(AfxGetStaticModuleState());

Sample usage:

void CMyDlg::DisplayMainDialog(CWnd* pWndParent)
{
    //In order to use the OS theme, this call has been added.
    AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
   
    if(Create(IDD, pWndParent))
    {
        ShowWindow(SW_SHOW);
        UpdateWindow();
        SetWindowPos(pWndParent,
                     50, 30, 0, 0,
                     SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOZORDER);
...
}
...
}

Refer this.