wxUICanceller: Move upstream and make reusable
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
@@ -463,6 +463,30 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// Closes active window if exists
|
||||
///
|
||||
class wxUICanceller
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Send WM_CLOSE to the active window if it exists.
|
||||
///
|
||||
/// \param[inout] hWndCurrent Reference to a handle of the active window is stored. The variable should be shared between threads.
|
||||
/// \param[in] hWnd Handle of a new window to be activated
|
||||
///
|
||||
wxUICanceller(_Inout_ HWND volatile &hWndCurrent, _In_ HWND hWnd);
|
||||
|
||||
///
|
||||
/// Clears the active window handle.
|
||||
///
|
||||
~wxUICanceller();
|
||||
|
||||
protected:
|
||||
HWND volatile &m_hWndCurrent;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// EAP general note
|
||||
///
|
||||
|
@@ -600,3 +600,24 @@ wxInitializerPeer::~wxInitializerPeer()
|
||||
wxCriticalSection wxInitializerPeer::s_lock;
|
||||
unsigned long wxInitializerPeer::s_init_ref_count = 0;
|
||||
wxLocale *wxInitializerPeer::s_locale = NULL;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// wxUICanceller
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
wxUICanceller::wxUICanceller(_Inout_ HWND volatile &hWndCurrent, _In_ HWND hWnd) :
|
||||
m_hWndCurrent(hWndCurrent)
|
||||
{
|
||||
HWND hWndPrev = (HWND)InterlockedCompareExchangePointer((PVOID volatile *)&m_hWndCurrent, hWnd, NULL);
|
||||
if (hWndPrev) {
|
||||
PostMessage(hWndPrev, WM_CLOSE, 0, 0);
|
||||
throw winstd::win_runtime_error(ERROR_CANCELLED, __FUNCTION__ " Aborted.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
wxUICanceller::~wxUICanceller()
|
||||
{
|
||||
InterlockedExchangePointer((PVOID volatile *)&m_hWndCurrent, NULL);
|
||||
}
|
||||
|
Reference in New Issue
Block a user