AfxEnableDRA

This function enables device resolution awareness in device application projects.

void AfxEnableDRA(BOOL bEnable);

Parameters

  • bEnable
    Specifying TRUE enables device resolution awareness; specifying FALSE, or not calling the function, disables device resolution awareness.

Remarks

The Device Resolution Awareness feature allows the application to respond to changes in resolution at run time, such as changing from portrait to landscape mode.

Use the AfxEnableDRA() function when you instantiate CDialog directly. In this situation you are using the OnSize method defined in dlgcore.cpp and implemented in the MFC DLL and LIB. In these library versions, AfxIsDRAEnabled() is used to perform a run-time check to determine whether or not to call DRA::RelayoutDialog(...). AfxIsDRAEnabled() returns true only if AfxEnableDRA(TRUE) has previously been called.

Note

When you use wizards to create an MFC project for devices, the generated code implements an override (CDialog::OnSize(int, int)) for CDialog-derived classes. Device resolution awareness is then checked at compile time, and the decision to call or not call DRA::RelayoutDialog(...) is made.

Example

AfxEnableDRA(TRUE); //Enable Device Resolution Awareness
...
void CDialog::OnSize(UINT nType, int cx, int cy)
{
    if (AfxIsDRAEnabled())
    {
        DRA::RelayoutDialog(
            AfxGetInstanceHandle(), 
            this->m_hWnd, 
            DRA::GetDisplayMode() != DRA::Portrait ? 
                m_lpszWideTemplateName : m_lpszTemplateName);
    }
    else
    {
        CWnd::OnSize(nType, cx, cy);
    }
}

See Also

Other Resources

Unique MFC for Devices Classes