Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cWndControls.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cWndControls_H
7 #define _INC_cWndControls_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cWindow.h"
13 
14 #ifdef _WIN32
15 namespace GrayLib
16 {
17  class GRAYLIB_LINK cWndStatic : public cWndHandle
18  {
21  public:
22  cWndStatic(HWND hWnd = WINHANDLE_NULL) : cWndHandle(hWnd)
23  {}
24  cWndStatic(cWndHandle* pWndParent, DLGID_t id) : cWndHandle(pWndParent, id)
25  {}
26  virtual ~cWndStatic()
27  {
28  }
29 
30  // Operations
31 
32 #ifndef UNDER_CE
33  HICON SetIcon(HICON hIcon)
34  {
35  ASSERT(IsWindow());
36  return (HICON)(UINT_PTR)SendMessageX(STM_SETICON, (WPARAM)hIcon);
37  }
38  HICON GetIcon() const
39  {
40  ASSERT(IsWindow());
41  return (HICON)(UINT_PTR)SendMessageX(STM_GETICON);
42  }
43 
44  HENHMETAFILE SetEnhMetaFile(HENHMETAFILE hMetaFile)
45  {
46  ASSERT(IsWindow());
47  return (HENHMETAFILE)(UINT_PTR)SendMessageX(STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)hMetaFile);
48  }
49  HENHMETAFILE GetEnhMetaFileX() const
50  {
51  ASSERT(IsWindow());
52  return (HENHMETAFILE)(UINT_PTR)SendMessageX(STM_GETIMAGE, IMAGE_ENHMETAFILE);
53  }
54 #endif
55 
56  HBITMAP SetBitmap(HBITMAP hBitmap)
57  {
58  ASSERT(IsWindow());
59  return (HBITMAP)(UINT_PTR)SendMessageX(STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
60  }
61  HBITMAP GetBitmap() const
62  {
63  ASSERT(IsWindow());
64  return (HBITMAP)(UINT_PTR)SendMessageX(STM_GETIMAGE, IMAGE_BITMAP);
65  }
66  HCURSOR SetCursor(HCURSOR hCursor)
67  {
68  ASSERT(IsWindow());
69  return (HCURSOR)(UINT_PTR)SendMessageX(STM_SETIMAGE, IMAGE_CURSOR, (LPARAM)hCursor);
70  }
71  HCURSOR GetCursor()
72  {
73  ASSERT(IsWindow());
74  return (HCURSOR)(UINT_PTR)SendMessageX(STM_GETIMAGE, IMAGE_CURSOR);
75  }
76  };
77 
78  class GRAYLIB_LINK cWndEdit : public cWndHandle
79  {
84 
85  public:
86  // Constructors
87  cWndEdit(HWND hWnd = WINHANDLE_NULL) : cWndHandle(hWnd)
88  {}
89  cWndEdit(cWndHandle* pWndParent, DLGID_t id) : cWndHandle(pWndParent, id)
90  {}
91  virtual ~cWndEdit()
92  {
93  }
94 
95  // Operations
96 
97  void SetSel(DWORD dwSelectionPos)
98  {
100  ASSERT(IsWindow());
101  SendMessageX(EM_SETSEL, (WPARAM)dwSelectionPos, (LPARAM)dwSelectionPos);
102  }
103  void SetSel(StrLen_t nStartChar, StrLen_t nEndChar)
104  {
105  ASSERT(IsWindow());
106  SendMessageX(EM_SETSEL, (WPARAM)nStartChar, (LPARAM)nEndChar);
107  }
108  DWORD GetSel() const
109  {
111  ASSERT(IsWindow());
112  return((DWORD)SendMessageX(EM_GETSEL));
113  }
114  void GetSel(StrLen_t& nStartChar, StrLen_t& nEndChar) const
115  {
116  ASSERT(IsWindow());
117  DWORD dwSel = GetSel();
118  nStartChar = LOWORD(dwSel);
119  nEndChar = HIWORD(dwSel);
120  }
121 
122  void ReplaceSel(const GChar_t* lpszNewText, bool bCanUndo = false)
123  {
124  ASSERT(IsWindow());
125  SendMessageX(EM_REPLACESEL, (WPARAM)bCanUndo, (LPARAM)lpszNewText);
126  }
127 
128  int GetLineCount() const
129  {
130  ASSERT(IsWindow());
131  return (int)SendMessageX(EM_GETLINECOUNT);
132  }
133  int GetLine(int nLine, GChar_t* lpszBuffer) const
134  {
136  ASSERT(IsWindow());
137  return (int)SendMessageX(EM_GETLINE, (WPARAM)nLine, (LPARAM)lpszBuffer);
138  }
139  StrLen_t LineLength(StrLen_t nCharIndex = -1) const
140  {
141  // Get line length from char index.
142  return (StrLen_t)SendMessageX(EM_LINELENGTH, (WPARAM)nCharIndex);
143  }
144  StrLen_t LineIndex(int nLine = -1) const
145  {
146  // Get Char index from line index.
147  return (int)SendMessageX(EM_LINEINDEX, (WPARAM)nLine);
148  }
149  int LineFromChar(StrLen_t nCharIndex) const
150  {
151  // MFC like.
152  return (int)(DWORD)SendMessageX(EM_LINEFROMCHAR, (WPARAM)(int)(nCharIndex), 0L);
153  }
154 
155  BOOL GetModify() const
156  {
157  return((BOOL)SendMessageX(EM_GETMODIFY));
158  }
159  void SetModify(bool bModified)
160  {
161  SendMessageX(EM_SETMODIFY, (WPARAM)(UINT)(bModified));
162  }
163 
164  DWORD Scroll(int iAction = SB_PAGEDOWN)
165  {
166  return((DWORD)SendMessageX(EM_SCROLL, (WPARAM)iAction));
167  }
168  void ScrollCaret()
169  {
170  SendMessageX(EM_SCROLLCARET);
171  }
172  void ScrollLine(int iLines = 0, StrLen_t iChars = 0)
173  {
174  // MFC = Scroll()
175  // EM_LINESCROLL = 0x00B6
176  SendMessageX(EM_LINESCROLL, (WPARAM)iChars, (LPARAM)iLines);
177  }
178  void SetTabStops(int cTabs, const int* lpTabs)
179  {
180  SendMessageX(EM_SETTABSTOPS, (WPARAM)cTabs, (LPARAM)lpTabs);
181  }
182 
183 #if 0
184  BOOL CanUndo() const { (BOOL)(DWORD)SendMessageX(EM_CANUNDO, 0L, 0L) }
185  BOOL Undo() { (BOOL)(DWORD)SendMessageX(EM_UNDO, 0L, 0L) }
186  void EmptyUndoBuffer() { (void)SendMessageX(EM_EMPTYUNDOBUFFER, 0L, 0L) }
187  void SetPasswordChar(ch) { (void)SendMessageX(EM_SETPASSWORDCHAR, (WPARAM)(UINT)(ch), 0L) }
188  BOOL FmtLines(fAddEOL) { (BOOL)(DWORD)SendMessageX(EM_FMTLINES, (WPARAM)(BOOL)(fAddEOL), 0L) }
189 #endif
190 
191 #ifndef UNDER_CE
192  HLOCAL get_Handle() const
193  {
194  return((HLOCAL)(UINT_PTR)SendMessageX(EM_GETHANDLE));
195  }
196  void SetHandle(HLOCAL h)
197  {
198  SendMessageX(EM_SETHANDLE, (WPARAM)(HLOCAL)(h));
199  }
200 #endif
201 
202  int GetFirstVisibleLine() const
203  {
204  return((int)SendMessageX(EM_GETFIRSTVISIBLELINE));
205  }
206  bool SetTextFromFile(const FILECHAR_t* pszFilename);
207  };
208 
209  class GRAYLIB_LINK cWndComboBox : public cWndHandle
210  {
214  public:
215  cWndComboBox(HWND hWnd = WINHANDLE_NULL) : cWndHandle(hWnd)
216  {}
217  cWndComboBox(cWndHandle* pWndParent, DLGID_t id) : cWndHandle(pWndParent, id)
218  {}
219  virtual ~cWndComboBox()
220  {
221  }
222 
223  // Attributes
224  // for entire combo box
225  int GetCount() const
226  {
227  ASSERT(IsWindow());
228  return (int)SendMessageX(CB_GETCOUNT);
229  }
230  int GetCurSel() const
231  {
232  ASSERT(IsWindow());
233  return (int)SendMessageX(CB_GETCURSEL, 0, 0);
234  }
235  int SetCurSel(int nSelect)
236  {
237  ASSERT(IsWindow());
238  return (int)SendMessageX(CB_SETCURSEL, nSelect, 0);
239  }
240 
241  // for edit control
242  DWORD GetEditSel() const
243  {
244  ASSERT(IsWindow());
245  return (DWORD)SendMessageX(CB_GETEDITSEL, 0, 0);
246  }
247 
248  // for combobox item
249  DWORD_PTR GetItemData(int nIndex) const
250  {
251  ASSERT(IsWindow());
252  return (DWORD_PTR)SendMessageX(CB_GETITEMDATA, nIndex, 0);
253  }
254  int SetItemData(int nIndex, DWORD_PTR dwItemData)
255  {
256  ASSERT(IsWindow());
257  return (int)SendMessageX(CB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
258  }
259  // int FindItemData(int nStartAfter, DWORD_PTR dwItemData) const;
260 
261  // Operations
262 
263  // manipulating listbox items
264  int AddString(const GChar_t* lpszString)
265  {
266  // @return Position in the list, -1 = CB_ERR, CB_ERRSPACE .
267  ASSERT(IsWindow());
268  return (int)SendMessageX(CB_ADDSTRING, 0, (LPARAM)lpszString);
269  }
270  int AddItem(const GChar_t* lpszString, DWORD_PTR dwItemData)
271  {
272  int nIndex = AddString(lpszString);
273  SetItemData(nIndex, dwItemData);
274  return nIndex;
275  }
276  int InsertString(int nIndex, const GChar_t* lpszString)
277  {
278  ASSERT(IsWindow());
279  return (int)SendMessageX(CB_INSERTSTRING, nIndex, (LPARAM)lpszString);
280  }
281  int InsertItem(int nIndex, const GChar_t* lpszString, DWORD_PTR dwItemData)
282  {
283  nIndex = InsertString(nIndex, lpszString);
284  SetItemData(nIndex, dwItemData);
285  return nIndex;
286  }
287 
288  int DeleteItem(UINT nIndex)
289  {
290  ASSERT(IsWindow());
291  return (int)SendMessageX(CB_DELETESTRING, nIndex, 0);
292  }
293  void ResetContent()
294  {
295  ASSERT(IsWindow());
296  SendMessageX(CB_RESETCONTENT, 0, 0);
297  }
298 
299  int GetLBTextLen(int nIndex) const
300  {
301  // @return Length of the string. or CB_ERR
302  ASSERT(IsWindow());
303  return (int)SendMessageX(CB_GETLBTEXTLEN, nIndex, 0);
304  }
305  int GetLBText(int nIndex, GChar_t* lpszText) const
306  {
307  // @return Length of the string. or CB_ERR
308  ASSERT(IsWindow());
309  return (int)SendMessageX(CB_GETLBTEXT, nIndex, (LPARAM)lpszText);
310  }
311  int GetLBText(int nIndex, cString& rString) const;
312  cString GetLBText(int nIndex) const;
313 
314  // selection helpers
315  int FindString(int nStartAfter, const GChar_t* lpszString) const;
316  int SelectString(int nStartAfter, const GChar_t* lpszString);
317 
318  int FillComboBox(const cArrayStringA& aValues);
319  };
320 
321 #ifndef UNDER_CE
322 
323  class GRAYLIB_LINK cWndScrollBar : public cWndHandle
324  {
327  public:
328  cWndScrollBar(HWND hWnd = WINHANDLE_NULL) : cWndHandle(hWnd)
329  {}
330  cWndScrollBar(cWndHandle* pWndParent, DLGID_t id) : cWndHandle(pWndParent, id)
331  {}
332  virtual ~cWndScrollBar()
333  {
334  }
335 
336  // Attributes
337  int GetScrollPos() const
338  {
339  ASSERT(IsWindow());
340  return ::GetScrollPos(get_Hwnd(), SB_CTL);
341  }
342  int SetScrollPos(int nPos, bool bRedraw)
343  {
344  ASSERT(IsWindow());
345  return ::SetScrollPos(get_Hwnd(), SB_CTL, nPos, bRedraw);
346  }
347  void GetScrollRange(LPINT lpMinPos, LPINT lpMaxPos) const
348  {
349  ASSERT(IsWindow());
350  ::GetScrollRange(get_Hwnd(), SB_CTL, lpMinPos, lpMaxPos);
351  }
352  void SetScrollRange(int nMinPos, int nMaxPos, bool bRedraw)
353  {
354  ASSERT(IsWindow());
355  ::SetScrollRange(get_Hwnd(), SB_CTL, nMinPos, nMaxPos, bRedraw);
356  }
357  void ShowScrollBar(bool bShow)
358  {
359  ASSERT(IsWindow());
360  ::ShowScrollBar(get_Hwnd(), SB_CTL, bShow);
361  }
362  BOOL EnableScrollBar(UINT nArrowFlags)
363  {
364  ASSERT(IsWindow());
365  return ::EnableScrollBar(get_Hwnd(), SB_CTL, nArrowFlags);
366  }
367 
368  BOOL SetScrollInfo(LPSCROLLINFO lpScrollInfo, bool bRedraw)
369  {
370  lpScrollInfo->cbSize = sizeof(*lpScrollInfo);
371  ::SetScrollInfo(get_Hwnd(), SB_CTL, lpScrollInfo, bRedraw);
372  return true;
373  }
374 
375  BOOL GetScrollInfo(LPSCROLLINFO lpScrollInfo, UINT nMask)
376  {
377  lpScrollInfo->cbSize = sizeof(*lpScrollInfo);
378  lpScrollInfo->fMask = nMask;
379  return ::GetScrollInfo(get_Hwnd(), SB_CTL, lpScrollInfo);
380  }
381 
382  int GetScrollLimit()
383  {
384  int nMin, nMax;
385  GetScrollRange(&nMin, &nMax);
386  SCROLLINFO info;
387  if (GetScrollInfo(&info, SIF_PAGE))
388  {
389  int iPage = info.nPage - 1;
390  if (iPage > 0)
391  nMax -= iPage;
392  }
393  return nMax;
394  }
395  };
396 
397 #endif
398 
399  class GRAYLIB_LINK cWndListBox : public cWndHandle
400  {
403  public:
404  // Constructors
405  cWndListBox(HWND hWnd = WINHANDLE_NULL) : cWndHandle(hWnd)
406  {}
407  cWndListBox(cWndHandle* pWndParent, DLGID_t id) : cWndHandle(pWndParent, id)
408  {}
409  virtual ~cWndListBox()
410  {
411  }
412 
413  // Operations
414 
415  void ResetContent()
416  {
417  ASSERT(IsWindow());
418  SendMessageX(LB_RESETCONTENT);
419  }
420  int GetCount() const
421  {
422  return((int)(DWORD)SendMessageX(LB_GETCOUNT));
423  }
424  int AddString(const GChar_t* lpsz) const
425  {
426  return((int)(DWORD)SendMessageX(LB_ADDSTRING, 0L, (LPARAM)(lpsz)));
427  }
428  int DeleteString(int index)
429  {
430  return((int)(DWORD)SendMessageX(LB_DELETESTRING, (WPARAM)(index), 0L));
431  }
432  int InsertString(int index, const GChar_t* lpsz)
433  {
434  return((int)(DWORD)SendMessageX(LB_INSERTSTRING, (WPARAM)(index), (LPARAM)(lpsz)));
435  }
436  DWORD_PTR GetItemData(int index) const
437  {
438  return((DWORD_PTR)SendMessageX(LB_GETITEMDATA, (WPARAM)(index), 0L));
439  }
440  int SetItemData(int index, DWORD data)
441  {
442  return((int)(DWORD)SendMessageX(LB_SETITEMDATA, (WPARAM)(int)(index), (LPARAM)(data)));
443  }
444  int GetTextLen(int index)
445  {
446  return((int)(DWORD)SendMessageX(LB_GETTEXTLEN, (WPARAM)(index)));
447  }
448  int GetText(int index, const GChar_t* lpszBuffer)
449  {
450  return((int)(DWORD)SendMessageX(LB_GETTEXT, (WPARAM)(index), (LPARAM)(lpszBuffer)));
451  }
452  int AddItemData(DWORD data)
453  {
454  return((int)(DWORD)SendMessageX(LB_ADDSTRING, 0L, (LPARAM)(data)));
455  }
456  int InsertItemData(int index, DWORD data)
457  {
458  return((int)(DWORD)SendMessageX(LB_INSERTSTRING, (WPARAM)(index), (LPARAM)(data)));
459  }
460  void SetTabStops(int cTabs, const int* lpTabs)
461  {
462  SendMessageX(LB_SETTABSTOPS, (WPARAM)(int)(cTabs), (LPARAM)(const int*)(lpTabs));
463  }
464  int SetCurSel(int index)
465  {
466  return((int)(DWORD)SendMessageX(LB_SETCURSEL, (WPARAM)index));
467  }
468  int GetCurSel() const
469  {
470  return((int)(DWORD)SendMessageX(LB_SETCURSEL));
471  }
472  };
473 
474  class GRAYLIB_LINK cWndButton : public cWndHandle
475  {
478  public:
479  // Constructors
480  cWndButton(HWND hWnd = WINHANDLE_NULL) : cWndHandle(hWnd)
481  {}
482  cWndButton(cWndHandle* pWndParent, DLGID_t id) : cWndHandle(pWndParent, id)
483  {}
484  virtual ~cWndButton()
485  {
486  }
487 
488  // Operations
489  int GetCheck() const
490  {
492  return((int)(DWORD)SendMessageX(BM_GETCHECK));
493  }
494  void SetCheck(int check)
495  {
497  SendMessageX(BM_SETCHECK, (WPARAM)(check));
498  }
499  void SetCheckBool(bool bCheck)
500  {
501  SetCheck(bCheck ? BST_CHECKED : BST_UNCHECKED);
502  }
503 
504  int GetState() const
505  {
506  return((int)(DWORD)SendMessageX(BM_GETSTATE));
507  }
508  UINT SetState(int state)
509  {
510  return((UINT)(DWORD)SendMessageX(BM_SETSTATE, (WPARAM)(state)));
511  }
512  };
513 
514 #ifndef _MFC_VER
515  typedef cWndStatic CStatic;
516  typedef cWndEdit CEdit;
517  typedef cWndComboBox CComboBox;
518 #endif
519 };
520 #endif // _WIN32
521 #endif // _INC_cWndControls_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
Using X files without the sources and the makefile How to use you just create a debug directory e the sample3 directory must contain Sample3 Final Sample3 exe Sample3 Final Debug Sample3 Final Gfx OpenGL bmp Sample3 Final Gfx tiny_skin bmp Sample3 Final Gfx tiny_4anim x The source files have the DevCpp project file plus the makefile The demos use standard FreeGlut functions Technical without warranty Neither Paul Coppens nor GameDev net make any or either express or with respect to the their or fitness for a specific purpose neither Paul Coppens nor GameDev net shall have any liability to you or any other person or entity with respect to any or damage caused or alleged to have been caused directly or indirectly by the programs provided by Paul Coppens and GameDev net This but is not limited interruption of loss of data
Definition: Readme.txt:39
#define ASSERT(exp)
Definition: cDebugAssert.h:87
#define WINHANDLE_NULL
HWND, HPEN, etc are NOT OS Handles. like HWND_DESKTOP. like HANDLEPTR_NULL. This is a WINAPI void* ha...
Definition: cOSHandle.h:23
Definition: cMesh.h:22
UINT DLGID_t
old window format this was a WORD, EX format this is UINT32.
Definition: cResDialog.h:68
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26
cArrayString< char > cArrayStringA
Definition: cArrayString.h:174
cStringT< GChar_t > cString
Definition: cString.h:636
uint16 index
Definition: sample3.cpp:29