4 #ifndef tools_Windows_window
5 #define tools_Windows_window
15 static const std::string& s_class() {
16 static const std::string s_v(
"tools::Windows::window");
19 static void register_class(){
20 static bool s_done =
false;
23 wc.style = CS_HREDRAW | CS_VREDRAW;
24 wc.lpfnWndProc = (WNDPROC)
proc;
27 wc.hInstance = ::GetModuleHandle(NULL);
28 wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
29 wc.hCursor = LoadCursor(NULL,IDC_ARROW);
30 wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
31 wc.lpszMenuName = s_class().c_str();
32 wc.lpszClassName = s_class().c_str();
48 window(
const char* a_title,
int a_x,
int a_y,
unsigned int a_w,
unsigned int a_h,
unsigned int a_mask = WS_OVERLAPPEDWINDOW)
57 m_hwnd = ::CreateWindow(s_class().c_str(),
63 ::GetModuleHandle(NULL),
66 ::SetWindowText(
m_hwnd,a_title);
67 ::SetWindowLongPtr(
m_hwnd,GWLP_USERDATA,LONG_PTR(
this));
71 ::SetWindowLongPtr(
m_hwnd,GWLP_USERDATA,LONG_PTR(NULL));
114 ::GetWindowRect(
m_hwnd,&wrect);
115 unsigned int ww = wrect.right-wrect.left;
116 unsigned int wh = wrect.bottom-wrect.top;
119 ::GetClientRect(
m_hwnd,&carect);
120 unsigned int cw = carect.right-carect.left;
121 unsigned int ch = carect.bottom-carect.top;
123 unsigned int woffset = ww-cw;
124 unsigned int hoffset = wh-ch;
126 ::MoveWindow(
m_hwnd,wrect.left,wrect.top,a_w+woffset,a_h+hoffset,TRUE);
128 void move(
unsigned int a_x,
unsigned int a_y) {
131 ::GetWindowRect(
m_hwnd,&rect);
132 unsigned int w = rect.right-rect.left;
133 unsigned int h = rect.bottom-rect.top;
134 ::MoveWindow(
m_hwnd,a_x,a_y,w,h,TRUE);
140 static LRESULT CALLBACK
proc(HWND a_hwnd,UINT a_msg,WPARAM a_wparam,LPARAM a_lparam) {
144 int width = LOWORD(a_lparam);
145 int height = HIWORD(a_lparam);
146 HWND
hwnd = GetFirstChild(a_hwnd);
148 ::MoveWindow(
hwnd,0,0,width,height,TRUE);
153 window* _this = (
window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
163 window* _this = (
window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
168 window* _this = (
window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
173 window* _this = (
window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
174 if(_this) _this->
key_up();
178 window* _this = (
window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
183 window* _this = (
window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
188 window* _this = (
window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
193 window* _this = (
window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
203 window* _this = (
window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
208 window* _this = (
window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
217 window* _this = (
window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
218 if(_this) _this->
close();
222 return (DefWindowProc(a_hwnd,a_msg,a_wparam,a_lparam));
225 window* _this = (
window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
227 if(_this->
m_hwnd!=a_hwnd) {
232 ::SetWindowLongPtr(a_hwnd,GWLP_USERDATA,LONG_PTR(NULL));
237 ::GetWindowRect(a_hwnd,&rect);
238 a_w = rect.right-rect.left;
239 a_h = rect.bottom-rect.top;