00001 #ifndef _FOOBAR2000_HELPERS_WIN32_DIALOG_H_
00002 #define _FOOBAR2000_HELPERS_WIN32_DIALOG_H_
00003
00004
00005 namespace dialog_helper
00006 {
00007
00008 class dialog
00009 {
00010 protected:
00011
00012 dialog() : wnd(0), m_is_modal(false) {}
00013 ~dialog() { }
00014
00015 virtual BOOL on_message(UINT msg,WPARAM wp,LPARAM lp)=0;
00016
00017 void end_dialog(int code);
00018
00019 public:
00020 inline HWND get_wnd() {return wnd;}
00021
00022 __declspec(deprecated) int run_modal(unsigned id,HWND parent);
00023
00024 __declspec(deprecated) HWND run_modeless(unsigned id,HWND parent);
00025 private:
00026 HWND wnd;
00027 static INT_PTR CALLBACK DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp);
00028
00029 bool m_is_modal;
00030
00031 modal_dialog_scope m_modal_scope;
00032 };
00033
00035 class dialog_modal
00036 {
00037 public:
00038 __declspec(deprecated) 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
00054
00066 class dialog_modeless
00067 {
00068 public:
00071 __declspec(deprecated) bool create(unsigned p_id,HWND p_parent,HINSTANCE p_instance = core_api::get_my_instance());
00072 protected:
00074 virtual BOOL on_message(UINT msg,WPARAM wp,LPARAM lp)=0;
00075
00076 inline dialog_modeless() : m_wnd(0), m_destructor_status(destructor_none), m_is_in_create(false) {}
00077 inline HWND get_wnd() const {return m_wnd;}
00078 virtual ~dialog_modeless();
00079 private:
00080 static INT_PTR CALLBACK DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp);
00081 void on_window_destruction();
00082
00083 BOOL on_message_wrap(UINT msg,WPARAM wp,LPARAM lp);
00084
00085 HWND m_wnd;
00086 enum {destructor_none,destructor_normal,destructor_fromwindow} m_destructor_status;
00087 bool m_is_in_create;
00088 };
00089
00090
00091 class dialog_modeless_v2
00092 {
00093 protected:
00094 __declspec(deprecated) explicit dialog_modeless_v2(unsigned p_id,HWND p_parent,HINSTANCE p_instance = core_api::get_my_instance(),bool p_stealfocus = true);
00095 virtual ~dialog_modeless_v2();
00096 HWND get_wnd() const {return m_wnd;}
00097 virtual BOOL on_message(UINT msg,WPARAM wp,LPARAM lp) {return FALSE;}
00098
00099 static dialog_modeless_v2 * __unsafe__instance_from_window(HWND p_wnd) {return reinterpret_cast<dialog_modeless_v2*>(GetWindowLongPtr(p_wnd,DWLP_USER));}
00100 private:
00101 static INT_PTR CALLBACK DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp);
00102 void detach_window();
00103 BOOL on_message_internal(UINT msg,WPARAM wp,LPARAM lp);
00104 enum {status_construction, status_lifetime, status_destruction_requested, status_destruction} m_status;
00105 HWND m_wnd;
00106 const bool m_stealfocus;
00107
00108 const dialog_modeless_v2 & operator=(const dialog_modeless_v2 &);
00109 dialog_modeless_v2(const dialog_modeless_v2 &);
00110 };
00111
00112 };
00113
00114
00115 class CModelessDialogEntry {
00116 public:
00117 inline CModelessDialogEntry() : m_wnd() {}
00118 inline CModelessDialogEntry(HWND p_wnd) : m_wnd() {Set(p_wnd);}
00119 inline ~CModelessDialogEntry() {Set(NULL);}
00120
00121 void Set(HWND p_new) {
00122 static_api_ptr_t<modeless_dialog_manager> api;
00123 if (m_wnd) api->remove(m_wnd);
00124 m_wnd = p_new;
00125 if (m_wnd) api->add(m_wnd);
00126 }
00127 private:
00128 PFC_CLASS_NOT_COPYABLE_EX(CModelessDialogEntry);
00129 HWND m_wnd;
00130 };
00131
00132 #endif