SCINTILLA Usage Guide (2)

xiaoxiao2021-03-06  21

Use an overview

How do I use the ScinitLLA control? The SCINTILLA control requires two header files, SCINTILLA.H, and ScileXer.h, which defines the message macro, the data structure type used, and the like. These two header files can be included in the CPP file you want. The SCINITLLA control and the main program interactive communication are passed through messaging. In the form class, create a scinitlla control, then send a message to the control to achieve a different purpose. Sometimes, we also need the feedback of the control. For example, when the user clicks on the left side of the editor, we hope that the control can inform the parent form. At this time, the parent window receives a WM_NOTIFY message, and its parameter LPARAM can be converted to a structure. The type of SCNOTIFICATION is defined by the control header file, which is defined as follows:

struct SCNotification {struct NotifyHeader nmhdr; int position; // SCN_STYLENEEDED, SCN_MODIFIED, SCN_DWELLSTART, // SCN_DWELLEND, SCN_CALLTIPCLICK, // SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK int ch; // SCN_CHARADDED, SCN_KEY int modifiers; // SCN_KEY, SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK int modificationType; // SCN_MODIFIED const char * text; // SCN_MODIFIED int length; // SCN_MODIFIED int linesAdded; // SCN_MODIFIED int message; // SCN_MACRORECORD uptr_t wParam; // SCN_MACRORECORD sptr_t lParam; // SCN_MACRORECORD int line; // SCN_MODIFIED int foldLevelNow; // SCN_MODIFIED int foldLevelPrev; // SCN_MODIFIED int margin; // SCN_MARGINCLICK int listType; // SCN_USERLISTSELECTION int x; // SCN_DWELLSTART, SCN_DWELLEND int y; // SCN_DWELLSTART, SCN_DWELLEND};

The above SCN_MODIFIED, SCN_MARGINCLICK, SCN_STYLENEDED, etc. are all controlled different messaging macros, and through the structure, you can know that the control informs the content of the parent form.

The specific code implementation will be described below.

Before creating a control, an essential step is to load dynamic library scilexer.dll, in the initInstance () method of the WinApp class, add m_hdll = loadingLibrary (_t ("scilexer.dll"));

Where m_hdll is a member variable for the defined App class, at the same time, add // unload scintilla dllif (m_hdll! = Null) FreElibrary (m_hdll); this can use the powerful SCINTILLA control, otherwise it will appear Unable to create an error of the control.

So how do you create a SCINTILLA control? In MFC, our general practice is to create a CWND form class, a series of implementations of communication with the SCINTILLA control, and then add a member variable of the form class in the view class, through the form class to implement the control of the control. Operation, such as creation, initialization, etc. At this time, the form class that is encapsulated is considered as a control, which is called Proxy in the design mode.

We establish a CScintillaWnd ​​class as follows: class CScintillaWnd: public CWnd {public: CScintillaWnd ​​(); virtual ~ CScintillaWnd ​​(); BOOL Create (LPCTSTR lpszWindowName, DWORD dwStyle, const RECT & rect, CWnd * pParentWnd, UINT nID);}

#define str_scintillawnd_T ("scintilla")

BOOL CScintillaWnd ​​:: Create (LPCTSTR lpszWindowName, DWORD dwStyle, const RECT & rect, CWnd * pParentWnd, UINT nID) {return CWnd :: CreateEx (WS_EX_CLIENTEDGE, STR_SCINTILLAWND, lpszWindowName, dwStyle, rect, pParentWnd, (UINT) nID))}

This creates a control. In the view class, add a CSCintillaWnd ​​type member variable, for example: private: CSCintillaWnd ​​M_Wndscintilla;

In the oncreate () function of the view class, add: if (! M_wndscintilla.create (_t ("title"), WS_CHILD | WS_Visible, CRECT (0, 0, 0), this, 10000))

{AFXMessageBox ("can't create scintilla!"); Return -1;} return 0; at the same time, in the onsize () function, join: if (m_wndscintilla.getsafehwnd ()) M_Wndscintilla.MoveWindow (0, 0, CX, CY); this ensures that the control is aligned with the view, otherwise the phenomenon of the control will not be found.

After the above steps are performed, in the view class, you should see the edit window of the SCINTILLA control, and you can enter text on this window now.

转载请注明原文地址:https://www.9cbs.com/read-68196.html

New Post(0)