00001 #ifndef _FOOBAR2000_HELPERS_WIN32_DIALOG_H_
00002 #define _FOOBAR2000_HELPERS_WIN32_DIALOG_H_
00003
00004
00005 namespace dialog_helper
00006 {
00007 class dialog
00008 {
00009 protected:
00010
00011 dialog() : wnd(0), m_is_modal(false) {}
00012 ~dialog() { }
00013
00014 virtual BOOL on_message(UINT msg,WPARAM wp,LPARAM lp)=0;
00015
00016 void end_dialog(int code);
00017
00018 public:
00019 inline HWND get_wnd() {return wnd;}
00020
00021 int run_modal(unsigned id,HWND parent);
00022
00023 HWND run_modeless(unsigned id,HWND parent);
00024 private:
00025 HWND wnd;
00026 static INT_PTR CALLBACK DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp);
00027
00028 bool m_is_modal;
00029
00030 modal_dialog_scope m_modal_scope;
00031 };
00032
00033
00035 class dialog_modal
00036 {
00037 public:
00038 int run(unsigned p_id,HWND p_parent,HINSTANCE p_instance = core_api::get_my_instance());
00039 protected:
00040 virtual BOOL on_message(UINT msg,WPARAM wp,LPARAM lp)=0;
00041
00042 inline dialog_modal() : m_wnd(0) {}
00043 void end_dialog(int p_code);
00044 inline HWND get_wnd() const {return m_wnd;}
00045 private:
00046 static INT_PTR CALLBACK DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp);
00047
00048 HWND m_wnd;
00049 modal_dialog_scope m_modal_scope;
00050 };
00051
00052
00055
00067 class dialog_modeless
00068 {
00069 public:
00072 bool create(unsigned p_id,HWND p_parent,HINSTANCE p_instance = core_api::get_my_instance());
00073 protected:
00075 virtual BOOL on_message(UINT msg,WPARAM wp,LPARAM lp)=0;
00076
00077 inline dialog_modeless() : m_wnd(0), m_destructor_status(destructor_none), m_is_in_create(false) {}
00078 inline HWND get_wnd() const {return m_wnd;}
00079 virtual ~dialog_modeless();
00080 private:
00081 static INT_PTR CALLBACK DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp);
00082 void on_window_destruction();
00083
00084 BOOL on_message_wrap(UINT msg,WPARAM wp,LPARAM lp);
00085
00086 HWND m_wnd;
00087 enum {destructor_none,destructor_normal,destructor_fromwindow} m_destructor_status;
00088 bool m_is_in_create;
00089 };
00090
00091 #pragma deprecated(dialog_modeless)
00092
00093
00094
00095 class dialog_modeless_v2
00096 {
00097 protected:
00098 explicit dialog_modeless_v2(unsigned p_id,HWND p_parent,HINSTANCE p_instance = core_api::get_my_instance(),bool p_stealfocus = true);
00099 virtual ~dialog_modeless_v2();
00100 HWND get_wnd() const {return m_wnd;}
00101 virtual BOOL on_message(UINT msg,WPARAM wp,LPARAM lp) {return FALSE;}
00102
00103 static dialog_modeless_v2 * __unsafe__instance_from_window(HWND p_wnd) {return reinterpret_cast<dialog_modeless_v2*>(GetWindowLongPtr(p_wnd,DWLP_USER));}
00104 private:
00105 static INT_PTR CALLBACK DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp);
00106 void detach_window();
00107 BOOL on_message_internal(UINT msg,WPARAM wp,LPARAM lp);
00108 enum {status_construction, status_lifetime, status_destruction_requested, status_destruction} m_status;
00109 HWND m_wnd;
00110 const bool m_stealfocus;
00111
00112 const dialog_modeless_v2 & operator=(const dialog_modeless_v2 &);
00113 dialog_modeless_v2(const dialog_modeless_v2 &);
00114 };
00115
00116
00117 };
00118
00119
00120
00121 #endif