foobar2000 SDK  2015-08-03
message_loop.h
Go to the documentation of this file.
1 class NOVTABLE message_filter
2 {
3 public:
4  virtual bool pretranslate_message(MSG * p_msg) = 0;
5 };
6 
7 class NOVTABLE idle_handler {
8 public:
9  virtual bool on_idle() = 0;
10 };
11 
12 class NOVTABLE message_loop : public service_base
13 {
14 public:
15  virtual void add_message_filter(message_filter * ptr) = 0;
16  virtual void remove_message_filter(message_filter * ptr) = 0;
17 
18  virtual void add_idle_handler(idle_handler * ptr) = 0;
19  virtual void remove_idle_handler(idle_handler * ptr) = 0;
20 
21  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(message_loop);
22 };
23 
24 class NOVTABLE message_loop_v2 : public message_loop {
25 public:
26  virtual void add_message_filter_ex(message_filter * ptr, t_uint32 lowest, t_uint32 highest) = 0;
27 
28  FB2K_MAKE_SERVICE_INTERFACE(message_loop_v2, message_loop);
29 };
30 
32 public:
36  message_loop_v2::ptr apiV2;
37  if (api->service_query_t(apiV2)) {
38  apiV2->add_message_filter_ex(this, lowest, highest);
39  } else {
40  api->add_message_filter(this);
41  }
42  }
43  ~message_filter_impl_base() {static_api_ptr_t<message_loop>()->remove_message_filter(this);}
44  bool pretranslate_message(MSG * p_msg) {return false;}
45 
46  PFC_CLASS_NOT_COPYABLE(message_filter_impl_base,message_filter_impl_base);
47 };
48 
50 protected:
51  bool pretranslate_message(MSG * p_msg) {
52  if (m_wnd != NULL) {
53  if (GetActiveWindow() == m_wnd) {
54  if (TranslateAccelerator(m_wnd,m_accel.get(),p_msg) != 0) {
55  return true;
56  }
57  }
58  }
59  return false;
60  }
61 public:
62  message_filter_impl_accel(HINSTANCE p_instance,const TCHAR * p_accel) : m_wnd(NULL) {
63  m_accel.load(p_instance,p_accel);
64  }
65  void set_wnd(HWND p_wnd) {m_wnd = p_wnd;}
66 private:
67  HWND m_wnd;
69 
71 };
72 
74 public:
75  bool pretranslate_message(MSG * p_msg) {
76  if (IsOurMsg(p_msg) && m_wnd != NULL && GetActiveWindow() == m_wnd) {
77  ::PostMessage(m_wnd, WM_SYSCOMMAND, SC_CONTEXTHELP, -1);
78  return true;
79  }
80  return false;
81  }
82  void set_wnd(HWND wnd) {m_wnd = wnd;}
83 private:
84  static bool IsOurMsg(const MSG * msg) {
85  return msg->message == WM_KEYDOWN && msg->wParam == VK_F1;
86  }
87  HWND m_wnd;
88 };
89 
91 public:
93  ~idle_handler_impl_base() {static_api_ptr_t<message_loop>()->remove_idle_handler(this);}
94  bool on_idle() {return true;}
95 
96  PFC_CLASS_NOT_COPYABLE_EX(idle_handler_impl_base)
97 };
bool pretranslate_message(MSG *p_msg)
Definition: message_loop.h:51
message_filter_impl_accel(HINSTANCE p_instance, const TCHAR *p_accel)
Definition: message_loop.h:62
static bool IsOurMsg(const MSG *msg)
Definition: message_loop.h:84
void set_wnd(HWND p_wnd)
Definition: message_loop.h:65
win32_accelerator m_accel
Definition: message_loop.h:68
bool pretranslate_message(MSG *p_msg)
Definition: message_loop.h:75
Base class for all service classes. Provides interfaces for reference counter and querying for differ...
Definition: service.h:333
void set_wnd(HWND wnd)
Definition: message_loop.h:82
bool pretranslate_message(MSG *p_msg)
Definition: message_loop.h:44
message_filter_impl_base(t_uint32 lowest, t_uint32 highest)
Definition: message_loop.h:34
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
uint32_t t_uint32
Definition: int_types.h:5