feisty meow concerns codebase  2.140
window_classist.h
Go to the documentation of this file.
1 #ifndef WINDOW_CLASSIST_CLASS
2 #define WINDOW_CLASSIST_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : window_classist *
7 * Author : Chris Koeritz *
8 * *
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 \*****************************************************************************/
17 
19 
53 #include "windoze_helper.h"
54 
55 #include <basis/utf_conversion.h>
56 
57 namespace application {
58 
59 #ifndef __WIN32__
60 
61 // this is a placeholder implementation for other platforms.
63  const basis::astring &formal(class_name)) { return NULL_POINTER; }
65 
66 #else
67 
69 
70 LRESULT CALLBACK window_procedure(HWND hWnd, UINT message,
71  WPARAM wParam, LPARAM lParam)
72 {
73 
74  switch (message) {
75  case WM_COMMAND: {
76  int identifier, event;
77  identifier = LOWORD(wParam);
78  event = HIWORD(wParam);
79  return DefWindowProc(hWnd, message, wParam, lParam);
80  break;
81  }
82  case WM_PAINT: {
83  HDC hdc;
84  PAINTSTRUCT ps;
85  hdc = BeginPaint(hWnd, &ps);
86  // hmmm: Add any drawing code here...
87  EndPaint(hWnd, &ps);
88  break;
89  }
90  case WM_DESTROY: {
91  PostQuitMessage(0);
92  break;
93  }
94  default: {
95  return DefWindowProc(hWnd, message, wParam, lParam);
96  }
97  }
98  return 0;
99 }
100 
102 
103 ATOM register_class(const basis::astring &name)
104 {
105  WNDCLASSEX wcex;
106  wcex.cbSize = sizeof(WNDCLASSEX);
107 
108  wcex.style = CS_HREDRAW | CS_VREDRAW;
109  wcex.lpfnWndProc = (WNDPROC)window_procedure;
110  wcex.cbClsExtra = 0;
111  wcex.cbWndExtra = 0;
112  wcex.hInstance = GET_INSTANCE_HANDLE();
113  wcex.hIcon = 0;
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;
119  wcex.hIconSm = 0;
120 
121  return RegisterClassEx(&wcex);
122 }
123 
125  const basis::astring &class_name)
126 {
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);
133  return f_window;
134 }
135 
137 {
138  SendMessage(f_window, WM_CLOSE, NULL_POINTER, NULL_POINTER);
139 //hmmm: is this enough?
140 }
141 
142 #endif // win32
143 
144 } // namespace.
145 
146 #endif // outer guard
147 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
#define formal(parameter)
This macro just eats what it's passed; it marks unused formal parameters.
Definition: definitions.h:48
#define NULL_POINTER
The value representing a pointer to nothing.
Definition: definitions.h:32
Implements an application lock to ensure only one is running at once.
window_handle create_simplistic_window(const basis::astring &formal(window_title), const basis::astring &formal(class_name))
void whack_simplistic_window(window_handle formal(f_window))
Support for unicode builds.
Aids in achievement of platform independence.
void * ATOM
#define GET_INSTANCE_HANDLE()
a handy macro that frees one from knowing the name of the handle.
void * window_handle
void * HDC