WinapiExtension
 All Classes Files Functions Variables Typedefs Pages
functions.h
Go to the documentation of this file.
1 #ifndef WINAPI_EX_FUNCTIONS_H
2 #define WINAPI_EX_FUNCTIONS_H
3 
9 class ComboBox;
10 class Button;
11 class Edit;
12 class ListBox;
13 class ScrollBar;
14 class StaticCtrl;
15 
20 HWND CreateControl(HWND parent, const tstring& className, const tstring& text, int id, int x, int y, int w, int h, DWORD addStyle, DWORD addExStyle);
21 
23 Button CreateButton(HWND parent, const tstring& text, int id, int x, int y, int w, int h, DWORD addStyle = 0);
25 Button CreateCheckBox(HWND parent, const tstring& text, int id, int x, int y, int w, int h, DWORD addStyle = 0);
27 ComboBox CreateComboBox(HWND parent, int id, int x, int y, int w, int h, DWORD addStyle = CBS_DROPDOWNLIST|WS_VSCROLL);
29 Edit CreateEdit(HWND parent, int id, int x, int y, int w, int h, DWORD addStyle = ES_AUTOHSCROLL);
31 Button CreateGroupBox(HWND parent, const tstring& text, int x, int y, int w, int h, DWORD addStyle = 0);
33 ListBox CreateListBox(HWND parent, int id, int x, int y, int w, int h, DWORD addStyle = WS_VSCROLL|LBS_NOTIFY);
35 Button CreateRadioButton(HWND parent, const tstring& text, int id, int x, int y, int w, int h, DWORD addStyle = 0);
37 ScrollBar CreateScrollBar(HWND parent, int id, int x, int y, int w, int h, DWORD addStyle = SBS_HORZ);
39 StaticCtrl CreateStatic(HWND parent, const tstring& text, int x, int y, int w, int h, DWORD addStyle = 0);
40 
41 #ifdef WINAPI_EX_COMMCTRL
42  class ListView;
43  class ProgressBar;
44  class StatusBar;
45  class TabCtrl;
46  class TreeView;
47 
52  HWND CreateDateTimePicker(HWND parent, int id, int x, int y, int w, int h, DWORD addStyle = 0);
57  ListView CreateListView(HWND parent, int id, int x, int y, int w, int h, DWORD addStyle = 0);
62  ProgressBar CreateProgressBar(HWND parent, int id, int x, int y, int w, int h, DWORD addStyle = 0);
71  StatusBar CreateStatusBar(HWND parent, DWORD addStyle = 0);
76  TabCtrl CreateTabControl(HWND parent, int id, int x, int y, int w, int h, DWORD addStyle = 0);
81  TreeView CreateTreeView(HWND parent, int id, int x, int y, int w, int h, DWORD addStyle = 0);
82 
83 #endif // WINAPI_EX_COMMCTRL
84 
91 void UpdateScrollPos(HWND window, UINT message, WPARAM wp, LPARAM lp);
92 
93 //-----------------------------------------------------------------------------
94 
95 // this is basically how every scrollbar works
96 // but if you forget to call it in the WM_HSCROLL message handler, the scrollbar will not react
97 inline void UpdateScrollPos(HWND window, UINT message, WPARAM wp, LPARAM lp)
98 {
99  int scrollCode = LOWORD(wp);
100  int scrollPos = HIWORD(wp);
101  HWND scrollBar = (HWND)lp;
102 
103  HWND scrollBarHandle;
104  int scrollBarType;
105  if(scrollBar)
106  {
107  scrollBarHandle = scrollBar;
108  scrollBarType = SB_CTL;
109  }
110  else
111  {
112  scrollBarHandle = window;
113  scrollBarType = message == WM_HSCROLL ? SB_HORZ : SB_VERT;
114  }
115 
116  SCROLLINFO si;
117  si.cbSize = sizeof(si);
118  si.fMask = SIF_PAGE|SIF_POS|SIF_RANGE;
119  GetScrollInfo(scrollBarHandle, scrollBarType, &si);
120 
121  switch(scrollCode){
122  case SB_LINELEFT:
123  //case SB_LINEUP:
124  si.nPos -= 1;
125  break;
126  case SB_LINERIGHT:
127  //case SB_LINEDOWN:
128  si.nPos += 1;
129  break;
130  case SB_PAGELEFT:
131  //case SB_PAGEUP:
132  if(si.nPage == 0)
133  si.nPos -= 1;
134  else
135  si.nPos -= si.nPage;
136  break;
137  case SB_PAGERIGHT:
138  //case SB_PAGEDOWN:
139  if(si.nPage == 0)
140  si.nPos += 1;
141  else
142  si.nPos += si.nPage;
143  break;
144  case SB_LEFT:
145  //case SB_TOP:
146  si.nPos = si.nMin;
147  break;
148  case SB_RIGHT:
149  //case SB_BOTTOM:
150  si.nPos = si.nMax;
151  break;
152  case SB_THUMBTRACK:
153  si.nPos = scrollPos;
154  break;
155  case SB_THUMBPOSITION:
156  si.nPos = scrollPos;
157  break;
158  default:
159  break;
160  }
161 
162  SetScrollPos(scrollBarHandle, scrollBarType, si.nPos, TRUE);
163 }
164 
165 #endif