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 and this permission notice shall be included
27 * in all copies or substantial portions of the Software.
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
30 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
32 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35 * DEALINGS IN THE SOFTWARE.
37 * ---------------------------------------------------------------------------
40 #define WIN32_LEAN_AND_MEAN
46 # define OnEventCase(MSG,ACTION) case MSG: if( ACTION == 0L ) return 0L; break
47 # define SplitWord(PARAM_NAME) LOWORD(PARAM_NAME), HIWORD(PARAM_NAME)
49 long CALLBACK GenericWindow::WindowProcedure
50 ( HWND window, unsigned message, WPARAM w_param, LPARAM l_param )
52 /* Generic dispatcher for all window procedures. This is a static
53 * member function of the generic window class; as such, it must do
54 * no more than establish a pointer to the class instance, before
55 * delegating processing to a regular member function.
58 if( message == WM_NCCREATE )
60 /* This message is dispatched during processing of CreateWindow(),
61 * which has been called by the class constructor; we have arranged
62 * that the requisite class instance pointer will have been passed
63 * within the CREATESTRUCT at *l_param, and we must now save it.
65 me = (GenericWindow *)(((CREATESTRUCT *)(l_param))->lpCreateParams);
66 SetWindowLong( window, GWL_USERDATA, (long)(me) );
68 /* We must also store the passed window handle within the class
69 * instance data space...
71 me->AppWindow = window;
74 /* ...otherwise we retrieve the class instance pointer we saved,
75 * during the CreateWindow() call...
77 me = (GenericWindow *)(GetWindowLong( window, GWL_USERDATA ));
79 /* ...before delegating the handling of the current message to the
80 * controller associated with the class instance...
82 return me ? me->Controller( message, w_param, l_param )
84 * ...or to the default window procedure, if no controller can
87 : DefWindowProc( window, message, w_param, l_param );
90 long GenericWindow::Controller
91 ( unsigned message, WPARAM w_param, LPARAM l_param )
93 /* Centralised marshalling function for all window messages. It is
94 * to this function that the preceding static function delegates all
95 * message handling requests; these are then forwarded...
99 /* ...to the appropriate handler from those enumerated below. In
100 * its default implementation, each of these virtual functions does
101 * no more than simply return; an actual window class must derive
102 * from the GenericWindow class, and override any such of these
103 * message handlers as may be required.
105 * FIXME: Only a small subset of possible window messages is
106 * currently supported; this list should be extended to cover
107 * all possible message types.
110 OnEventCase( WM_CREATE, OnCreate() );
111 OnEventCase( WM_COMMAND, OnCommand( w_param ) );
112 OnEventCase( WM_MOUSEMOVE, OnMouseMove( w_param ) );
113 OnEventCase( WM_LBUTTONDOWN, OnLeftButtonDown() );
114 OnEventCase( WM_LBUTTONUP, OnLeftButtonUp() );
115 OnEventCase( WM_NOTIFY, OnNotify( w_param, l_param ) );
116 OnEventCase( WM_SIZE, OnSize( w_param, SplitWord(l_param) ) );
117 OnEventCase( WM_HSCROLL, OnHorizontalScroll( SplitWord(w_param), (HWND)(l_param)) );
118 OnEventCase( WM_VSCROLL, OnVerticalScroll( SplitWord(w_param), (HWND)(l_param)) );
119 OnEventCase( WM_PAINT, OnPaint() );
120 OnEventCase( WM_DESTROY, OnDestroy() );
122 /* In the event that no handler is provided for any particular message,
123 * fall back to MS-Windows own default handler.
125 return DefWindowProc( AppWindow, message, w_param, l_param );
129 /* $RCSfile$: end of file */