4 * ---------------------------------------------------------------------------
6 * Implementation of a minimal C++ class framework for use with the
7 * Microsoft Windows Application Programming Interface.
11 * This file provides the implementation for the default window procedure,
12 * which is used by all window classes derived from GenericWindow.
14 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
15 * Copyright (C) 2012, MinGW.org Project.
17 * ---------------------------------------------------------------------------
19 * Permission is hereby granted, free of charge, to any person obtaining a
20 * copy of this software and associated documentation files (the "Software"),
21 * to deal in the Software without restriction, including without limitation
22 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
23 * and/or sell copies of the Software, and to permit persons to whom the
24 * Software is furnished to do so, subject to the following conditions:
26 * The above copyright notice, this permission notice, and the following
27 * disclaimer shall be included in all copies or substantial portions of
30 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
31 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
33 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
35 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
36 * DEALINGS IN THE SOFTWARE.
38 * ---------------------------------------------------------------------------
41 #define WIN32_LEAN_AND_MEAN
47 # define OnEventCase(MSG,ACTION) case MSG: if( ACTION == 0L ) return 0L; break
48 # define SplitWord(PARAM_NAME) LOWORD(PARAM_NAME), HIWORD(PARAM_NAME)
50 long CALLBACK GenericWindow::WindowProcedure
51 ( HWND window, unsigned message, WPARAM w_param, LPARAM l_param )
53 /* Generic dispatcher for all window procedures. This is a static
54 * member function of the generic window class; as such, it must do
55 * no more than establish a pointer to the class instance, before
56 * delegating processing to a regular member function.
59 if( message == WM_NCCREATE )
61 /* This message is dispatched during processing of CreateWindow(),
62 * which has been called by the class constructor; we have arranged
63 * that the requisite class instance pointer will have been passed
64 * within the CREATESTRUCT at *l_param, and we must now save it.
66 me = (GenericWindow *)(((CREATESTRUCT *)(l_param))->lpCreateParams);
67 SetWindowLong( window, GWL_USERDATA, (long)(me) );
69 /* We must also store the passed window handle within the class
70 * instance data space...
72 me->AppWindow = window;
75 /* ...otherwise we retrieve the class instance pointer we saved,
76 * during the CreateWindow() call...
78 me = (GenericWindow *)(GetWindowLong( window, GWL_USERDATA ));
80 /* ...before delegating the handling of the current message to the
81 * controller associated with the class instance...
83 return me ? me->Controller( message, w_param, l_param )
85 * ...or to the default window procedure, if no controller can
88 : DefWindowProc( window, message, w_param, l_param );
91 long GenericWindow::Controller
92 ( unsigned message, WPARAM w_param, LPARAM l_param )
94 /* Centralised marshalling function for all window messages. It is
95 * to this function that the preceding static function delegates all
96 * message handling requests; these are then forwarded...
100 /* ...to the appropriate handler from those enumerated below. In
101 * its default implementation, each of these virtual functions does
102 * no more than simply return; an actual window class must derive
103 * from the GenericWindow class, and override any such of these
104 * message handlers as may be required.
106 * FIXME: Only a small subset of possible window messages is
107 * currently supported; this list should be extended to cover
108 * all possible message types.
111 OnEventCase( WM_CREATE, OnCreate() );
112 OnEventCase( WM_COMMAND, OnCommand( w_param ) );
113 OnEventCase( WM_MOUSEMOVE, OnMouseMove( w_param ) );
114 OnEventCase( WM_LBUTTONDOWN, OnLeftButtonDown() );
115 OnEventCase( WM_LBUTTONUP, OnLeftButtonUp() );
116 OnEventCase( WM_NOTIFY, OnNotify( w_param, l_param ) );
117 OnEventCase( WM_SIZE, OnSize( w_param, SplitWord(l_param) ) );
118 OnEventCase( WM_HSCROLL, OnHorizontalScroll( SplitWord(w_param), (HWND)(l_param)) );
119 OnEventCase( WM_VSCROLL, OnVerticalScroll( SplitWord(w_param), (HWND)(l_param)) );
120 OnEventCase( WM_PAINT, OnPaint() );
121 OnEventCase( WM_DESTROY, OnDestroy() );
122 OnEventCase( WM_CLOSE, OnClose() );
124 /* In the event that no handler is provided for any particular message,
125 * fall back to MS-Windows own default handler.
127 return DefWindowProc( AppWindow, message, w_param, l_param );
131 /* $RCSfile$: end of file */