1 #ifndef WINDOW_CLASSIST_CLASS
2 #define WINDOW_CLASSIST_CLASS
4 /*****************************************************************************\
6 * Name : window_classist *
7 * Author : Chris Koeritz *
9 *******************************************************************************
10 * Copyright (c) 2007-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 //! An add-in file providing window class registration and a window procedure.
20 This file makes it easier to add a very simple window to any console or
21 win32 application that might need it (possibly because the app does not
22 create any windows itself, but for crazy insane reasons, a window is still
23 needed by an external agent, ahem installshield). It implements a very
24 important part of this process, which is setting a window procedure and
25 registering a window class. Sometime in 2005 or 2006, a windows update
26 came through that made these formerly optional practices mandatory (and
27 broke many of our applications that created windows without a window
28 procedure or class registration). That occurrence prompted the creation
29 of this class which tries to provide the bare minimum needed to make
34 // include our code file to embed the window procedure and register class
35 // methods in whoever needs them. this should only be needed once per
38 #include <application/windows_classist.h>
40 // create our simple window...
42 basis::astring window_title = "my_freaky_window";
43 basis::astring class_name = "jumbo_stompy_update_crudburger";
45 window_handle f_window = create_simplistic_window(window_title, class_name);
47 // and then much later, after the window is no longer needed...
49 whack_simplistic_window(f_window);
53 #include "windoze_helper.h"
55 #include <basis/utf_conversion.h>
57 namespace application {
61 // this is a placeholder implementation for other platforms.
62 window_handle create_simplistic_window(const basis::astring &formal(window_title),
63 const basis::astring &formal(class_name)) { return NULL_POINTER; }
64 void whack_simplistic_window(window_handle formal(f_window)) {}
68 //! this is the very simple window procedure used by register_class() below.
70 LRESULT CALLBACK window_procedure(HWND hWnd, UINT message,
71 WPARAM wParam, LPARAM lParam)
76 int identifier, event;
77 identifier = LOWORD(wParam);
78 event = HIWORD(wParam);
79 return DefWindowProc(hWnd, message, wParam, lParam);
85 hdc = BeginPaint(hWnd, &ps);
86 // hmmm: Add any drawing code here...
95 return DefWindowProc(hWnd, message, wParam, lParam);
101 //! returns the registered class as a windows atom.
103 ATOM register_class(const basis::astring &name)
106 wcex.cbSize = sizeof(WNDCLASSEX);
108 wcex.style = CS_HREDRAW | CS_VREDRAW;
109 wcex.lpfnWndProc = (WNDPROC)window_procedure;
112 wcex.hInstance = GET_INSTANCE_HANDLE();
114 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
115 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
116 wcex.lpszMenuName = 0;
117 basis::to_unicode_persist(temp_class, name);
118 wcex.lpszClassName = temp_class;
121 return RegisterClassEx(&wcex);
124 window_handle create_simplistic_window(const basis::astring &window_title,
125 const basis::astring &class_name)
127 register_class(class_name);
128 window_handle f_window = CreateWindow(basis::to_unicode_temp(class_name),
129 basis::to_unicode_temp(window_title), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
130 0, CW_USEDEFAULT, 0, NULL_POINTER, NULL_POINTER, GET_INSTANCE_HANDLE(), NULL_POINTER);
131 ShowWindow(f_window, SW_HIDE);
132 UpdateWindow(f_window);
136 void whack_simplistic_window(window_handle f_window)
138 SendMessage(f_window, WM_CLOSE, NULL_POINTER, NULL_POINTER);
139 //hmmm: is this enough?
146 #endif // outer guard