Mercurial > foo_out_sdl
comparison foosdk/sdk/foobar2000/helpers/win32_dialog.cpp @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #include "StdAfx.h" | |
| 2 | |
| 3 #ifdef FOOBAR2000_DESKTOP_WINDOWS | |
| 4 | |
| 5 #include "win32_misc.h" | |
| 6 #include "win32_dialog.h" | |
| 7 | |
| 8 namespace dialog_helper { | |
| 9 | |
| 10 | |
| 11 INT_PTR CALLBACK dialog::DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp) | |
| 12 { | |
| 13 dialog * p_this; | |
| 14 BOOL rv; | |
| 15 if (msg==WM_INITDIALOG) | |
| 16 { | |
| 17 p_this = reinterpret_cast<dialog*>(lp); | |
| 18 p_this->wnd = wnd; | |
| 19 SetWindowLongPtr(wnd,DWLP_USER,lp); | |
| 20 | |
| 21 if (p_this->m_is_modal) p_this->m_modal_scope.initialize(wnd); | |
| 22 } | |
| 23 else p_this = reinterpret_cast<dialog*>(GetWindowLongPtr(wnd,DWLP_USER)); | |
| 24 | |
| 25 rv = p_this ? p_this->on_message(msg,wp,lp) : FALSE; | |
| 26 | |
| 27 if (msg==WM_DESTROY && p_this) | |
| 28 { | |
| 29 SetWindowLongPtr(wnd,DWLP_USER,0); | |
| 30 // p_this->wnd = 0; | |
| 31 } | |
| 32 | |
| 33 return rv; | |
| 34 } | |
| 35 | |
| 36 | |
| 37 int dialog::run_modal(unsigned id,HWND parent) | |
| 38 { | |
| 39 assert(wnd == 0); | |
| 40 if (wnd != 0) return -1; | |
| 41 m_is_modal = true; | |
| 42 return uDialogBox(id,parent,DlgProc,reinterpret_cast<LPARAM>(this)); | |
| 43 } | |
| 44 HWND dialog::run_modeless(unsigned id,HWND parent) | |
| 45 { | |
| 46 assert(wnd == 0); | |
| 47 if (wnd != 0) return 0; | |
| 48 m_is_modal = false; | |
| 49 return uCreateDialog(id,parent,DlgProc,reinterpret_cast<LPARAM>(this)); | |
| 50 } | |
| 51 | |
| 52 void dialog::end_dialog(int code) | |
| 53 { | |
| 54 assert(m_is_modal); | |
| 55 if (m_is_modal) uEndDialog(wnd,code); | |
| 56 } | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 int dialog_modal::run(unsigned p_id,HWND p_parent,HINSTANCE p_instance) | |
| 68 { | |
| 69 int status; | |
| 70 | |
| 71 // note: uDialogBox() has its own modal scope, we don't want that to trigger | |
| 72 // if this is ever changed, move deinit to WM_DESTROY handler in DlgProc | |
| 73 | |
| 74 status = (int)DialogBoxParam(p_instance,MAKEINTRESOURCE(p_id),p_parent,DlgProc,reinterpret_cast<LPARAM>(this)); | |
| 75 | |
| 76 m_modal_scope.deinitialize(); | |
| 77 | |
| 78 return status; | |
| 79 } | |
| 80 | |
| 81 void dialog_modal::end_dialog(int p_code) | |
| 82 { | |
| 83 EndDialog(m_wnd,p_code); | |
| 84 } | |
| 85 | |
| 86 | |
| 87 INT_PTR CALLBACK dialog_modal::DlgProc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp) | |
| 88 { | |
| 89 dialog_modal * _this; | |
| 90 if (msg==WM_INITDIALOG) | |
| 91 { | |
| 92 _this = reinterpret_cast<dialog_modal*>(lp); | |
| 93 _this->m_wnd = wnd; | |
| 94 SetWindowLongPtr(wnd,DWLP_USER,lp); | |
| 95 | |
| 96 _this->m_modal_scope.initialize(wnd); | |
| 97 } | |
| 98 else _this = reinterpret_cast<dialog_modal*>(GetWindowLongPtr(wnd,DWLP_USER)); | |
| 99 | |
| 100 assert(_this == 0 || _this->m_wnd == wnd); | |
| 101 | |
| 102 return _this ? _this->on_message(msg,wp,lp) : FALSE; | |
| 103 } | |
| 104 | |
| 105 } | |
| 106 | |
| 107 HWND uCreateDialog(UINT id,HWND parent,DLGPROC proc,LPARAM param) | |
| 108 { | |
| 109 return CreateDialogParam(core_api::get_my_instance(),MAKEINTRESOURCE(id),parent,proc,param); | |
| 110 } | |
| 111 | |
| 112 int uDialogBox(UINT id,HWND parent,DLGPROC proc,LPARAM param) | |
| 113 { | |
| 114 return (int)DialogBoxParam(core_api::get_my_instance(),MAKEINTRESOURCE(id),parent,proc,param); | |
| 115 } | |
| 116 | |
| 117 #endif // FOOBAR2000_DESKTOP_WINDOWS |
