[vlc-commits] Win32: add helper window base class (common/win32_vlcwnd).
Sergey Radionov
git at videolan.org
Fri Jan 13 12:01:04 CET 2012
npapi-vlc | branch: master | Sergey Radionov <RSATom at gmail.com> | Sun Jan 8 19:25:44 2012 +0700| [3be390d67ac0e982ffd6275f88e9eb8f0434074c] | committer: Jean-Baptiste Kempf
Win32: add helper window base class (common/win32_vlcwnd).
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/npapi-vlc.git/?a=commit;h=3be390d67ac0e982ffd6275f88e9eb8f0434074c
---
activex/Makefile.am | 2 +
common/win32_vlcwnd.cpp | 111 +++++++++++++++++++++++++++++++++++++++++++++++
common/win32_vlcwnd.h | 61 ++++++++++++++++++++++++++
npapi/Makefile.am | 4 +-
4 files changed, 177 insertions(+), 1 deletions(-)
diff --git a/activex/Makefile.am b/activex/Makefile.am
index 9e9e7d6..ea876ac 100644
--- a/activex/Makefile.am
+++ b/activex/Makefile.am
@@ -74,6 +74,8 @@ axvlc_la_SOURCES = \
axvlc_idl.h \
../common/win32_fullscreen.cpp \
../common/win32_fullscreen.h \
+ ../common/win32_vlcwnd.cpp \
+ ../common/win32_vlcwnd.h \
$(NULL)
axvlc_la_DEPENDENCIES = $(srcdir)/axvlc.def $(DATA_axvlc_rc)
diff --git a/common/win32_vlcwnd.cpp b/common/win32_vlcwnd.cpp
new file mode 100644
index 0000000..ec004dd
--- /dev/null
+++ b/common/win32_vlcwnd.cpp
@@ -0,0 +1,111 @@
+/*****************************************************************************
+ * Copyright © 2002-2011 VideoLAN and VLC authors
+ * $Id$
+ *
+ * Authors: Sergey Radionov <rsatom at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "win32_vlcwnd.h"
+
+LRESULT CALLBACK VLCWnd::_WindowProc(HWND hWnd, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ LONG_PTR ud = GetWindowLongPtr(hWnd, GWLP_USERDATA);
+ VLCWnd* wnd = reinterpret_cast<VLCWnd*>(ud);
+
+ if( !wnd && WM_CREATE != uMsg )
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+
+ switch( uMsg )
+ {
+ case WM_CREATE:{
+ CREATESTRUCT* cs = (CREATESTRUCT*)(lParam);
+ wnd = reinterpret_cast<VLCWnd*>(cs->lpCreateParams);
+ wnd->_hWnd = hWnd;
+ SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)wnd);
+ return wnd->WindowProc(uMsg, wParam, lParam);
+ }
+ case WM_NCDESTROY:{
+ LRESULT r = wnd->WindowProc(uMsg, wParam, lParam);
+ wnd->_hWnd = 0;
+ return r;
+ }
+ default:{
+ return wnd->WindowProc(uMsg, wParam, lParam);
+ }
+ }
+}
+
+bool VLCWnd::RegisterClass(WNDCLASS* wc)
+{
+ memset(wc, 0, sizeof(WNDCLASS));
+
+ wc->style = CS_DBLCLKS;
+ wc->hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc->lpfnWndProc = _WindowProc;
+ wc->hInstance = _hInstance;
+
+ PreRegisterWindowClass(wc);
+
+ if( !wc->lpszClassName )
+ return false;
+
+ if( GetClassInfo(_hInstance, wc->lpszClassName, wc) ) {
+ return true;
+ } else {
+ _wndclass_atom = ::RegisterClass(wc);
+ return _wndclass_atom != 0;
+ }
+}
+
+bool VLCWnd::Create(LPCTSTR lpWindowName, DWORD dwStyle,
+ int x, int y, int nWidth, int nHeight,
+ HWND hWndParent, HMENU hMenu)
+{
+ return CreateEx(0, lpWindowName, dwStyle,
+ x, y, nWidth, nHeight,
+ hWndParent, hMenu);
+}
+
+bool VLCWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpWindowName, DWORD dwStyle,
+ int x, int y, int nWidth, int nHeight,
+ HWND hWndParent, HMENU hMenu)
+{
+ if(_hWnd)
+ return false;
+
+ WNDCLASS wc;
+ if( !RegisterClass(&wc) )
+ return false;
+
+ ::CreateWindowEx(dwExStyle, wc.lpszClassName, lpWindowName, dwStyle,
+ x, y, nWidth, nHeight,
+ hWndParent, hMenu, _hInstance, (LPVOID)this);
+
+ return _hWnd != 0;
+}
+
+VLCWnd::~VLCWnd()
+{
+ if( _hWnd )
+ DestroyWindow( _hWnd );
+
+ if( 0 != _wndclass_atom ) {
+ if( UnregisterClass(MAKEINTATOM(_wndclass_atom), _hInstance) )
+ _wndclass_atom = 0;
+ }
+}
diff --git a/common/win32_vlcwnd.h b/common/win32_vlcwnd.h
new file mode 100644
index 0000000..247abe1
--- /dev/null
+++ b/common/win32_vlcwnd.h
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ * Copyright © 2002-2011 VideoLAN and VLC authors
+ * $Id$
+ *
+ * Authors: Sergey Radionov <rsatom at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef _WIN32_VLCWND_H_
+#define _WIN32_VLCWND_H_
+
+#include <windows.h>
+
+class VLCWnd
+{
+protected:
+ VLCWnd(HINSTANCE hInstance)
+ : _hInstance(hInstance), _wndclass_atom(0), _hWnd(0){};
+ virtual ~VLCWnd();
+
+ bool Create(LPCTSTR lpWindowName, DWORD dwStyle,
+ int x, int y, int nWidth, int nHeight,
+ HWND hWndParent, HMENU hMenu);
+ bool CreateEx(DWORD dwExStyle, LPCTSTR lpWindowName, DWORD dwStyle,
+ int x, int y, int nWidth, int nHeight,
+ HWND hWndParent, HMENU hMenu);
+
+ virtual void PreRegisterWindowClass(WNDCLASS* wc) {};
+ virtual LRESULT WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
+ { return DefWindowProc(_hWnd, uMsg, wParam, lParam); };
+
+ HINSTANCE hInstance() const
+ { return _hInstance;}
+
+public:
+ HWND hWnd() const {return _hWnd;}
+
+private:
+ bool RegisterClass(WNDCLASS* wc);
+
+private:
+ static LRESULT CALLBACK _WindowProc(HWND hWnd, UINT uMsg, WPARAM, LPARAM);
+ HINSTANCE _hInstance;
+ ATOM _wndclass_atom;
+ HWND _hWnd;
+};
+
+#endif //_WIN32_VLCWND_H_
diff --git a/npapi/Makefile.am b/npapi/Makefile.am
index b78d674..03ae2d1 100644
--- a/npapi/Makefile.am
+++ b/npapi/Makefile.am
@@ -77,7 +77,9 @@ SOURCES_support = \
vlcplugin_win.cpp \
vlcplugin_win.h \
../common/win32_fullscreen.cpp \
- ../common/win32_fullscreen.h
+ ../common/win32_fullscreen.h \
+ ../common/win32_vlcwnd.cpp \
+ ../common/win32_vlcwnd.h
npvlc_la_DEPENDENCIES += $(DATA_npvlc_rc)
npvlc_la_LDFLAGS += -Wl,--kill-at -Wl,$(DATA_npvlc_rc)
More information about the vlc-commits
mailing list