summaryrefslogtreecommitdiff
path: root/src/window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/window.cpp b/src/window.cpp
new file mode 100644
index 0000000..c34c5ca
--- /dev/null
+++ b/src/window.cpp
@@ -0,0 +1,140 @@
+// w32dlib - Win32 Window Helpers
+//
+// Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk)
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// -------------------------------------------------------------------------
+//
+#include "w32dlib/window.h"
+
+namespace W32DLib
+{
+// ------------------------------------------------------------
+//
+Window::ProcSet Window::m_procset;
+
+
+// ------------------------------------------------------------
+//
+Window::Window() : m_wnd(0)
+{
+}
+
+
+// ------------------------------------------------------------
+//
+Window::~Window()
+{
+}
+
+
+// ------------------------------------------------------------
+//
+HWND Window::GetHWND()
+{
+ return m_wnd;
+}
+
+
+// ------------------------------------------------------------
+//
+void Window::SetText(const char *text)
+{
+ ::SendMessage(m_wnd,WM_SETTEXT,0,reinterpret_cast<LPARAM>(text));
+}
+
+
+// ------------------------------------------------------------
+//
+std::string Window::GetText(int maxlen)
+{
+ char *buff=new char[maxlen+1];
+ std::string res;
+
+ buff[0]=0;
+
+ ::SendMessage(m_wnd,WM_GETTEXT,maxlen,reinterpret_cast<LPARAM>(buff));
+
+ res=buff;
+ delete[] buff;
+
+ return res;
+}
+
+
+// ------------------------------------------------------------
+//
+void Window::Enable(bool enable)
+{
+ ::EnableWindow(m_wnd,enable);
+}
+
+
+// ------------------------------------------------------------
+//
+
+BOOL Window::InstanceProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
+{
+ bool ret=FALSE;
+
+ switch(msg)
+ {
+ case WM_INITDIALOG:
+ case WM_CREATE:
+ m_wnd=wnd;
+ m_procset[wnd]=this;
+
+ ret=TRUE;
+ break;
+
+ case WM_DESTROY:
+ m_procset.erase(wnd);
+ break;
+
+ default:
+ break;
+ }
+
+ return ret;
+}
+
+// ------------------------------------------------------------
+//
+
+BOOL CALLBACK Window::WindowProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
+{
+ if (msg==WM_INITDIALOG || msg==WM_CREATE)
+ {
+ Window *window=reinterpret_cast<Window*>(lp);
+ return window->InstanceProc(wnd,msg,wp,lp);
+ }
+ else
+ {
+ if (m_procset.count(wnd))
+ {
+ return m_procset[wnd]->InstanceProc(wnd,msg,wp,lp);
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+}
+
+
+}; // namespace w32dlib
+
+// END OF FILE