1 /* Edit Control Test for ReactOS, quick n' dirty. Very rigid too.
2 * There you go, is only a test program. Not made to be fast, small
3 * easy to mantain, or portable. Lots of duplicated code too.
5 * I'm not erasing text because I don't want to use other functions from th API
6 * or make this more complex.
8 * This source code is in the PUBLIC DOMAIN and has NO WARRANTY.
9 * by Waldo Alvarez CaƱizares <wac at ghost.matcom.uh.cu>, June 22, 2003. */
11 //#define WIN32_LEAN_AND_MEAN
15 #define CREATEWINDOW 106
16 #define CREATEWINDOWEX 107
17 #define CREATEWINDOWW 108
25 #define BUFFERLEN 80 /* Size of buffer to hold result strings */
27 /* Edit is created with this text */
28 #define TestStr "The quick brown fox jumps over the lazy dog"
30 #define TestStrW L"This is a WCHAR string" /* Wide to support unicode edits */
32 #define MAXMESSAGEBUTTONS 42
35 HINSTANCE g_hInst
= NULL
;
43 DWORD EditWidth
= 240;
44 DWORD EditHeight
= 250;
46 BOOL UnicodeUsed
= FALSE
;
51 RECT rect
= {0,0,20,20},rect2
;
54 #define ReplaceTextStr "->> Replaced!! <<-"
56 char* AllocatedText
; /* Buffer in the heap to feed it to the edit control */
57 char* NewText
= "New text for the edit control";
58 wchar_t* NewTextW
= L
"New text for the edit control in UNICODE"; // Wide
60 char TextBuffer
[BUFFERLEN
]={'R','e','s','u','l','t',':',' '};
62 typedef void FunctionHandler(HWND
,DWORD
,WPARAM
,LPARAM
);
63 typedef FunctionHandler
* LPFUNCTIONHANDLER
;
66 PrintTextXY(char* Text
,int x
,int y
,int len
)
70 SelectObject (hdc
, GetStockObject (SYSTEM_FIXED_FONT
));
72 TextOut (hdc
, x
,y
,Text
,len
);
73 ReleaseDC (g_hwnd
, hdc
);
74 ValidateRect (g_hwnd
, &rect
);
79 HandlePrintReturnHex(HWND handle
,DWORD Msg
,WPARAM wParam
,LPARAM lParam
)
82 ret
= SendMessage(handle
,Msg
,wParam
,lParam
);
83 htoa(ret
,&TextBuffer
[8]);
84 PrintTextXY(TextBuffer
,ResultX
,ResultY
,16);
89 HandleSetHandlePrintHex(HWND handle
,DWORD Msg
,WPARAM wParam
,LPARAM lParam
)
95 LocalFree((HLOCAL
)SendMessage(handle
, EM_GETHANDLE
, 0, 0L));
98 hNewBuffer
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, 100);
99 pMem
= LocalLock(hNewBuffer
);
100 strcpyw_((wchar_t*)pMem
,NewTextW
);
104 hNewBuffer
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
,50);
105 pMem
= LocalLock(hNewBuffer
);
106 strcpy_((char*)pMem
,NewText
);
110 hNewBuffer
= LocalHandle(pMem
);
112 /* Updates the buffer and displays new buffer */
113 ret
= SendMessage(handle
, EM_SETHANDLE
, (WPARAM
)hNewBuffer
, 0L);
115 htoa(ret
,&TextBuffer
[8]);
116 PrintTextXY(TextBuffer
,ResultX
,ResultY
,16);
121 HandlePrintReturnStr(HWND handle
,DWORD Msg
,WPARAM wParam
,LPARAM lParam
)
124 TextBuffer
[8] = (char)(BUFFERLEN
- 8); /* Setting the max size to put chars in first byte */
125 ret
= SendMessage(handle
,Msg
,wParam
,lParam
);
126 PrintTextXY(TextBuffer
,ResultX
,ResultY
,8+ret
);
131 HandlePrintRect(HWND handle
,DWORD Msg
,WPARAM wParam
,LPARAM lParam
)
133 TextBuffer
[8] = (char)(BUFFERLEN
- 8); /* Setting the max size to put chars in first byte */
134 SendMessage(handle
,Msg
,wParam
,lParam
);
136 htoa(rect
.top
,&TextBuffer
[8]);
137 TextBuffer
[8+8] = ' ';
138 htoa(rect
.bottom
,&TextBuffer
[8+8+1]);
139 TextBuffer
[8+8+8+1] = ' ';
140 htoa(rect
.left
,&TextBuffer
[8+8+8+1+1]);
141 TextBuffer
[8+8+8+8+1+1] = ' ';
142 htoa(rect
.right
,&TextBuffer
[8+8+8+8+1+1+1]);
144 PrintTextXY(TextBuffer
,ResultX
,ResultY
,8+4*9-1);
149 HandlePrintPasswdChar(HWND handle
,DWORD Msg
,WPARAM wParam
,LPARAM lParam
)
152 int ret
= SendMessage(handle
,Msg
,wParam
,lParam
);
159 TextBuffer
[8] = (char)(ret
);
165 TextBuffer
[10] = 'L';
166 TextBuffer
[11] = 'L';
170 hdc
= GetDC (g_hwnd
);
171 SelectObject (hdc
, GetStockObject (SYSTEM_FIXED_FONT
));
173 TextOut (hdc
,ResultX
,ResultY
,TextBuffer
,8+s
);
174 ReleaseDC (g_hwnd
, hdc
);
175 ValidateRect (g_hwnd
, &rect
);
181 char* Text
; /* Text for the button */
182 DWORD MsgCode
; /* Message Code */
183 WPARAM wParam
; /* Well hope you can understand this */
184 LPARAM lParam
; /* ditto */
185 LPFUNCTIONHANDLER Handler
; /* Funtion called to handle the result of each message */
189 {"EM_CANUNDO",EM_CANUNDO
,0,0,&HandlePrintReturnHex
},
190 {"EM_CHARFROMPOS",EM_CHARFROMPOS
,(WPARAM
)&point
,0,&HandlePrintReturnHex
},
191 {"EM_EMPTYUNDOBUFFER",EM_EMPTYUNDOBUFFER
,0,0,&HandlePrintReturnHex
},
192 {"EM_FMTLINES",EM_FMTLINES
,TRUE
,0,&HandlePrintReturnHex
},
193 {"EM_GETFIRSTVISIBLELINE",EM_GETFIRSTVISIBLELINE
,0,0,&HandlePrintReturnHex
},
195 {"EM_GETLIMITTEXT",EM_GETLIMITTEXT
,0,0,&HandlePrintReturnHex
},
196 {"EM_GETLINE",EM_GETLINE
,2,(WPARAM
)&TextBuffer
[8],&HandlePrintReturnStr
},
197 {"EM_GETLINECOUNT",EM_GETLINECOUNT
,0,0,&HandlePrintReturnHex
},
198 {"EM_GETMARGINS",EM_GETMARGINS
,0,0,&HandlePrintReturnHex
},
199 {"EM_SETMARGINS",EM_SETMARGINS
,EC_LEFTMARGIN
,10,&HandlePrintReturnHex
},
201 {"EM_GETMODIFY",EM_GETMODIFY
,0,0,&HandlePrintReturnHex
},
202 {"EM_SETMODIFY",EM_SETMODIFY
,TRUE
,0,&HandlePrintReturnHex
},
204 {"EM_GETSEL",EM_GETSEL
,(WPARAM
)&StartP
,(LPARAM
)&EndP
,&HandlePrintReturnHex
},
206 {"EM_GETTHUMB",EM_GETTHUMB
,0,0,&HandlePrintReturnHex
},
208 {"EM_LIMITTEXT",EM_LIMITTEXT
,10,0,&HandlePrintReturnHex
},
209 {"EM_LINEFROMCHAR",EM_LINEFROMCHAR
,-1,0,&HandlePrintReturnHex
},
210 {"EM_POSFROMCHAR",EM_POSFROMCHAR
,10,0,&HandlePrintReturnHex
},
211 {"EM_LINEINDEX",EM_LINEINDEX
,2,0,&HandlePrintReturnHex
},
212 {"EM_LINELENGTH",EM_LINELENGTH
,-1,0,&HandlePrintReturnHex
},
214 {"EM_GETWORDBREAKPROC",EM_GETWORDBREAKPROC
,0,0,&HandlePrintReturnHex
},
215 {"EM_REPLACESEL",EM_REPLACESEL
,TRUE
,(LPARAM
)&ReplaceTextStr
,&HandlePrintReturnHex
},
217 {"EM_LINESCROLL",EM_LINESCROLL
,5,1,&HandlePrintReturnHex
},
218 {"EM_SCROLL",EM_SCROLL
,SB_LINEDOWN
,0,&HandlePrintReturnHex
},
219 {"EM_SCROLLCARET",EM_SCROLLCARET
,0,0,&HandlePrintReturnHex
},
221 {"EM_SETHANDLE",EM_SETHANDLE
,0,0,&HandleSetHandlePrintHex
},
222 {"EM_GETHANDLE",EM_GETHANDLE
,0,0,&HandlePrintReturnHex
},
223 {"EM_GETPASSWORDCHAR",EM_GETPASSWORDCHAR
,0,0,&HandlePrintPasswdChar
},
224 {"EM_SETPASSWORDCHAR - clear",EM_SETPASSWORDCHAR
,0,0,&HandlePrintReturnHex
},
225 {"EM_SETPASSWORDCHAR - x",EM_SETPASSWORDCHAR
,'x',0,&HandlePrintReturnHex
},
227 {"EM_SETREADONLY - set",EM_SETREADONLY
,TRUE
,0,&HandlePrintReturnHex
},
228 {"EM_SETREADONLY - clear",EM_SETREADONLY
,FALSE
,0,&HandlePrintReturnHex
},
230 {"EM_GETRECT",EM_GETRECT
,0,(LPARAM
)&rect2
,&HandlePrintRect
},
231 {"EM_SETRECT",EM_SETRECT
,0,(LPARAM
)&rect
,&HandlePrintReturnHex
},
232 {"EM_SETRECTNP",EM_SETRECTNP
,0,(LPARAM
)&rect
,&HandlePrintReturnHex
},
233 {"EM_SETSEL",EM_SETSEL
,1,3,&HandlePrintReturnHex
},
235 {"EM_SETSEL - all",EM_SETSEL
,0,-1,&HandlePrintReturnHex
},
236 {"EM_SETSEL - remove",EM_SETSEL
,-1,0,&HandlePrintReturnHex
},
237 {"EM_UNDO",EM_UNDO
,0,0,&HandlePrintReturnHex
},
238 {"WM_UNDO",WM_UNDO
,0,0,&HandlePrintReturnHex
},
239 {"WM_PASTE",WM_PASTE
,0,0,&HandlePrintReturnHex
},
241 {"WM_CUT",WM_CUT
,0,0,&HandlePrintReturnHex
},
242 {"WM_COPY",WM_COPY
,0,0,&HandlePrintReturnHex
}
246 DWORD EditStyles
[] = {
247 WS_THICKFRAME
,WS_DISABLED
,WS_BORDER
,ES_LOWERCASE
,ES_UPPERCASE
,ES_NUMBER
,ES_AUTOVSCROLL
,
248 ES_AUTOHSCROLL
,ES_LEFT
,ES_CENTER
,ES_RIGHT
,ES_MULTILINE
,
249 ES_NOHIDESEL
,ES_OEMCONVERT
,ES_PASSWORD
,ES_READONLY
,ES_WANTRETURN
,
250 WS_HSCROLL
,WS_VSCROLL
253 char* StyleNames
[] = {
254 "WS_THICKFRAME","WS_DISABLED","WS_BORDER","ES_LOWERCASE","ES_UPPERCASE","ES_NUMBER","ES_AUTOVSCROLL",
255 "ES_AUTOHSCROLL","ES_LEFT","ES_CENTER","ES_RIGHT","ES_MULTILINE",
256 "ES_NOHIDESEL","ES_OEMCONVERT","ES_PASSWORD","ES_READONLY","ES_WANTRETURN",
257 "WS_HSCROLL","WS_VSCROLL"
260 #define NUMBERBUTTONS 26
261 HWND Buttons
[NUMBERBUTTONS
];
262 HWND MessageButtons
[MAXMESSAGEBUTTONS
];
263 HWND Back1But
,Back2But
;
268 CreateCheckButton(const char* lpWindowName
, DWORD xSize
, DWORD id
)
271 h
= CreateWindowEx(0,
274 WS_CHILD
| WS_VISIBLE
| BS_AUTOCHECKBOX
,
289 CreatePushButton(const char* lpWindowName
, DWORD xSize
, DWORD id
,DWORD Style
)
292 HWND h
= CreateWindow("BUTTON",
294 WS_CHILD
| BS_PUSHBUTTON
| Style
,
314 for (i
=0 ; i
< 19 ; i
++)
316 if(BST_CHECKED
== SendMessage(Buttons
[i
],BM_GETCHECK
,0,0))
317 EditStyle
|= EditStyles
[i
];
318 ShowWindow(Buttons
[i
],SW_HIDE
);
321 for (; i
< NUMBERBUTTONS
; i
++)ShowWindow(Buttons
[i
],SW_HIDE
);
322 for (i
=0 ; i
< 26 ; i
++) ShowWindow(MessageButtons
[i
],SW_SHOW
);
324 ShowWindow(Back1But
,SW_SHOW
);
325 ShowWindow(NextBut
,SW_SHOW
);
329 ForwardToSecondPage()
332 for (i
=0;i
<26;i
++)ShowWindow(MessageButtons
[i
],SW_HIDE
);
333 for(;i
<MAXMESSAGEBUTTONS
;i
++)ShowWindow(MessageButtons
[i
],SW_SHOW
);
334 ShowWindow(Back2But
,SW_SHOW
);
336 ShowWindow(Back1But
,SW_HIDE
);
337 ShowWindow(NextBut
,SW_HIDE
);
344 for (i
=0;i
<26;i
++)ShowWindow(MessageButtons
[i
],SW_SHOW
);
345 for(;i
<MAXMESSAGEBUTTONS
;i
++)ShowWindow(MessageButtons
[i
],SW_HIDE
);
346 ShowWindow(Back2But
,SW_HIDE
);
347 ShowWindow(Back1But
,SW_SHOW
);
348 ShowWindow(NextBut
,SW_SHOW
);
355 DestroyWindow(hwndEdit
);
356 for (i
=0 ; i
< NUMBERBUTTONS
; i
++) {ShowWindow(Buttons
[i
],SW_SHOW
);}
357 for (i
=0;i
<26;i
++)ShowWindow(MessageButtons
[i
],SW_HIDE
);
358 ShowWindow(Back1But
,SW_HIDE
);
359 ShowWindow(NextBut
,SW_HIDE
);
364 WndProc ( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
372 /* ---- Initial page ---- */
374 for (i
= 0 ; i
< 14 ; i
++)
375 Buttons
[i
] = CreateCheckButton(StyleNames
[i
],150,500+i
);
381 Buttons
[i
] = CreateCheckButton(StyleNames
[i
],140,500+i
);
383 Buttons
[i
++] = CreatePushButton("Width +",70,100,WS_VISIBLE
);
384 Buttons
[i
++] = CreatePushButton("Width -",70,101,WS_VISIBLE
);
386 Buttons
[i
++] = CreatePushButton("Heigth +",70,102,WS_VISIBLE
);
387 Buttons
[i
++] = CreatePushButton("Heigth -",70,103,WS_VISIBLE
);
389 Buttons
[i
++] = CreatePushButton("CreateWindowA",140,CREATEWINDOW
,WS_VISIBLE
);
390 Buttons
[i
++] = CreatePushButton("CreateWindowExA",140,CREATEWINDOWEX
,WS_VISIBLE
);
391 Buttons
[i
++] = CreatePushButton("CreateWindowExW",140,CREATEWINDOWW
,WS_VISIBLE
);
394 /* ---- The 1st page of buttons ---- */
399 for (i
= 0 ; i
< 14 ; i
++)
400 MessageButtons
[i
] = CreatePushButton(Msg
[i
].Text
,170,600+i
,0);
406 MessageButtons
[i
] = CreatePushButton(Msg
[i
].Text
,170,600+i
,0);
408 Back1But
= CreatePushButton("Back - destroys edit",170,400,0);
409 NextBut
= CreatePushButton("Next",170,401,0);
411 /* ---- The 2nd page of buttons ------*/
417 MessageButtons
[i
] = CreatePushButton(Msg
[i
].Text
,170,600+i
,0);
422 for (; i
< MAXMESSAGEBUTTONS
; i
++)
423 MessageButtons
[i
] = CreatePushButton(Msg
[i
].Text
,170,600+i
,0);
425 Back2But
= CreatePushButton("Back",170,402,0);
430 if (LOWORD(wParam
) >= 600)
432 Msg
[LOWORD(wParam
)-600].Handler(hwndEdit
,
433 Msg
[LOWORD(wParam
)-600].MsgCode
,
434 Msg
[LOWORD(wParam
)-600].wParam
,
435 Msg
[LOWORD(wParam
)-600].lParam
);
439 switch(LOWORD(wParam
)){
462 ForwardToSecondPage();
472 hwndEdit
= CreateWindow("EDIT",
474 EditStyle
| WS_CHILD
| WS_VISIBLE
,
488 hwndEdit
= CreateWindowEx(WS_EX_CLIENTEDGE
,
491 EditStyle
| WS_CHILD
| WS_VISIBLE
,
505 hwndEdit
= CreateWindowExW(WS_EX_CLIENTEDGE
,
508 EditStyle
| WS_CHILD
| WS_VISIBLE
,
520 if (lParam
== (LPARAM
)hwndEdit
)
521 switch(HIWORD(wParam
))
524 PrintTextXY("EN_CHANGE notification",NOTIFYX
,NOTIFYY
,22);
528 PrintTextXY("EN_ERRSPACE notification",NOTIFYX
,NOTIFYY
,24);
531 /* --- FIXME not defined in w32api-2.3 headers
533 PrintTextXY("H_SCROLL notification",NOTIFYX,NOTIFYY,21);
536 /* --- FIXME not defined in w32api-2.3 headers
538 PrintTextXY("KILL_FOCUS notification",NOTIFYX,NOTIFYY,23);
541 /* --- FIXME not defined in w32api-2.3 headers
543 PrintTextXY("EN_MAXTEXT notification",NOTIFYX,NOTIFYY,23);
547 PrintTextXY("EN_SETFOCUS notification",NOTIFYX
,NOTIFYY
,24);
551 PrintTextXY("EN_UPDATE notification",NOTIFYX
,NOTIFYY
+ 20,22);
555 PrintTextXY("EN_VSCROLL notification",NOTIFYX
,NOTIFYY
,23);
566 DestroyWindow (g_hwnd
);
569 case WM_QUERYENDSESSION
:
576 return DefWindowProc ( hwnd
, msg
, wParam
, lParam
);
580 RegisterAndCreateWindow (HINSTANCE hInst
,
581 const char* className
,
589 wc
.cbSize
= sizeof (WNDCLASSEX
);
591 wc
.lpfnWndProc
= WndProc
; /* window procedure */
592 wc
.hInstance
= hInst
; /* owner of the class */
594 wc
.lpszClassName
= className
;
595 wc
.hCursor
= LoadCursor ( 0, (LPCTSTR
)IDC_ARROW
);
596 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
597 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
604 if ( !RegisterClassEx ( &wc
) )
607 hwnd
= CreateWindowEx (
609 className
, /* class name */
610 title
, /* window title */
612 WS_OVERLAPPEDWINDOW
, /* dwStyle */
618 NULL
, /* hwndParent */
624 if (!hwnd
) return NULL
;
626 ShowWindow (hwnd
, SW_SHOW
);
634 WinMain ( HINSTANCE hInst
, HINSTANCE hPrevInst
, LPSTR cmdParam
, int cmdShow
)
636 char className
[] = "Edit Control Test";
639 RegisterAndCreateWindow ( hInst
, className
, "Edit Control Styles Test" );
642 while (GetMessage (&msg
, NULL
, 0, 0))
644 TranslateMessage (&msg
);
645 DispatchMessage (&msg
);