g4tools  5.4.0
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
tools::Windows::window Class Reference
Inheritance diagram for tools::Windows::window:
Inheritance graph
[legend]

Public Member Functions

virtual void key_up ()
 
virtual void key_down ()
 
virtual void key_left ()
 
virtual void key_right ()
 
virtual void key_escape ()
 
virtual void close ()
 
 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)
 
virtual ~window ()
 
const windowget_me () const
 
windowget_me ()
 
bool key_shift () const
 
HWND hwnd () const
 
void set_client_area_size (unsigned int a_w, unsigned int a_h)
 
void move (unsigned int a_x, unsigned int a_y)
 
void set_focus_hwnd (HWND a_hwnd)
 
HWND focus_hwnd () const
 

Protected Member Functions

 window (const window &a_from)
 
windowoperator= (const window &a_from)
 
void get_size (HWND a_hwnd, int &a_w, int &a_h)
 

Static Protected Member Functions

static LRESULT CALLBACK proc (HWND a_hwnd, UINT a_msg, WPARAM a_wparam, LPARAM a_lparam)
 
static void wm__destroy (HWND a_hwnd)
 

Protected Attributes

HWND m_hwnd
 
bool m_key_shift
 
bool m_key_ctrl
 
HWND m_focus_hwnd
 

Detailed Description

Definition at line 14 of file window.

Constructor & Destructor Documentation

◆ window() [1/2]

tools::Windows::window::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 
)
inline

Definition at line 48 of file window.

49  :m_hwnd(0)
50  ,m_key_shift(false)
51  ,m_key_ctrl(false)
52  ,m_focus_hwnd(0)
53  {
54  // WARNING : given a_w,a_h may not be the client area because of various decorations.
55  // See set_client_area_size() method to enforce a client area size.
56  register_class();
57  m_hwnd = ::CreateWindow(s_class().c_str(),
58  NULL,
59  a_mask,
60  a_x,a_y,
61  a_w,a_h,
62  NULL,NULL,
63  ::GetModuleHandle(NULL),
64  NULL);
65  if(!m_hwnd) return;
66  ::SetWindowText(m_hwnd,a_title);
67  ::SetWindowLongPtr(m_hwnd,GWLP_USERDATA,LONG_PTR(this));
68  }

◆ ~window()

virtual tools::Windows::window::~window ( )
inlinevirtual

Definition at line 69 of file window.

69  {
70  if(m_hwnd) {
71  ::SetWindowLongPtr(m_hwnd,GWLP_USERDATA,LONG_PTR(NULL));
72  ::DestroyWindow(m_hwnd);
73  m_hwnd = 0;
74  }
75  }

◆ window() [2/2]

tools::Windows::window::window ( const window a_from)
inlineprotected

Definition at line 77 of file window.

78  :m_hwnd(0)
79  ,m_key_shift(a_from.m_key_shift)
80  ,m_key_ctrl(a_from.m_key_ctrl)
81  ,m_focus_hwnd(0)
82  {
83  /*
84  if(!a_from.m_hwnd) return;
85  int w,h;
86  get_size(a_from.m_hwnd,w,h);
87  register_class();
88  m_hwnd = ::CreateWindow(s_class().c_str(),
89  NULL,
90  WS_OVERLAPPEDWINDOW,
91  CW_USEDEFAULT,CW_USEDEFAULT,
92  w,h,
93  NULL,NULL,
94  ::GetModuleHandle(NULL),
95  NULL);
96  if(!m_hwnd) return;
97  ::SetWindowLongPtr(m_hwnd,GWLP_USERDATA,LONG_PTR(this));
98  */
99  }

Member Function Documentation

◆ close()

virtual void tools::Windows::window::close ( )
inlinevirtual

Reimplemented in tools::Windows::sg_viewer.

Definition at line 43 of file window.

43  {
44  //if(m_hwnd) ::PostMessage(m_hwnd,WM_QUIT,0,0);
45  ::PostQuitMessage(0);
46  }

◆ focus_hwnd()

HWND tools::Windows::window::focus_hwnd ( ) const
inline

Definition at line 138 of file window.

138 {return m_focus_hwnd;}

◆ get_me() [1/2]

window& tools::Windows::window::get_me ( )
inline

Definition at line 107 of file window.

107 {return *this;}

◆ get_me() [2/2]

const window& tools::Windows::window::get_me ( ) const
inline

Definition at line 106 of file window.

106 {return *this;}

◆ get_size()

void tools::Windows::window::get_size ( HWND  a_hwnd,
int &  a_w,
int &  a_h 
)
inlineprotected

Definition at line 235 of file window.

235  {
236  RECT rect;
237  ::GetWindowRect(a_hwnd,&rect);
238  a_w = rect.right-rect.left;
239  a_h = rect.bottom-rect.top;
240  }

◆ hwnd()

HWND tools::Windows::window::hwnd ( ) const
inline

Definition at line 109 of file window.

109 {return m_hwnd;}

◆ key_down()

virtual void tools::Windows::window::key_down ( )
inlinevirtual

Definition at line 39 of file window.

39 {}

◆ key_escape()

virtual void tools::Windows::window::key_escape ( )
inlinevirtual

Definition at line 42 of file window.

42 {}

◆ key_left()

virtual void tools::Windows::window::key_left ( )
inlinevirtual

Definition at line 40 of file window.

40 {}

◆ key_right()

virtual void tools::Windows::window::key_right ( )
inlinevirtual

Definition at line 41 of file window.

41 {}

◆ key_shift()

bool tools::Windows::window::key_shift ( ) const
inline

Definition at line 108 of file window.

108 {return m_key_shift;}

◆ key_up()

virtual void tools::Windows::window::key_up ( )
inlinevirtual

Definition at line 38 of file window.

38 {}

◆ move()

void tools::Windows::window::move ( unsigned int  a_x,
unsigned int  a_y 
)
inline

Definition at line 128 of file window.

128  {
129  if(!m_hwnd) return;
130  RECT rect;
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);
135  }

◆ operator=()

window& tools::Windows::window::operator= ( const window a_from)
inlineprotected

Definition at line 100 of file window.

100  {
101  m_key_shift = a_from.m_key_shift;
102  m_key_ctrl = a_from.m_key_ctrl;
103  return *this;
104  }

◆ proc()

static LRESULT CALLBACK tools::Windows::window::proc ( HWND  a_hwnd,
UINT  a_msg,
WPARAM  a_wparam,
LPARAM  a_lparam 
)
inlinestaticprotected

Definition at line 140 of file window.

140  {
141  switch (a_msg) {
142  // Else :
143  case WM_SIZE:{ // Assume one child window ! FIXME : have a message if not.
144  int width = LOWORD(a_lparam);
145  int height = HIWORD(a_lparam);
146  HWND hwnd = GetFirstChild(a_hwnd);
147  if(hwnd) {
148  ::MoveWindow(hwnd,0,0,width,height,TRUE);
149  }
150  }return 0;
151 
152  case WM_SETFOCUS:{
153  window* _this = (window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
154  if(_this) {
155  HWND hwnd = _this->focus_hwnd();
156  if(hwnd) ::SetFocus(hwnd);
157  }
158  }return 0;
159 
160  case WM_KEYDOWN:{
161  switch(a_wparam){
162  case VK_SHIFT:{
163  window* _this = (window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
164  if(_this) _this->m_key_shift = true;
165  return 0;
166  }
167  case VK_CONTROL:{
168  window* _this = (window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
169  if(_this) _this->m_key_ctrl = true;
170  return 0;
171  }
172  case VK_UP:{
173  window* _this = (window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
174  if(_this) _this->key_up();
175  return 0;
176  }
177  case VK_DOWN:{
178  window* _this = (window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
179  if(_this) _this->key_down();
180  return 0;
181  }
182  case VK_LEFT:{
183  window* _this = (window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
184  if(_this) _this->key_left();
185  return 0;
186  }
187  case VK_RIGHT:{
188  window* _this = (window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
189  if(_this) _this->key_right();
190  return 0;
191  }
192  case VK_ESCAPE:{
193  window* _this = (window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
194  if(_this) _this->key_escape();
195  return 0;
196  }
197  } //end switch(a_wparam)
198  break;
199  }
200  case WM_KEYUP:{
201  switch(a_wparam){
202  case VK_SHIFT:{
203  window* _this = (window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
204  if(_this) _this->m_key_shift = false;
205  return 0;
206  }
207  case VK_CONTROL:{
208  window* _this = (window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
209  if(_this) _this->m_key_ctrl = false;
210  return 0;
211  }
212  } //end switch(a_wparam)
213  break;
214  }
215 
216  case WM_CLOSE:{
217  window* _this = (window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
218  if(_this) _this->close();
219  }break; //NOTE : can't be return 0.
220  case WM_DESTROY:wm__destroy(a_hwnd);return 0;
221  }
222  return (DefWindowProc(a_hwnd,a_msg,a_wparam,a_lparam));
223  }

◆ set_client_area_size()

void tools::Windows::window::set_client_area_size ( unsigned int  a_w,
unsigned int  a_h 
)
inline

Definition at line 111 of file window.

111  {
112  if(!m_hwnd) return;
113  RECT wrect;
114  ::GetWindowRect(m_hwnd,&wrect);
115  unsigned int ww = wrect.right-wrect.left;
116  unsigned int wh = wrect.bottom-wrect.top;
117 
118  RECT carect;
119  ::GetClientRect(m_hwnd,&carect);
120  unsigned int cw = carect.right-carect.left;
121  unsigned int ch = carect.bottom-carect.top;
122 
123  unsigned int woffset = ww-cw;
124  unsigned int hoffset = wh-ch;
125 
126  ::MoveWindow(m_hwnd,wrect.left,wrect.top,a_w+woffset,a_h+hoffset,TRUE);
127  }

◆ set_focus_hwnd()

void tools::Windows::window::set_focus_hwnd ( HWND  a_hwnd)
inline

Definition at line 137 of file window.

137 {m_focus_hwnd = a_hwnd;}

◆ wm__destroy()

static void tools::Windows::window::wm__destroy ( HWND  a_hwnd)
inlinestaticprotected

Definition at line 224 of file window.

224  {
225  window* _this = (window*)::GetWindowLongPtr(a_hwnd,GWLP_USERDATA);
226  if(_this) { //How to be sure that we have a window* ???
227  if(_this->m_hwnd!=a_hwnd) {
228  //::printf("WinTk::Component::wm_destroy : HWND mismatch !\n");
229  }
230  _this->m_hwnd = 0;
231  }
232  ::SetWindowLongPtr(a_hwnd,GWLP_USERDATA,LONG_PTR(NULL));
233  }

Member Data Documentation

◆ m_focus_hwnd

HWND tools::Windows::window::m_focus_hwnd
protected

Definition at line 245 of file window.

◆ m_hwnd

HWND tools::Windows::window::m_hwnd
protected

Definition at line 242 of file window.

◆ m_key_ctrl

bool tools::Windows::window::m_key_ctrl
protected

Definition at line 244 of file window.

◆ m_key_shift

bool tools::Windows::window::m_key_shift
protected

Definition at line 243 of file window.


The documentation for this class was generated from the following file:
tools::Windows::window::wm__destroy
static void wm__destroy(HWND a_hwnd)
Definition: window:224
tools::Windows::window::m_focus_hwnd
HWND m_focus_hwnd
Definition: window:245
tools::Windows::window::hwnd
HWND hwnd() const
Definition: window:109
tools::Windows::window::m_key_ctrl
bool m_key_ctrl
Definition: window:244
tools::Windows::window::m_hwnd
HWND m_hwnd
Definition: window:242
tools::Windows::window::window
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)
Definition: window:48
tools::Windows::window::m_key_shift
bool m_key_shift
Definition: window:243