neoWidgets
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
Message.h
1 #ifndef NEO_MESSAGE_H
2 #define NEO_MESSAGE_H
3 
4 namespace neo
5 {
6 
7 class WindowBase;
8 
10 struct Message
11 {
12  Message()
13  : hwnd(0)
14  , message(0)
15  , wp(0)
16  , lp(0)
17  , result(0)
18  , resultSet(false)
19  , messageHandler(0)
20  {}
21 
25  void Init(HWND pHwnd, UINT pMessage, WPARAM pWP, LPARAM pLP)
26  {
27  hwnd = pHwnd;
28  message = pMessage;
29  wp = pWP;
30  lp = pLP;
31  result = 0;
32  resultSet = false;
33  }
34 
40  void Result(LRESULT res)
41  {
42  // warn if the result is set more than once
43  assert(resultSet == false);
44  result = res;
45  resultSet = true;
46  }
47 
49  LRESULT Default();
51  void ResultDefault() { Result(Default()); }
52 
53  HWND hwnd;
54  UINT message;
55  WPARAM wp;
56  LPARAM lp;
57 
58  LRESULT result;
59  bool resultSet;
60  WindowBase* messageHandler;
61 };
62 
64 {
65  HWND WindowGainingCapture() { return (HWND)lp; }
66 };
67 
68 struct CommandMessage : public Message
69 {
70  WORD ID() { return LOWORD(wp); }
71  WORD NotifyCode() { return HIWORD(wp); }
72  HWND Control() { return reinterpret_cast<HWND>(lp); }
73 };
74 
75 struct CreateMessage : public Message
76 {
77  CREATESTRUCT* CreateStruct() { return reinterpret_cast<CREATESTRUCT*>(lp); }
78 };
79 
80 struct CtlColorMessage : public Message
81 {
82  HDC DC() { return (HDC)wp; }
83  HWND Control() { return (HWND)lp; }
84 
86  void Result(HBRUSH brush) { return Message::Result(reinterpret_cast<LRESULT>(brush)); }
87 };
88 
89 struct DropFilesMessage : public Message
90 {
94  HDROP HandleDrop() { return reinterpret_cast<HDROP>(wp); }
95 
99  UINT NumFiles() { return DragQueryFile(HandleDrop(), 0xFFFFFFFF, 0, 0); }
100 
105  tstring GetFile(UINT i)
106  {
107  UINT requiredBufferSize = DragQueryFile(HandleDrop(), i, 0, 0);
108 
109  tstring dropped;
110  dropped.resize(requiredBufferSize);
111 
112  DragQueryFile(HandleDrop(), i, &dropped[0], requiredBufferSize + 1);
113 
114  return dropped;
115  }
116 };
117 
118 struct EnableMessage : public Message
119 {
120  bool Enabled() { return wp == TRUE; }
121 };
122 
123 struct EraseBkgndMessage : public Message
124 {
125  HDC DC() { return reinterpret_cast<HDC>(wp); }
126 
128  void Result(bool erased) { Message::Result(erased ? TRUE : FALSE); }
129 };
130 
131 struct GetIconMessage : public Message
132 {
133  WPARAM Type() { return wp; }
134 
136  void Result(HICON icon) { Message::Result(reinterpret_cast<LRESULT>(icon)); }
137 };
138 
140 {
141  MINMAXINFO* MinMaxInfo() { return reinterpret_cast<MINMAXINFO*>(lp); }
142 };
143 
144 struct KeyMessage : public Message
145 {
154  WPARAM KeyCode() { return wp; }
155  SHORT Repeat() { return LOWORD(lp); }
156  BYTE ScanCode() { return static_cast<BYTE>((lp & 0x00FF0000) >> 16); }
157  bool ExtendedKey() { return (lp & 0x01000000) > 0; }
158  bool AltDown() { return (lp & 0x20000000) > 0; }
159  bool KeyWasDown() { return (lp & 0x40000000) > 0; }
160  bool KeyWasUp() { return !KeyWasDown(); }
161  bool KeyReleased() { return (lp & 0x80000000) > 0; }
162  bool KeyPressed() { return !KeyReleased(); }
163 };
164 
165 struct MouseMessage : public Message
166 {
167  bool Ctrl() { return (wp & MK_CONTROL) > 0; }
168  bool Shift() { return (wp & MK_SHIFT) > 0; }
169  bool LButton() { return (wp & MK_LBUTTON) > 0; }
170  bool MButton() { return (wp & MK_MBUTTON) > 0; }
171  bool RButton() { return (wp & MK_RBUTTON) > 0; }
172  bool XButton1() { return (wp & MK_XBUTTON1) > 0; }
173  bool XButton2() { return (wp & MK_XBUTTON2) > 0; }
174  SHORT X() { return MAKEPOINTS(lp).x; }
175  SHORT Y() { return MAKEPOINTS(lp).y; }
176  Point GetPoint() { return Point(X(), Y()); }
178  double WheelMoveSteps()
179  {
180  return static_cast<double>( static_cast<SHORT>(HIWORD(wp)) ) /
181  static_cast<double>(WHEEL_DELTA);
182  }
184  bool FromXButton1() { return HIWORD(wp) == XBUTTON1; }
186  bool FromXButton2() { return HIWORD(wp) == XBUTTON2; }
187 };
188 
189 struct MoveMessage : public Message
190 {
191  SHORT X() { return MAKEPOINTS(lp).x; }
192  SHORT Y() { return MAKEPOINTS(lp).y; }
193  Point GetPoint() { return Point(X(), Y()); }
194 };
195 
196 struct MovingMessage : public Message
197 {
198  RECT* Rect() { return reinterpret_cast<RECT*>(lp); }
199 };
200 
201 struct NotifyMessage : public Message
202 {
203  WPARAM ID() { return wp; }
204  NMHDR* Header() { return reinterpret_cast<NMHDR*>(lp); }
205 };
206 
207 struct PrintMessage : public Message
208 {
209  HDC DC() { return reinterpret_cast<HDC>(wp); }
210  LPARAM Options() { return lp; }
211 };
212 
213 struct ScrollMessage : public Message
214 {
215  WORD Pos() { return LOWORD(wp); }
216  WORD ScrollCode() { return HIWORD(wp); }
217  HWND ScrollBar() { return reinterpret_cast<HWND>(lp); }
218  bool IsHorizontal() { return message == WM_HSCROLL; }
219  bool IsVertical() { return message == WM_VSCROLL; }
220 
222  void UpdateScrollPos();
223 };
224 
225 struct SizeMessage : public Message
226 {
227  WPARAM Type() { return wp; }
228  WORD Width() { return LOWORD(lp); }
229  WORD Height() { return HIWORD(lp); }
230  Size GetSize() { return Size(Width(), Height()); }
231 };
232 
233 struct SizingMessage : public Message
234 {
235  WPARAM Side() { return wp; }
236  RECT* Rect() { return reinterpret_cast<RECT*>(lp); }
237 };
238 
240 {
241  bool StyleChanged() { return (wp & GWL_STYLE) > 0; }
242  bool ExStyleChanged() { return (wp & GWL_EXSTYLE) > 0; }
243  STYLESTRUCT* StyleStruct() { return reinterpret_cast<STYLESTRUCT*>(lp); }
244 };
245 
246 struct TimerMessage : public Message
247 {
248  WPARAM ID() { return wp; }
249 };
250 
252 {
253  WINDOWPOS* WindowPos() { return reinterpret_cast<WINDOWPOS*>(lp); }
254 };
255 
256 } // namespace neo
257 
258 #endif
The big window class that every other class descends from.
Definition: WindowBase.h:152
Definition: Message.h:213
WPARAM KeyCode()
Definition: Message.h:154
Base class for standard Windows controls.
Definition: Control.h:73
Definition: Message.h:68
bool FromXButton2()
Definition: Message.h:186
Definition: Message.h:189
Definition: Message.h:131
Definition: Message.h:196
void ResultDefault()
Definition: Message.h:51
UINT NumFiles()
Definition: Message.h:99
Definition: Message.h:251
double WheelMoveSteps()
Definition: Message.h:178
Wrap parameters of WndProc in a struct. Can be used for any message.
Definition: Message.h:10
Definition: ControlTypes.h:83
void Init(HWND pHwnd, UINT pMessage, WPARAM pWP, LPARAM pLP)
Definition: Message.h:25
Windows POINT structure with constructor.
Definition: Rect.h:10
tstring GetFile(UINT i)
Definition: Message.h:105
Definition: Message.h:144
Unmanaged device context, to allow the user to call IDC functions on arbitrary DCs.
Definition: DC.h:167
Windows SIZE structure with constructor.
Definition: Rect.h:79
Definition: Message.h:207
LRESULT Default()
Definition: Message.inl:4
HDROP HandleDrop()
Definition: Message.h:94
Definition: Message.h:123
Definition: Message.h:89
bool FromXButton1()
Definition: Message.h:184
void UpdateScrollPos()
Definition: Message.inl:12
Windows RECT structure with constructor.
Definition: Rect.h:108
Definition: Message.h:118
void Result(HICON icon)
Definition: Message.h:136
void Result(bool erased)
Definition: Message.h:128
Definition: Message.h:233
void Result(LRESULT res)
Definition: Message.h:40
Definition: Message.h:225
Definition: Message.h:239
Definition: Message.h:201
Definition: Message.h:139
Definition: Message.h:246
Definition: Message.h:165
Definition: Message.h:75
void Result(HBRUSH brush)
Definition: Message.h:86
Definition: Message.h:63
Definition: Message.h:80