summaryrefslogtreecommitdiff
path: root/src/window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp54
1 files changed, 52 insertions, 2 deletions
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 <sstream>
+
#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;
}
@@ -59,6 +80,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;