1 /* ComboBox Control Test for ReactOS.
3 * This is a test program. Not made to be fast, small
4 * easy to mantain, or portable.
6 * I'm not erasing text because I don't want to use other functions from the API
7 * or make this more complex. Also Fonts are not heavily used.
9 * This source code is in the PUBLIC DOMAIN and has NO WARRANTY.
10 * by Waldo Alvarez CaƱizares <wac at ghost.matcom.uh.cu>, started July 11, 2003. */
12 //#define WIN32_LEAN_AND_MEAN
16 #define CONTROLCLASS "COMBOBOX" /* the class name */
17 #define CONTROLCLASSW L"COMBOBOX" /* the class name in unicode*/
19 #define WINDOWWIDTH 560
20 #define WINDOWHEIGHT 350
22 /* --- Command IDs of some buttons --- */
23 #define CREATEWINDOW_ID 106
24 #define CREATEWINDOWEX_ID 107
25 #define CREATEWINDOWW_ID 108
26 #define INITPAGE_ID 400
27 #define SECONDPAGE_ID 401
28 #define BACKFIRSTPAGE_ID 402
30 /* --- Position where the result text goes --- */
34 /* --- Position where the notify text goes --- */
38 /* --- The width of most buttons --- */
39 #define CHECKBUTWIDTH 190
40 #define SCROLLAMOUNT -15
42 /* Size of buffer to hold resulting strings from conversion
43 and returned by messages */
45 char TextBuffer[BUFFERLEN]={'R','e','s','u','l','t',':',' '};
48 HINSTANCE g_hInst = NULL;
57 /* --- Control coordinates --- */
58 #define CONTROLPOSX 390
59 #define CONTROLPOSY 10
60 DWORD ControlWidth = 160;
61 DWORD ControlHeight = 150;
63 static RECT srect = {CONTROLPOSX,CONTROLPOSY,WINDOWWIDTH,WINDOWHEIGHT};
69 HWND hwnd; /* main window handle */
71 char AddString[] = "string added";
73 typedef void FunctionHandler(HWND,DWORD,WPARAM,LPARAM);
74 typedef FunctionHandler* LPFUNCTIONHANDLER;
76 PrintTextXY(char* Text,int x,int y,int len, RECT rect)
80 SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
82 TextOut (hdc, x,y,Text,len);
83 ReleaseDC (g_hwnd, hdc);
85 ValidateRect (g_hwnd, &rect);
90 HandlePrintReturnHex(HWND handle,DWORD Msg,WPARAM wParam,LPARAM lParam)
94 ret = SendMessage(handle,Msg,wParam,lParam);
95 htoa((unsigned int)ret,&TextBuffer[8]);
96 GetWindowRect(g_hwnd,&rect);
97 PrintTextXY(TextBuffer,ResultX,ResultY,16,rect);
103 HandlePrintReturnStr(HWND handle,DWORD Msg,WPARAM wParam,LPARAM lParam)
108 TextBuffer[8] = (char)(BUFFERLEN - 8); /* Setting the max size to put chars in first byte */
109 ret = SendMessage(handle,Msg,wParam,lParam);
110 GetWindowRect(g_hwnd,&rect);
111 PrintTextXY(TextBuffer,ResultX,ResultY,8+(int)ret,rect);
116 HandlePrintRect(HWND handle,DWORD Msg,WPARAM wParam,LPARAM lParam)
119 TextBuffer[8] = (char)(BUFFERLEN - 8); /* Setting the max size to put chars in first byte */
120 SendMessage(handle,Msg,wParam,lParam);
122 htoa(rect.top,&TextBuffer[8]);
123 TextBuffer[8+8] = ' ';
124 htoa(rect.bottom,&TextBuffer[8+8+1]);
125 TextBuffer[8+8+8+1] = ' ';
126 htoa(rect.left,&TextBuffer[8+8+8+1+1]);
127 TextBuffer[8+8+8+8+1+1] = ' ';
128 htoa(rect.right,&TextBuffer[8+8+8+8+1+1+1]);
130 GetWindowRect(g_hwnd,&rect);
131 PrintTextXY(TextBuffer,ResultX,ResultY,8+4*9-1,rect);
136 char* Text; /* Text for the button */
137 DWORD MsgCode; /* Message Code */
138 WPARAM wParam; /* Well hope you can understand this */
139 LPARAM lParam; /* ditto */
140 LPFUNCTIONHANDLER Handler; /* Funtion called to handle the result of each message */
144 "CB_ADDSTRING",CB_ADDSTRING,0,(LPARAM)&AddString,&HandlePrintReturnHex,
145 "CB_ADDSTRING - long",CB_ADDSTRING,0,(LPARAM)"very loooooooooong striiinnnnnnnnnggg",&HandlePrintReturnHex,
146 "CB_DELETESTRING",CB_DELETESTRING,2,0,&HandlePrintReturnHex, /* remember to catch WM_DELETEITEM*/
148 /* What a message, why M$ decided to implement his thing ? */
149 "CB_DIR - drives",CB_DIR,DDL_DRIVES,
150 /* Hoping that most machines have this */
152 &HandlePrintReturnHex,
154 "CB_DIR - dirs",CB_DIR,DDL_DIRECTORY,(LPARAM)"C:\\*",&HandlePrintReturnHex,
156 "CB_DIR - files",CB_DIR,
157 DDL_ARCHIVE | DDL_EXCLUSIVE | DDL_HIDDEN | DDL_READONLY | DDL_READWRITE | DDL_SYSTEM,
158 (LPARAM)"C:\\*",&HandlePrintReturnHex,
160 /* Do not forget WM_COMPAREITEM */
162 "CB_FINDSTRING",CB_FINDSTRING,1,(LPARAM)"str",&HandlePrintReturnHex,
163 "CB_FINDSTRINGEXACT(-1)",CB_FINDSTRINGEXACT,-1,(LPARAM)&AddString,&HandlePrintReturnHex,
164 "CB_FINDSTRINGEXACT(2)",CB_FINDSTRINGEXACT,2,(LPARAM)&AddString,&HandlePrintReturnHex,
166 /* "CB_GETCOMBOBOXINFO",CB_GETCOMBOBOXINFO,0,0,&HandlePrintReturnHex, winXP & .net server remember to handle the struct */
168 "CB_GETCOUNT",CB_GETCOUNT,0,0,&HandlePrintReturnHex,
170 "CB_GETCURSEL",CB_GETCURSEL,0,0,&HandlePrintReturnHex,
172 /* To implement "CB_GETEDITSEL - vars",CB_GETEDITSEL,,,&HandlePrintReturnHex, */
174 "CB_GETEXTENDEDUI",CB_GETEXTENDEDUI,0,0,&HandlePrintReturnHex,
175 "CB_GETHORIZONTALEXTENT",CB_GETHORIZONTALEXTENT,0,0,&HandlePrintReturnHex,
179 "CB_GETLBTEXT",CB_GETLBTEXT,1,(LPARAM)&TextBuffer[8],&HandlePrintReturnStr,
180 "CB_GETLBTEXTLEN",CB_GETLBTEXTLEN,1,0,&HandlePrintReturnHex,
181 "CB_GETLOCALE",CB_GETLOCALE,0,0,&HandlePrintReturnHex,
183 /* "CB_GETMINVISIBLE",CB_GETMINVISIBLE,0,0,&HandlePrintReturnHex, Included in Windows XP and Windows .NET Server. */
185 "CB_GETTOPINDEX",CB_GETTOPINDEX,0,0,&HandlePrintReturnHex,
187 "CB_INITSTORAGE",CB_INITSTORAGE,10,200,&HandlePrintReturnHex,
188 "CB_INSERTSTRING",CB_INSERTSTRING,2,(LPARAM)"inserted string",&HandlePrintReturnHex,
190 "CB_LIMITTEXT",CB_LIMITTEXT,10,0,&HandlePrintReturnHex,
191 "CB_RESETCONTENT",CB_RESETCONTENT ,0,0,&HandlePrintReturnHex,
192 "CB_SELECTSTRING",CB_SELECTSTRING,2,(LPARAM)"str",&HandlePrintReturnHex,
193 "CB_SETCURSEL",CB_SETCURSEL,1,0,&HandlePrintReturnHex,
195 "CB_SETDROPPEDWIDTH",CB_SETDROPPEDWIDTH,250,0,&HandlePrintReturnHex,
197 "CB_SETEXTENDEDUI - set",CB_SETEXTENDEDUI,TRUE,0,&HandlePrintReturnHex,
198 "CB_SETEXTENDEDUI - clear",CB_SETEXTENDEDUI,FALSE,0,&HandlePrintReturnHex,
201 * win2k have a small bug with this ^ , if you press F4 while it is cleared,
202 * the combobox is using style cbs_dropdown
203 * and the pointer is over the edit box then the mouse pointer is not changed
207 "CB_SETHORIZONTALEXTENT",CB_SETHORIZONTALEXTENT,500,0,&HandlePrintReturnHex,
209 "CB_GETITEMDATA",CB_GETITEMDATA,1,0,&HandlePrintReturnHex,
210 "CB_SETITEMDATA",CB_SETITEMDATA,1,0x791031,&HandlePrintReturnHex,
212 "CB_SETITEMHEIGHT",CB_SETITEMHEIGHT,-1,30,&HandlePrintReturnHex,
213 "CB_GETITEMHEIGHT",CB_GETITEMHEIGHT,2,0,&HandlePrintReturnHex,
215 /* "CB_SETMINVISIBLE",CB_SETMINVISIBLE,4,0,&HandlePrintReturnHex, Included in Windows XP and Windows .NET Server */
217 "CB_GETEDITSEL",CB_GETEDITSEL,(WPARAM)NULL,(LPARAM)NULL,&HandlePrintReturnHex,
218 "CB_SETEDITSEL",CB_SETEDITSEL,0,0x00020005,&HandlePrintReturnHex,
219 "CB_SETEDITSEL - clear",CB_SETEDITSEL,0,0xFFFFFFFF,&HandlePrintReturnHex,
221 "CB_SETTOPINDEX",CB_SETTOPINDEX,3,0,&HandlePrintReturnHex,
223 "CB_SHOWDROPDOWN - true",CB_SHOWDROPDOWN,TRUE,0,&HandlePrintReturnHex,
224 "CB_SHOWDROPDOWN - false",CB_SHOWDROPDOWN,FALSE,0,&HandlePrintReturnHex,
226 "CB_GETDROPPEDCONTROLRECT",CB_GETDROPPEDCONTROLRECT,0,(LPARAM)&rect,&HandlePrintRect,
227 "CB_GETDROPPEDSTATE",CB_GETDROPPEDSTATE,0,0,&HandlePrintReturnHex,
228 "CB_GETDROPPEDWIDTH",CB_GETDROPPEDWIDTH,0,0,&HandlePrintReturnHex,
230 "WM_PASTE",WM_PASTE,0,0,&HandlePrintReturnHex,
233 #define MAXMESSAGEBUTTONS 40
237 char* Name; /* Text for the button */
238 DWORD Code; /* Style Code */
241 "WS_DISABLED",WS_DISABLED,
242 "CBS_AUTOHSCROLL",CBS_AUTOHSCROLL,
243 "CBS_DISABLENOSCROLL",CBS_DISABLENOSCROLL,
244 "CBS_DROPDOWN",CBS_DROPDOWN,
245 "CBS_DROPDOWNLIST",CBS_DROPDOWNLIST,
246 "CBS_HASSTRINGS",CBS_HASSTRINGS,
247 "CBS_LOWERCASE",CBS_LOWERCASE,
248 "CBS_NOINTEGRALHEIGHT",CBS_NOINTEGRALHEIGHT,
249 "CBS_OEMCONVERT",CBS_OEMCONVERT,
250 "CBS_OWNERDRAWFIXED",CBS_OWNERDRAWFIXED,
251 "CBS_OWNERDRAWVARIABLE",CBS_OWNERDRAWVARIABLE,
252 "CBS_SIMPLE",CBS_SIMPLE,
254 "CBS_UPPERCASE",CBS_UPPERCASE,
255 "CBS_DISABLENOSCROLL",CBS_DISABLENOSCROLL,
256 "WS_HSCROLL",WS_HSCROLL,
257 "WS_VSCROLL",WS_VSCROLL
260 /* The number of check buttons we have.
261 * Maybe some calculations at compile time would be better
264 #define NUMBERCHECKS 17
266 #define NUMBERBUTTONS NUMBERCHECKS + 7
267 HWND Buttons[NUMBERBUTTONS];
268 HWND MessageButtons[MAXMESSAGEBUTTONS];
269 HWND Back1But,Back2But;
273 CreateCheckButton(const char* lpWindowName, DWORD xSize, DWORD id)
276 h = CreateWindowEx(0,
279 WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
294 CreatePushButton(const char* lpWindowName, DWORD xSize, DWORD id,DWORD Style)
297 HWND h = CreateWindow("BUTTON",
299 WS_CHILD | BS_PUSHBUTTON | Style,
319 for (i=0 ; i< NUMBERCHECKS ; i++)
321 if(BST_CHECKED == SendMessage(Buttons[i],BM_GETCHECK,0,0))
322 ComboStyle |= Styles[i].Code;
323 ShowWindow(Buttons[i],SW_HIDE);
326 for (; i< NUMBERBUTTONS ; i++)ShowWindow(Buttons[i],SW_HIDE);
327 for (i=0 ; i< 26 ; i++) ShowWindow(MessageButtons[i],SW_SHOW);
329 ShowWindow(Back1But,SW_SHOW);
330 ShowWindow(NextBut,SW_SHOW);
334 ForwardToSecondPage()
337 for (i=0;i<26;i++)ShowWindow(MessageButtons[i],SW_HIDE);
338 for(;i<MAXMESSAGEBUTTONS;i++)ShowWindow(MessageButtons[i],SW_SHOW);
339 ShowWindow(Back2But,SW_SHOW);
341 ShowWindow(Back1But,SW_HIDE);
342 ShowWindow(NextBut,SW_HIDE);
349 for (i=0;i<26;i++)ShowWindow(MessageButtons[i],SW_SHOW);
350 for(;i<MAXMESSAGEBUTTONS;i++)ShowWindow(MessageButtons[i],SW_HIDE);
351 ShowWindow(Back2But,SW_HIDE);
352 ShowWindow(Back1But,SW_SHOW);
353 ShowWindow(NextBut,SW_SHOW);
360 DestroyWindow(hwndEdit);
361 for (i=0 ; i< NUMBERBUTTONS ; i++) {ShowWindow(Buttons[i],SW_SHOW);}
362 for (i=0;i<26;i++)ShowWindow(MessageButtons[i],SW_HIDE);
363 ShowWindow(Back1But,SW_HIDE);
364 ShowWindow(NextBut,SW_HIDE);
369 WndProc ( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
377 /* ---- Initial page ---- */
379 for (i = 0 ; i < 14 ; i++)
380 Buttons[i] = CreateCheckButton(Styles[i].Name,CHECKBUTWIDTH,500+i);
382 xButPos += CHECKBUTWIDTH + 10;
385 for (; i < NUMBERCHECKS ; i++)
386 Buttons[i] = CreateCheckButton(Styles[i].Name,CHECKBUTWIDTH,500+i);
388 Buttons[i++] = CreatePushButton("Width +",70,100,WS_VISIBLE);
389 Buttons[i++] = CreatePushButton("Width -",70,101,WS_VISIBLE);
391 Buttons[i++] = CreatePushButton("Heigth +",70,102,WS_VISIBLE);
392 Buttons[i++] = CreatePushButton("Heigth -",70,103,WS_VISIBLE);
394 Buttons[i++] = CreatePushButton("CreateWindowA",CHECKBUTWIDTH,CREATEWINDOW_ID,WS_VISIBLE);
395 Buttons[i++] = CreatePushButton("CreateWindowExA",CHECKBUTWIDTH,CREATEWINDOWEX_ID,WS_VISIBLE);
396 Buttons[i++] = CreatePushButton("CreateWindowExW",CHECKBUTWIDTH,CREATEWINDOWW_ID,WS_VISIBLE);
399 /* ---- The 1st page of buttons ---- */
404 for (i = 0 ; i < 14 ; i++)
405 MessageButtons[i] = CreatePushButton(Msg[i].Text,CHECKBUTWIDTH,600+i,0);
407 xButPos += CHECKBUTWIDTH + 10;
411 MessageButtons[i] = CreatePushButton(Msg[i].Text,CHECKBUTWIDTH,600+i,0);
413 Back1But = CreatePushButton("Back - destroys ComboBox",CHECKBUTWIDTH,INITPAGE_ID,0);
414 NextBut = CreatePushButton("Next",CHECKBUTWIDTH,SECONDPAGE_ID,0);
416 /* ---- The 2nd page of buttons ------*/
422 MessageButtons[i] = CreatePushButton(Msg[i].Text,CHECKBUTWIDTH,600+i,0);
424 xButPos += CHECKBUTWIDTH + 10;
427 for (; i < MAXMESSAGEBUTTONS ; i++)
428 MessageButtons[i] = CreatePushButton(Msg[i].Text,CHECKBUTWIDTH,600+i,0);
430 Back2But = CreatePushButton("Back",CHECKBUTWIDTH,BACKFIRSTPAGE_ID,0);
435 if (LOWORD(wParam) >= 600)
437 Msg[LOWORD(wParam)-600].Handler(hwndEdit,
438 Msg[LOWORD(wParam)-600].MsgCode,
439 Msg[LOWORD(wParam)-600].wParam,
440 Msg[LOWORD(wParam)-600].lParam);
444 switch(LOWORD(wParam)){
467 ForwardToSecondPage();
470 case BACKFIRSTPAGE_ID:
474 case CREATEWINDOW_ID:
476 srect.top = CONTROLPOSY + ControlHeight;
477 hwndEdit = CreateWindow(CONTROLCLASS,
479 ComboStyle | WS_CHILD | WS_VISIBLE,
490 case CREATEWINDOWEX_ID:
492 srect.top = CONTROLPOSY + ControlHeight;
493 hwndEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
496 ComboStyle | WS_CHILD | WS_VISIBLE ,
507 case CREATEWINDOWW_ID:
509 srect.top = CONTROLPOSY + ControlHeight;
510 hwndEdit = CreateWindowExW(WS_EX_CLIENTEDGE,
513 ComboStyle | WS_CHILD | WS_VISIBLE ,
525 if (lParam == (LPARAM)hwndEdit)
526 switch(HIWORD(wParam))
529 ScrollWindow (hwnd, 0, SCROLLAMOUNT, &srect, &srect);
530 PrintTextXY("CBN_DROPDOWN notification",NOTIFYX,NOTIFYY,25,srect);
534 ScrollWindow (hwnd, 0, SCROLLAMOUNT, &srect, &srect);
535 PrintTextXY("CBN_CLOSEUP notification",NOTIFYX,NOTIFYY,24,srect);
539 ScrollWindow (hwnd, 0, SCROLLAMOUNT, &srect, &srect);
540 PrintTextXY("CBN_DBLCLK notification",NOTIFYX,NOTIFYY,23,srect);
544 ScrollWindow (hwnd, 0, SCROLLAMOUNT, &srect, &srect);
545 PrintTextXY("CBN_EDITCHANGE notification",NOTIFYX,NOTIFYY,27,srect);
549 ScrollWindow (hwnd, 0, SCROLLAMOUNT, &srect, &srect);
550 PrintTextXY("CBN_ERRSPACE notification",NOTIFYX,NOTIFYY,25,srect);
554 ScrollWindow (hwnd, 0, SCROLLAMOUNT, &srect, &srect);
555 PrintTextXY("CBN_KILLFOCUS notification",NOTIFYX,NOTIFYY,26,srect);
559 ScrollWindow (hwnd, 0, SCROLLAMOUNT, &srect, &srect);
560 PrintTextXY("CBN_EDITUPDATE notification",NOTIFYX,NOTIFYY,27,srect);
564 ScrollWindow (hwnd, 0, SCROLLAMOUNT, &srect, &srect);
565 PrintTextXY("CBN_SELCHANGE notification",NOTIFYX,NOTIFYY,26,srect);
568 case CBN_SELENDCANCEL:
569 ScrollWindow (hwnd, 0, SCROLLAMOUNT, &srect, &srect);
570 PrintTextXY("CBN_SELENDCANCEL notification",NOTIFYX,NOTIFYY,29,srect);
574 ScrollWindow (hwnd, 0, SCROLLAMOUNT, &srect, &srect);
575 PrintTextXY("CBN_SETFOCUS notification",NOTIFYX,NOTIFYY,25,srect);
579 ScrollWindow (hwnd, 0, SCROLLAMOUNT, &srect, &srect);
580 PrintTextXY("CBN_SELENDOK notification",NOTIFYX,NOTIFYY,25,srect);
584 return DefWindowProc ( hwnd, msg, wParam, lParam );
587 ScrollWindow (hwnd, 0, SCROLLAMOUNT, &srect, &srect);
588 PrintTextXY("WM_MEASUREITEM called",NOTIFYX,NOTIFYY,21,srect);
592 ScrollWindow (hwnd, 0, SCROLLAMOUNT, &srect, &srect);
593 PrintTextXY("WM_COMPAREITEM called",NOTIFYX,NOTIFYY,21,srect);
597 ScrollWindow (hwnd, 0, SCROLLAMOUNT, &srect, &srect);
598 PrintTextXY("WM_DRAWITEM called",NOTIFYX,NOTIFYY,18,srect);
605 DestroyWindow (g_hwnd);
608 case WM_QUERYENDSESSION:
615 return DefWindowProc ( hwnd, msg, wParam, lParam );
620 RegisterAndCreateWindow (HINSTANCE hInst,
621 const char* className,
629 wc.cbSize = sizeof (WNDCLASSEX);
631 wc.lpfnWndProc = WndProc; /* window procedure */
632 wc.hInstance = hInst; /* owner of the class */
634 wc.lpszClassName = className;
635 wc.hCursor = LoadCursor ( 0, IDC_ARROW );
636 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
637 wc.style = CS_HREDRAW | CS_VREDRAW;
644 if ( !RegisterClassEx ( &wc ) )
647 hwnd = CreateWindowEx (
649 className, /* class name */
650 title, /* window title */
652 WS_OVERLAPPEDWINDOW, /* dwStyle */
656 WINDOWWIDTH, /* width */
657 WINDOWHEIGHT, /* height */
658 NULL, /* hwndParent */
664 if (!hwnd) return NULL;
666 ShowWindow (hwnd, SW_SHOW);
674 WinMain ( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmdParam, int cmdShow )
676 char className [] = "ComboBox Control Test";
679 RegisterAndCreateWindow ( hInst, className, "ComboBox Control Test" );
681 while (GetMessage (&msg, NULL, 0, 0))
683 TranslateMessage (&msg);
684 DispatchMessage (&msg);
686 return (int)msg.wParam;