< Æú´õ ¼±Åà ´ÙÀ̾ó·Î±× >

¡¡WTL¿¡¼­ common dialogÀÇ ÆùÆ® ¼±Åà ´ÙÀ̾ó·Î±×¸¦ CFontDialogImplÀ̶ó°í ÇÏ´Â ÅÛÇø´ Ŭ·¡½º¿¡¼­ ĸ½¶È­Çϰí ÀÖ½À´Ï´Ù.  ÀÌ Å¬·¡½º´Â ATLÀÇ CDialogImplŬ·¡½º¿Í °°ÀÌ base class·Î¼­ÀÇ º¸°í »ç¿ëÇÕ´Ï´Ù. atldlgs.h Çì´õ¿¡¼­´Â CFontDialogImpl Ŭ·¡½ºÀÇ »ó¼Ó Ŭ·¡½º·Î¼­  CFontDialog Ŭ·¡½º°¡ Á¤Àǵǰí ÀÖ½À´Ï´Ù.

// atldlgs.h

class CFontDialog : public CFontDialogImpl<CFontDialog>

{

    ...

    ...

                      


¡¡WTL
ÀÇ CFontDialogŬ·¡½º´Â MFCÀÇ µ¿¸íÀÇ Å¬·¡½º¿Í °ÅÀÇ °°Àº ¸â¹ö ÇÔ¼ö¸¦ ÁغñÇØ ÀÖ½À´Ï´Ù. ÀÌÇÏ¿¡ ³ªÅ¸³»´Â °ÍÀº CFontDialog Ŭ·¡½º¸¦ »ç¿ëÇÏ´Â ¿¹ÀÔ´Ï´Ù.

 

CFontDialog dlg;

 

if(dlg.DoModal() == IDOK){

    CString strMsg;

    strMsg.Format(_T("ÆùÆ®¸í£º%s\n»çÀÌÁ%dpt"),

        dlg.GetFaceName(), dlg.GetSize() / 10);

    MessageBox(strMsg);

}

                      


CFontDialog Ŭ·¡½ºÀÇ constructorÀμö´Â ¸ðµÎ »ý·« ÇÒ ¼ö ÀÖ½À´Ï´Ù.  Àμö´Â ¼ø¼­·Î ÆùÆ® ¼±Åà ´ÙÀ̾ó·Î±×ÀÇ Ãʱ⠻óŸ¦ ¼³Á¤Çϱâ À§ÇÑ LOGFONT±¸Á¶Ã¼¿¡ÀÇ Æ÷ÀÎÅÍ , Ç÷¡±× , ÇÁ¸°ÅÍ µð¹ÙÀ̽º ÄÜÅØ½ºÆ® , ºÎ¸ð À©µµ¿ìÀÇ ÇÚµéÀ» ÁöÁ¤ÇÒ ¼ö ÀÖ½À´Ï´Ù.

ÆùÆ® ¼±Åà ´ÙÀ̾ó·Î±×¸¦ Ç¥½ÃÇϱâ À§Çؼ­´Â DoModal()À» »ç¿ëÇÕ´Ï´Ù.  [OK] ¹öưÀ» ´­·¯ ÆùÆ® ¼±Åà ´ÙÀ̾ó·Î±×¸¦ ´Ý¾ÒÀ» °æ¿ì´Â,  ¹Ýȯ°ªÀ¸·Î¼­ IDOK°¡  [ĵ½½]À» ´­·¯ ´Ý¾ÒÀ» °æ¿ì´ÂIDCANCELÀÌ µÇµ¹¾Æ ¿É´Ï´Ù.

IDOK°¡ ¹ÝȯµÈ °æ¿ì´Â CFontDialog Ŭ·¡½ºÀÇ ¸â¹öÀÎ m_cf¿¡ ÆùÆ®ÀÇ Á¤º¸°¡ ¼³Á¤µÇ¾î ÀÖ½À´Ï´Ù. CFontDialogŬ·¡½º´Â ÀÌ Á¤º¸¸¦ ÃëµæÇϱâ À§ÇÑ ¸â¹ö ÇÔ¼ö¸¦ ÁغñÇØ ÀÖ½À´Ï´Ù.

CFontDialogImplŬ·¡½ºÀÇ »ó¼Ó Ŭ·¡½º¿¡ ¸Þ¼¼Áö ¸ÊÀ» ÁغñÇÏ´Â °Í¿¡ ÀÇÇØ ÆùÆ® ¼±Åà ´ÙÀ̾ó·Î±×ÀÇ µ¿ÀÛÀ» Ä¿½ºÅÒ¸¶ÀÌÁî ÇÒ ¼ö°¡ ÀÖ½À´Ï´Ù.

´ÙÀ½¿¡ ³ªÅ¸³»´Â °ÍÀº WM_INITDIALOG ¸Þ¼¼Áö Çڵ鷯¸¦ ÁغñÇÏ¿© µ¶ÀÚÀûÀÎ ÆùÆ® ¼±Åà ´ÙÀ̾ó·Î±×¸¦ ÀÛ¼ºÇÏ´Â ¿¹ÀÔ´Ï´Ù.  ÀÌ ÆùÆ® ¼±Åà ´ÙÀ̾ó·Î±×¿¡´Â [ÇïÇÁ] ¹öưÀÌ Ãß°¡µÇ¾î ºÎ¸ð À©µµ¿ìÀÇ Áß¾Ó¿¡ Ç¥½ÃµË´Ï´Ù.  ÀÌ ¿¹¿¡¼­´Â CustomDlg.h À̶ó°í ÇÏ´Â Çì´õ ÆÄÀÏÀ» ÁغñÇÏ¿© °Å±â¿¡ CCustomDlgŬ·¡½º¸¦ Á¤ÀÇÇϰí ÀÖ½À´Ï´Ù.

 

// CustomDlg.h

class CCustomDlg : public CFontDialogImpl<CCustomDlg>

{

public:

    UINT m_uHelpMsg;  // [ÇïÇÁ]¹öư¿ë ¸Þ¼¼ÁöID

 

    // constructor¡¡ ¡¡

    CCustomDlg(LPLOGFONT lplfInitial = NULL,

        DWORD dwFlags = CF_EFFECTS | CF_SCREENFONTS,

        HDC hDCPrinter = NULL)

        : CFontDialogImpl<CCustomDlg>(lplfInitial, dwFlags, hDCPrinter), m_uHelpMsg(0)

    {

        // [ÇïÇÁ]¹öưÀ» Ç¥½ÃÇϱâ À§Çؼ­CF_SHOWHELPÇ÷¡±× Ãß°¡

        m_cf.Flags |= CF_SHOWHELP;

    }

 

    BEGIN_MSG_MAP_EX(CCustomDlg)

        MSG_WM_INITDIALOG(OnInitDialog)

        MESSAGE_HANDLER_EX(m_uHelpMsg, OnHelp)

    END_MSG_MAP()

 

    LRESULT OnInitDialog(HWND hWnd, LPARAM lParam){

        m_cf.hwndOwner = m_hWnd;

 

        // [ÇïÇÁ]¹öư¿ë ¸Þ¼¼Áö¸¦ µî·Ï

        m_uHelpMsg = RegisterWindowMessage(HELPMSGSTRING);

 

        CenterWindow();

 

        return TRUE;

    }

 

    LRESULT OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam){

        MessageBox(_T("ÇïÇÁ ¹öưÀ» ´­·¶½À´Ï´Ù. "));

        return 0;

    }

};

                      


CCustomDlgŬ·¡½ºÀÇ constructorÀμö´Â CFontDialogŬ·¡½ºÀÇ  constructorÀμö¸¦ Âü°í·Î Çϰí ÀÖ½À´Ï´Ù. constructor³»¿¡¼­´Â ÆùÆ® ¼±Åà ´ÙÀ̾ó·Î±×¿¡ [ÇïÇÁ] ¹öưÀ» Ãß°¡Çϱâ À§Çؼ­ CF_SHOWHELPÇ÷¡±×¸¦ Ãß°¡ÇÕ´Ï´Ù. OnInitDialog()¿¡¼­  m_cf.hwndOwner¿¡ [ÇïÇÁ] ¹öư¿ë ¸Þ¼¼Áö¸¦ ¼ö½ÅÇÏ´Â À©µµ¿ì ÇÚµé (Áï ÆùÆ® ¼±Åà ´ÙÀ̾ó·Î±× ÀÚ½ÅÀÇ ÇÚµé) À» ¼³Á¤ÇØ [ÇïÇÁ] ¹öưÀ» ´­·¶À» ¶§ÀÇ ¸Þ¼¼Áö¸¦ µî·ÏÇØ ¸Þ¼¼ÁöID¸¦ m_uHelpMsg·Î ¼³Á¤ÇÕ´Ï´Ù. ±×¸®°í CenterWindow()¿¡ ÀÇÇØ ´ÙÀ̾ó·Î±×¸¦ Áß¾Ó¿¡ Ç¥½ÃÇϰí ÀÖ½À´Ï´Ù.  OnHelp()´Â [ÇïÇÁ] ¹öưÀ» ´­·¶À» ¶§¿¡ ºÒ·Á Áý´Ï´Ù.  ¿©±â¿¡¼­´Â ¸Þ½ÃÁö ¹Ú½º·Î Ç¥½ÃÇϰí ÀÖÀ» »ÓÀÔ´Ï´Ù.

¡¡
´ÙÀ½¿¡ ³ªÅ¸³»´Â °ÍÀº CCustomDlgŬ·¡½º¸¦ »ç¿ëÇÏ´Â ¿¹ÀÔ´Ï´Ù.

// stdafx.h

#include <atlbase.h>

#include <atlapp.h>

extern CAppModule _Module;

#include <atlwin.h>

 

#include <atlcrack.h>

#include <atlmisc.h>

#include <atldlgs.h>  // common dialog¸¦ »ç¿ëÇϱâ À§ÇØ(¶§¹®¿¡)

                      

 

// maindlg.h

class CMainDlg : public CDialogImpl<CMainDlg>

{

public:

    enum { IDD = IDD_MAINDLG };

 

    // ¸Þ¼¼Áö ¸Ê

    BEGIN_MSG_MAP_EX(CMainDlg)

        MSG_WM_INITDIALOG(OnInitDialog)

        COMMAND_ID_HANDLER_EX(IDC_BUTTON_OPENDLG, OnButtonOpenDlg)

        COMMAND_ID_HANDLER_EX(IDOK, OnOK)

        COMMAND_ID_HANDLER_EX(IDCANCEL, OnCancel)

    END_MSG_MAP()

 

    LRESULT OnInitDialog(HWND hWnd, LPARAM lParam){

        // ½ºÅ©¸°ÀÇ Áß¾Ó¿¡ ¹èÄ¡

        CenterWindow();

 

        // Å« ¾ÆÀÌÄÜ ¼³Á¤

        HICON hIcon = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR,

            ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON));

        SetIcon(hIcon, TRUE);

       

        // ÀÛÀº ¾ÆÀÌÄÜ ¼³Á¤

        HICON hIconSmall = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR,

            ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON));

        SetIcon(hIconSmall, FALSE);

 

        return TRUE;

    }

 

    void OnButtonOpenDlg(UINT uNotifyCode, int nID, HWND hWndCtl){

        CCustomDlg dlg;

 

        if(dlg.DoModal() == IDOK){

            CString strMsg;

            strMsg.Format(_T("ÆùÆ®¸í£º%s\n»çÀÌÁ%dpt"),

                dlg.GetFaceName(), dlg.GetSize() / 10);

            MessageBox(strMsg);

        }

    }

 

    void OnOK(UINT uNotifyCode, int nID, HWND hWndCtl){

        EndDialog(nID);

    }

 

    void OnCancel(UINT uNotifyCode, int nID, HWND hWndCtl){

        EndDialog(nID);

    }

};

                      

 

// CommDlg.cpp

#include "stdafx.h"

 

#include "resource.h"

 

#include "CustomDlg.h"

#include "maindlg.h"

 

CAppModule _Module;

 

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR lpCmdLine, int nCmdShow)

{

    HRESULT hRes = ::CoInitialize(NULL);

    ATLASSERT(SUCCEEDED(hRes));

 

    ::DefWindowProc(NULL, 0, 0, 0L);

 

    AtlInitCommonControls(ICC_COOL_CLASSES | ICC_WIN95_CLASSES);

 

    hRes = _Module.Init(NULL, hInstance);

    ATLASSERT(SUCCEEDED(hRes));

 

    int nRet = 0;

    // BLOCK: ¾îÇø®ÄÉÀÌ¼Ç ½ÇÇà

    {

        CMainDlg dlgMain;

        nRet = dlgMain.DoModal();

    }

 

    _Module.Term();

    ::CoUninitialize();

 

    return nRet;

}

                      


¡¡
¿ì¼±  ¸®¼Ò½º¸¦ ÀÛ¼ºÇÕ´Ï´Ù. ´ÙÀ̾ó·Î±×¿¡ ¹öư ÄÁÆ®·ÑÀ» ¹èÄ¡ÇÏ¿© ¸®¼Ò½º ID¸¦ ´ÙÀ½°ú °°ÀÌ ÁöÁ¤ÇÕ´Ï´Ù.

ÄÁÆ®·Ñ¸í

¸®¼Ò½º ID

Ǫ½¬ ¹öư

IDC_BUTTON_OPENDLG


¡¡
´ÙÀ½¿¡ stdafx.h ¿¡¼­´Â atldlgs.h Çì´õ¸¦ ÀÎŬ·çµå ÇÕ´Ï´Ù.

¡¡
CMainDlgŬ·¡½º¿¡¼­´Â ¹öư¿ëÀÇ Ä¿¸àµå ¸Þ¼¼Áö Çڵ鷯 OnButtonOpenDlg()¸¦ Ãß°¡ÇÏ¿© °Å±â¼­ CCustomDlgŬ·¡½ºÀÇ ÀνºÅϽº¸¦ ÀÛ¼ºÇØ  DoModal()¿¡ ÀÇÇØ µ¶ÀÚÀûÀÎ ÆùÆ® ¼±Åà ´ÙÀ̾ó·Î±×¸¦ Ç¥½ÃÇÕ´Ï´Ù.

¡¡
¸¶Áö¸·À¸·Î CommDlg.cpp ¿¡¼­ maindlg.h Çì´õÀÇ Àü¿¡ CustomDlg.h Çì´õ¸¦ ÀÎŬ·çµå ÇÕ´Ï´Ù.



¸®Ä¡ ¿¡µðÆ® ÆùÆ® ¼±Åà ´ÙÀ̾ó·Î±×

¡¡CFontDialogŬ·¡½º¿¡¼­´Â ÆùÆ® ¼±Åà ´ÙÀ̾ó·Î±×ÀÇ Ãʱ⠻óŸ¦ ¼³Á¤Çϰųª  GetCurrentFont()¸¦ È£ÃâÇØ ÆùÆ® ¼±Åà ´ÙÀ̾ó·Î±×·Î ¼±ÅÃÇÑ Ç׸ñÀ» ÃëµæÇϱâ À§Çؼ­LOGFONT±¸Á¶Ã¼¸¦ »ç¿ëÇß½À´Ï´Ù. CRichEditFontDialogŬ·¡½º¸¦ »ç¿ëÇÏ¸é ±×·¯ÇÑ ¿ëµµ¸¦ À§Çؼ­ ¸®Ä¡ ¿¡µðÆ® ÄÁÆ®·ÑÀÇ ¼­½Ä Á¤º¸¸¦ ³ªÅ¸³»´ÂCHARFORMAT±¸Á¶Ã¼¸¦ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.

¡¡
CRichEditFontDialogŬ·¡½ºÀÇ  base classÀÎ CRichEditFontDialogImplŬ·¡½º´Â  CFontDialogImpl Ŭ·¡½º·ÎºÎÅÍ ÆÄ»ýÇϰí ÀÖ½À´Ï´Ù.  atldlgs.h Çì´õ¿¡¼­´Â ´ÙÀ½°ú °°ÀÌ Á¤Àǵǰí ÀÖ½À´Ï´Ù.

// atldlgs.h

template <class T>

class ATL_NO_VTABLE CRichEditFontDialogImpl : public CFontDialogImpl< T >

{

    ...

    ...

};

 

class CRichEditFontDialog : public CRichEditFontDialogImpl<CRichEditFontDialog>

{

    ...

    ...

};

                      


¡¡
ÀÌÇÏ¿¡ ³ªÅ¸³»´Â °ÍÀº CRichEditFontDialogŬ·¡½º¸¦ »ç¿ëÇÏ´Â ¿¹ÀÔ´Ï´Ù.

// Ãʱ⠻óÅ·Î10Æ÷ÀÎÆ®·Î »¡°­ÀÇArialÆùÆ®¸¦ ¼±ÅÃ

CHARFORMAT cfset = {sizeof(CHARFORMAT)};

cfset.dwMask = CFM_FACE | CFM_SIZE | CFM_COLOR; // ¼³Á¤ÇÏ´Â Ç׸ñÀ» ÁöÁ¤

lstrcpy(cfset.szFaceName, _T("Arial"));

cfset.yHeight = 10 * 20;

cfset.crTextColor = RGB(255, 0, 0);

 

CRichEditFontDialog dlg(cfset, CF_SCREENFONTS | CF_EFFECTS);

 

if(dlg.DoModal() == IDOK){

    CHARFORMAT cfget;

    dlg.GetCharFormat(cfget);

 

    CString strMsg;

    strMsg.Format(_T("ÆùÆ®¸í£º%s\n»çÀÌÁ%dpt"),

        cfget.szFaceName, cfget.yHeight / 20);

    MessageBox(strMsg);

}

                      


CRichEditFontDialog Ŭ·¡½º¸¦ »ç¿ëÇϱâ À§Çؼ­´Â atldlgs.h Çì´õÀÇ ¾Õ¿¡ richedit.hÇì´õ¸¦ ÀÎŬ·çµå ÇÒ Çʿ䰡 ÀÖ½À´Ï´Ù.  µ¡ºÙ¿© atlctrls.h Çì´õ¸¦ ÀÎŬ·çµå Çϸé ÀÚµ¿ÀûÀ¸·Î richedit.h Çì´õµµ ÀÎŬ·çµå µË´Ï´Ù.

CRichEditFontDialog Ŭ·¡½ºÀÇ constructorÀÇ Á¦1Àμö¿¡´Â CHARFORMAT ±¸Á¶Ã¼ÀÇ ÂüÁ¶¸¦ ÁöÁ¤ÇÕ´Ï´Ù. ³ª¸ÓÁöÀÇ Àμö´Â »ý·« °¡´ÉÇÏ¿© ¼ø¼­¿¡ Ç÷¡±× , ÇÁ¸°ÅÍ µð¹ÙÀ̽º ÄÜÅØ½ºÆ® , ºÎ¸ð À©µµ¿ìÀÇ ÇÚµéÀ» ÁöÁ¤ÇÒ ¼ö ÀÖ½À´Ï´Ù.

DoModal()ÀÇ È£Ãâ ÈÄ GetCharFormat()¿¡ ÀÇÇØ ¼­½Ä Á¤º¸¸¦ ²¨³À´Ï´Ù. µ¡ºÙ¿© CRichEditFontDialog Ŭ·¡½ºÀÇ  base class¿¡´Â CFontDialogImplŬ·¡½º°¡ Àֱ⠶§¹®¿¡ ¼­½Ä Á¤º¸¸¦ ÃëµæÇϱâ À§Çؼ­ GetFaceName()³ª GetSize() µîÀÇ ¸â¹ö ÇÔ¼ö¸¦ »ç¿ëÇÒ ¼öµµ ÀÖ½À´Ï´Ù.