Search

'전체 글'에 해당되는 글 113건

  1. 2008.02.29 RichEdit 관련

RichEdit 관련

Program Visual C++ 2008. 2. 29. 11:37 Posted by HisPark

RichEditCtrl은 다른 콘트롤들과 달리 설정해 줘야 되는게 많네요...

아마도 외부 콘트롤이라서 그런것 같은데, 버전도 1.0, 2.0, 3.0 까지 있는데,

Win98에서는 2.0을, 2000이나 XP는 3.0을 사용하는 것 같습니다.

특이한 것이 DLL의 이름이 1.0은 'RichEd32.dll'이고, 2.0과 3.0은 'RichEd20.dll'로 동일합니다. (뭘로 구분하죠? -_;;)




--------------------------------------------------------------------------------

(1) 일단 RichEditCtrl를 사용하는 프로그램은 CWinApp를 상속받은 클래스내 InitInstance() 함수에서 'AfxInitRichEdit(); "을  추가 해줘야 한다!
  

이것을 왜 해줘야 하는지 위 함수를 추적해보니 아래의 내용을 처럼. 'RichEd32.dll'가 로드 안되어 있으면,

로드를 해주는 함수 LoadLibraryA()를 호출해주더군요...

이걸 안해주니..전혀 엉뚱하게 MFC내 CDialog나 CFormView같은 클래스 생성 함수에서 오류가 뜨더군요...

Windows2000에서 동작확인시에는 'RichEd32.dll' 이 로드되고, 이게 다시 'RichEd20.dll'을 로드하더군요.

  

/*

BOOL PASCAL AfxInitRichEdit()

{

    _AFX_RICHEDIT_STATE* pState = _afxRichEditState;

    if (pState->m_hInstRichEdit == NULL)

        pState->m_hInstRichEdit = LoadLibraryA("RICHED32.DLL");

    return pState->m_hInstRichEdit != NULL;

}

*/

--------------------------------------------------------------------------------

(2) VC6.0 클래스 위자드 내에 RichEditCtrl 사용 메세지중 NM_ 으로 사용되는 메세지는 사용할 수 없다!
  

문서에는 NM_이 아니라 EN_으로 시작되는 Notification Message들에 대해 설명되어 있습니다.

  

NM_CLICK, NM_DBCLICK, NM_KILLFOCUS, NM_OUTOFMEMORY, NM_RCLICK, NM_RDBLCLK, NM_RETURN, NM_SETFOCUS

  

테스트 해보면, 위에 있는 이런 메세지를 클래스 위자드에서 연결을 시켜도 호출자체가 안 일어나더군요.

대신에 아래와 같이 EN_ 으로 시작하는 메세지가 존제하는데,

개인적인 생각으로는 Class Wizards 만든 분(?)이 RichEditCtrl용 메세지를 다른 것들과 혼돈하여

EN_(EditCtrl Notification Message)가 아닌 NM_(Notification Message)으로 사용한 것이 아닌가하는 추축이 듭니다. (믿거나 말거나 -_;;)

아래와 같은 메세지들은 잘 동작합니다.



EN_CORRECTTEXT , EN_DRAGDROPDONE, EN_DROPFILES, EN_IMECHANGE, EN_LINK, EN_MSGFILTER
EN_OBJECTPOSITIONS , EN_PROTECTED, EN_REQUESTRESIZE, EN_SELCHANGE ,EN_ALIGNLTR , EN_ALIGNRTL , EN_OLEOPFAILED , EN_SAVECLIPBOARD , EN_STOPNOUNDO
  
음...하여간 RichEditCtrl은 OS에서 제공한다뿐이지 다른 콘트롤과는 확연히 다른 콘트롤이라는 생각을 가지고 있어야 할 것 같습니다.




--------------------------------------------------------------------------------

(3) RichEditCtrl에서 마우스나 키보드 관련 이벤트를 사용하고자 하는 경우에는 다음과 같은 절차를 따른다.
  

초기화 함수(OnInitDialog() 혹은 OnInitUpdate())에서 받고자 하는 메세지의 종류에 대해 이벤트 마스크 플래그를  별도로 설정 해줘야 합니다. (문서 안 읽고, 클래스 위자드만 보면, 그냥 해주면 되는 것 같은 착각이 들기도 합니다..-_;:)

  

    CRichEditCtrl *pWndRichEditCtrl = (CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1);

    pWndRichEditCtrl->SetEventMask(pWndRichEditCtrl->GetEventMask() | ENM_MOUSEEVENTS | ENM_SCROLLEVENTS | ENM_KEYEVENTS);
    // 다른 것도 추가로 사용하고자 한다면 이벤트 마스크 플래그를 더 추가해주면 됩니다.


그리고, 'EN_MSGFILTER' 메세지 처리용 함수를 아래와 같이 유사(?)하게 구현한다  
  

void CxFormView::OnMsgfilterRichedit1(NMHDR* pNMHDR, LRESULT* pResult)
{
    MSGFILTER *pMsgFilter = reinterpret_cast<MSGFILTER *>(pNMHDR);
    // TODO: The control will not send this notification unless you override the
    // CFormView::OnInitDialog() function to send the EM_SETEVENTMASK message
    // to the control with either the ENM_KEYEVENTS or ENM_MOUSEEVENTS flag
    // ORed into the lParam mask.

    // TODO: Add your control notification handler code here
    switch(pMsgFilter->msg)
    {
    case WM_RBUTTONDOWN:    // 마우스 우측버턴에 대한 처리를 해주고자 하는 경우.
        OnRclickRichedit1(&pMsgFilter->nmhdr, pResult);    // NM_RCLICK 함수형태로 된 함수 콜~
        break;
    }
    *pResult = 0;
}

  

void CxFormView::OnRclickRichedit1(NMHDR* pNMHDR, LRESULT* pResult)
{
    // TODO: Add your control notification handler code here
    AfxMessageBox("아직 기능 구현 중입니다.");
    *pResult = 0;
}




** 아래 내용은 참고하시고 보시면 더 좋을 것 같습니다.



좋은 하루 되십시요.


--------------------------------------------------------------------------------



Platform SDK: Windows User Interface


About Rich Edit Controls
The original specification for rich edit controls is Rich Edit 1.0; the current specification is Rich Edit 3.0. Each version of rich edit is a superset of the preceding one, except that only Asian builds of Rich Edit 1.0 have a vertical text option. Before creating a rich edit control, you should call the LoadLibrary function to verify which version of Rich Edit is installed. The following table shows which DLL corresponds with which version of rich edit. Note that the name of the file did not change from version 2.0 to version 3.0. This allows version 2.0 to be upgraded to version 3.0 without breaking existing code.



Rich Edit version DLL
1.0 Riched32.dll
2.0 Riched20.dll
3.0 Riched20.dll


Windows NT/Windows 2000

Microsoft® Windows NT® version 4.0 includes Rich Edit 1.0 and 2.0. Microsoft Windows®  2000 includes Rich Edit 3.0 with a Rich Edit 1.0 emulator.

Windows 98

Windows 98 includes Rich Edit 1.0 and 2.0.

Windows 95

Windows 95 includes only Rich Edit 1.0. However, Riched20.dll is compatible with Windows 95 and may be installed if an application that uses Rich Edit 2.0 has been installed.



--------------------------------------------------------------------------------

Creating a Rich Edit Control
To create a rich edit control, call the CreateWindowEx function, specifying the rich edit window class. If you are using Rich Edit 1.0 (Riched32.dll), specify RichEdit for the window class parameter. If you are using Rich Edit 2.0 or later (Riched20.dll), specify RICHEDIT_CLASS for the window class parameter.

Rich edit controls support most of the window styles used with edit controls as well as additional styles. You should specify the ES_MULTILINE window style if you want to allow more than one line of text in the control.



--------------------------------------------------------------------------------


Miscellaneous Notification Messages
A rich edit control's parent window can process notification messages to monitor events affecting the control. Rich edit controls support all of the notification messages used with edit controls as well as several additional ones. You can determine which notification messages a rich edit control sends its parent window by setting its event mask.

To set the event mask for a rich edit control, use the EM_SETEVENTMASK message. You can retrieve the current event mask for a rich edit control by using the EM_GETEVENTMASK message. For a list of event mask flags, see Rich Edit Control Event Mask Flags.

A rich edit control's parent window can filter all keyboard and mouse input to the control by processing the EN_MSGFILTER notification message. The parent window can prevent the keyboard or mouse message from being processed or can change the message by modifying the specified MSGFILTER structure.

An application can process the EN_PROTECTED notification message to detect when the user attempts to modify protected text. To mark a range of text as protected, you can set the protected character effect. For more information, see Text Formatting.

You can enable the user to drop files in a rich edit control by processing the EN_DROPFILES notification message. The specified ENDROPFILES structure contains information about the files being dropped.

For lists of the edit control and rich edit control notification messages, see Rich Edit Notification Messages and Edit Control Notification Messages.




--------------------------------------------------------------------------------

Rich Edit Control Event Mask Flags
The event mask specifies which notification messages a rich edit control sends to its parent window. The event mask can be none or a combination of these values.



Value Meaning
ENM_CHANGE Sends EN_CHANGE notifications.
ENM_CORRECTTEXT Sends EN_CORRECTTEXT notifications.
ENM_DRAGDROPDONE Sends EN_DRAGDROPDONE notifications.
ENM_DROPFILES Sends EN_DROPFILES notifications.
ENM_IMECHANGE Rich Edit 1.0 only: Sends EN_IMECHANGE notifications when the IME conversion status has changed. Only for Asian-language versions of the operating system.
ENM_KEYEVENTS Sends EN_MSGFILTER notifications for keyboard events.
ENM_LINK Rich Edit 2.0 and later: Sends EN_LINK notifications when the mouse pointer is over text that has the CFE_LINK and one of several mouse actions is performed.
ENM_MOUSEEVENTS Sends EN_MSGFILTER notifications for mouse events.
ENM_OBJECTPOSITIONS Sends EN_OBJECTPOSITIONS notifications.
ENM_PROTECTED Sends EN_PROTECTED notifications.
ENM_REQUESTRESIZE Sends EN_REQUESTRESIZE notifications.
ENM_SCROLL Sends EN_HSCROLL and EN_VSCROLL notifications.
ENM_SCROLLEVENTS Sends EN_MSGFILTER notifications for mouse wheel events.
ENM_SELCHANGE Sends EN_SELCHANGE notifications.
ENM_UPDATE Sends EN_UPDATE notifications.
Rich Edit 2.0 and later: this flag is ignored and the EN_UPDATE notifications are always sent. However, if Rich Edit 3.0 emulates Rich Edit 1.0, you must use this flag to send EN_UPDATE notifications..




The default event mask is ENM_NONE in which case no notification messages are sent to the parent window. You can retrieve and set the event mask for a rich edit control by using the EM_GETEVENTMASK and EM_SETEVENTMASK messages.



'Program Visual C++' 카테고리의 다른 글

AfxBeginThread 사용법?  (0) 2009.05.05
Microsoft Platform SDK  (0) 2009.02.25
VC++ UNICODE Build - Configuration  (0) 2007.07.12
ActiveX 보안관련 설정  (0) 2007.05.25
Tray  (0) 2007.05.21