From 3a1bf865b6c1b6b7c096eaf6dab91a465319488a Mon Sep 17 00:00:00 2001 From: Ian C Date: Mon, 4 Apr 2005 00:52:23 +0000 Subject: Added DataX --- src/window.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'src/window.cpp') diff --git a/src/window.cpp b/src/window.cpp index 5ab893e..1646d70 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -18,10 +18,14 @@ // // ------------------------------------------------------------------------- // +#include + #include "w32dlib/window.h" + namespace W32DLib { + // ------------------------------------------------------------ // Window::ProcSet Window::m_procset; @@ -31,6 +35,11 @@ Window::ProcSet Window::m_procset; // Window::Window() : m_wnd(0) { + std::ostringstream name; + + name << "W32DLIB_MUTEX_" << GetCurrentProcessId(); + + m_mutex=CreateMutex(NULL,FALSE,name.str().c_str()); } @@ -38,6 +47,18 @@ Window::Window() : m_wnd(0) // Window::~Window() { + if (m_mutex!=NULL) + { + CloseHandle(m_mutex); + } +} + + +// ------------------------------------------------------------ +// +bool Window::HasMutex() +{ + return m_mutex!=NULL; } @@ -57,6 +78,14 @@ HMENU Window::GetHMENU() } +// ------------------------------------------------------------ +// +bool Window::SetHMENU(HMENU menu) +{ + return SetMenu(m_wnd,menu) ? true:false; +} + + // ------------------------------------------------------------ // LRESULT Window::SendMsg(UINT msg, WPARAM wp, LPARAM lp) @@ -105,7 +134,7 @@ std::string Window::GetText() // void Window::Enable(bool enable) { - ::EnableWindow(m_wnd,enable); + EnableWindow(m_wnd,enable); } @@ -114,6 +143,7 @@ void Window::Enable(bool enable) BOOL Window::InstanceProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp) { + DWORD res=WAIT_OBJECT_0; bool ret=FALSE; switch(msg) @@ -121,7 +151,27 @@ BOOL Window::InstanceProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp) case WM_INITDIALOG: case WM_CREATE: m_wnd=wnd; - m_procset[wnd]=this; + + if (m_mutex) + { + res=WaitForSingleObject(m_mutex,INFINITE); + } + + if (res==WAIT_OBJECT_0) + { + try + { + m_procset[wnd]=this; + } + catch (...) + { + } + + if (m_mutex) + { + ReleaseMutex(m_mutex); + } + } ret=TRUE; break; -- cgit v1.2.3