다음을 통해 공유


방법: 기존 MFC 리본을 리본 리소스로 변환

Ribbon resources are easier to visualize, modify, and maintain than manually coded ribbons. This topic describes how to convert a manually coded ribbon in an MFC Project into a ribbon resource.

You must have an existing MFC project that has code that uses the MFC ribbon classes, for example, CMFCRibbonBar Class.

To convert an MFC ribbon to a ribbon resource

  1. In Visual Studio, in an existing MFC project, open the source file where the CMFCRibbonBar object is initialized. Typically, the file is mainfrm.cpp. Add the following code after the initialization code for the ribbon.

    m_wndRibbonBar.SaveToXMLFile("RibbonOutput.xml");
    

    파일을 저장한 후 닫습니다.

  2. Build and run the MFC application, and then in Notepad, open RibbonOutput.txt and copy its contents.

  3. In Visual Studio, on the Project menu, click Add Resource. 리소스 추가대화 상자에서, 리본 을 선택한 다음 New을 클릭합니다.

    Visual Studio creates a ribbon resource and opens it in design view. 리본 리소스 ID는 리소스 뷰에서 표시되는 IDR_RIBBON1입니다. The ribbon is defined in the ribbon1.mfcribbon-ms XML file.

  4. In Visual Studio, open ribbon1.mfcribbon-ms, delete its contents, and then paste the contents of RibbonOutput.txt, which you copied earlier. Save and close ribbon1.mfcribbon-ms.

  5. Again open the source file where the CMFCRibbonBar object is initialized (typically, mainfrm.cpp) and comment out the existing ribbon code. Add the following code after the code that you commented out.

    m_wndRibbonBar.LoadFromResource(IDR_RIBBON1);
    
  6. Build the project and run the program.

참고 항목

개념

리본 디자이너(MFC)