drop crashrpt
[TortoiseGit.git] / ext / scintilla / doc / Steps.html
blob765268da448e57a2a84990cef2500515c944acf4
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
2 <html><head><meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"><title>How to use the Scintilla Edit Control in windows?</title></head><body bgcolor="#ffffff">
3 <p><h2>How to use the Scintilla Edit Control in windows?</h2>
4 <p>
5 This should be a little step by step explanation how to use Scintilla in the windows environment.
6 </p>
7 </p>
8 <p><h2>How to create Scintilla Edit Control?</h2>
9 <p>
10 First of all, load the Scintilla DLL with something like:
11 </p>
12 <pre>
14 hmod = LoadLibrary(&quot;SciLexer.DLL&quot;);
15 if (hmod==NULL)
17 MessageBox(hwndParent,
18 &quot;The Scintilla DLL could not be loaded.&quot;,
19 &quot;Error loading Scintilla&quot;,
20 MB_OK | MB_ICONERROR);
22 </pre>
23 <p>
24 If the DLL was loaded successfully, then the DLL has registered (yes, by itself) a new
25 window class. The new class called &quot;Scintilla&quot; is the new scintilla edit control.
26 </p>
27 <p>
28 Now you can use this new control just like any other windows control.
29 </p>
30 <pre>
32 hwndScintilla = CreateWindowEx(0,
33 &quot;Scintilla&quot;,&quot;&quot;, WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPCHILDREN,
34 10,10,500,400,hwndParent,(HMENU)GuiID, hInstance,NULL);
35 </pre>
36 <p>
37 Note the new window class name: &quot;Scintilla&quot;. By reaching this point you actually included
38 a Scintilla Edit Control to your windows program.
39 </p>
40 </p>
41 <p><h2>How to control the Scintilla Edit Control?</h2>
42 <p>
43 You can control Scintilla by sending commands to the Edit Control.
44 There a 2 ways of doing this. A simple and fast way.
45 </p>
46 <p><h3>The simple way to control Scintilla</h3>
47 <p>
48 The simple way is just like with any other windows control. You can send messages to the
49 Scintilla Edit Control and receive notifications from the control. (Note that the notifications
50 are sent to the parent window of the Scintilla Edit Control.)
51 </p>
52 <p>
53 The Scintilla Edit Control knows a special message for each command.
54 To send commands to the Scintilla Edit Control you can use the SendMessage function.
55 </p>
56 <pre>
58 SendMessage(hwndScintilla,sci_command,wparam,lparam);
59 </pre>
60 <p>
61 like:
62 </p>
63 <pre>
65 SendMessage(hwndScintilla,SCI_CREATEDOCUMENT, 0, 0);
66 </pre>
67 <p>
68 Some of the commands will return a value and unused parameters should be set to NULL.
69 </p>
70 </p>
71 <p><h3>The fast way to control Scintilla</h3>
72 <p>
73 The fast way of controlling the Scintilla Edit Control is to call message handling function by yourself.
74 You can retrieve a pointer to the message handling function of the Scintilla Edit Control and
75 call it directly to execute a command. This way is much more faster than the SendMessage() way.
76 </p>
77 <p>
78 1st you have to use the SCI_GETDIRECTFUNCTION and SCI_GETDIRECTPOINTER commands to
79 retrieve the pointer to the function and a pointer which must be the first parameter when calling the retrieved
80 function pointer.
81 You have to do this with the SendMessage way :)
82 </p>
83 <p>
84 The whole thing has to look like this:
85 </p>
86 <pre>
88 int (*fn)(void*,int,int,int);
89 void * ptr;
90 int canundo;
92 fn = (int (__cdecl *)(void *,int,int,int))SendMessage(
93 hwndScintilla,SCI_GETDIRECTFUNCTION,0,0);
94 ptr = (void *)SendMessage(hwndScintilla,SCI_GETDIRECTPOINTER,0,0);
96 canundo = fn(ptr,SCI_CANUNDO,0,0);
97 </pre>
98 <p>
99 with &quot;fn&quot; as the function pointer to the message handling function of the Scintilla Control
100 and &quot;ptr&quot; as the pointer that must be used as 1st parameter.
101 The next parameters are the Scintilla Command with its two (optional) parameters.
102 </p>
104 </p>
105 <p><h3>How will I receive notifications?</h3>
107 Whenever an event occurs where Scintilla wants to inform you about something, the Scintilla Edit Control
108 will send notification to the parent window. This is done by a WM_NOTITY message.
109 When receiving that message, you have to look in the xxx struct for the actual message.
110 </p>
112 So in Scintillas parent window message handling function you have to include some code like this:
113 </p>
114 <pre>
115 NMHDR *lpnmhdr;
117 [...]
119 case WM_NOTIFY:
120 lpnmhdr = (LPNMHDR) lParam;
122 if(lpnmhdr-&gt;hwndFrom==hwndScintilla)
124 switch(lpnmhdr-&gt;code)
126 case SCN_CHARADDED:
127 /* Hey, Scintilla just told me that a new */
128 /* character was added to the Edit Control.*/
129 /* Now i do something cool with that char. */
130 break;
133 break;
134 </pre>
135 </p>
136 </p>
139 <i>Page contributed by Holger Schmidt.</i>
140 </p>
141 </body></html>