# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlMFC/MDIWindow.cpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.org                                               */
    00005 /*                                                                                    */
    00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
    00007 /*  All rights reserved.                                                              */
    00008 /*                                                                                    */
    00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
    00010 /*  are permitted provided that the following conditions are met:                     */
    00011 /*                                                                                    */
    00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
    00013 /*  list of conditions and the following disclaimer.                                  */
    00014 /*                                                                                    */
    00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
    00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
    00017 /*  other materials provided with the distribution.                                   */
    00018 /*                                                                                    */
    00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
    00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
    00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
    00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
    00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
    00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
    00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
    00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
    00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
    00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
    00029 /*                                                                                    */
    00030 /**************************************************************************************/
    00031
    00032 #include "StdAfx.h"
    00033
    00034 #include <vlMFC/MDIWindow.hpp>
    00035 #include <vlWin32/Win32Window.hpp>
    00036 #include <vlCore/Log.hpp>
    00037 #include <vlCore/Say.hpp>
    00038 #include <vlCore/Time.hpp>
    00039 #include <shellapi.h>
    00040
    00041 using namespace vl;
    00042 using namespace vlMFC;
    00043
    00044 //-----------------------------------------------------------------------------
    00045 BEGIN_MESSAGE_MAP(MDIWindow, CView)
    00046   ON_WM_CHAR()
    00047   ON_WM_CLOSE()
    00048   ON_WM_CREATE()
    00049   ON_WM_KEYDOWN()
    00050   ON_WM_KEYUP()
    00051   ON_WM_LBUTTONDBLCLK()
    00052   ON_WM_LBUTTONDOWN()
    00053   ON_WM_LBUTTONUP()
    00054   ON_WM_MBUTTONDBLCLK()
    00055   ON_WM_MBUTTONDOWN()
    00056   ON_WM_MBUTTONUP()
    00057   ON_WM_MOUSEMOVE()
    00058   ON_WM_MOUSEWHEEL()
    00059   ON_WM_PAINT()
    00060   ON_WM_RBUTTONDBLCLK()
    00061   ON_WM_RBUTTONDOWN()
    00062   ON_WM_RBUTTONUP()
    00063   ON_WM_SIZE()
    00064   ON_WM_TIMER()
    00065   ON_WM_DROPFILES()
    00066   ON_WM_DESTROY()
    00067 END_MESSAGE_MAP()
    00068 /*
    00069   WM_SYSKEYDOWN
    00070   WM_SYSKEYUP
    00071   WM_GETICON
    00072   WM_SETCURSOR
    00073   WM_SETICON
    00074   WM_CAPTURECHANGED
    00075   WM_MOUSEFIRST
    00076 */
    00077 BOOL MDIWindow::PreCreateWindow(CREATESTRUCT & cs)
    00078 {
    00079   cs.dwExStyle |= WS_EX_ACCEPTFILES;
    00080   cs.style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
    00081   return CView::PreCreateWindow(cs);
    00082 }
    00083 //-----------------------------------------------------------------------------
    00084 MDIWindow::~MDIWindow()
    00085 {
    00086   dispatchDestroyEvent();
    00087 }
    00088 //-----------------------------------------------------------------------------
    00089 void MDIWindow::destroyGLContext()
    00090 {
    00091   // wglMakeCurrent(NULL, NULL) not needed
    00092   if (hwnd())
    00093   {
    00094     if (mHGLRC)
    00095     {
    00096       if ( wglDeleteContext(mHGLRC) == FALSE )
    00097       {
    00098         MessageBox( L"OpenGL context creation failed.\n"
    00099          L"The handle either doesn't specify a valid context or the context is being used by another thread.", L" MDIWindow::destroyGLContext() error!", MB_OK);
    00100       }
    00101       mHGLRC = NULL;
    00102     }
    00103
    00104     if (mHDC)
    00105     {
    00106       DeleteDC(mHDC);
    00107       mHDC = NULL;
    00108     }
    00109   }
    00110 }
    00111 //-----------------------------------------------------------------------------
    00112 void MDIWindow::OnDestroy()
    00113 {
    00114   dispatchDestroyEvent();
    00115   destroyGLContext();
    00116 }
    00117 //-----------------------------------------------------------------------------
    00118 void MDIWindow::OnPaint()
    00119 {
    00120   if (hwnd() && hdc() && hglrc())
    00121     dispatchRunEvent();
    00122   ValidateRect(NULL);
    00123 }
    00124 //-----------------------------------------------------------------------------
    00125 /*void MDIWindow::OnDraw(CDC *pDC)
    00126 {
    00127 }*/
    00128 //-----------------------------------------------------------------------------
    00129 /*void MDIWindow::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
    00130 {
    00131   unsigned short unicode_out = 0;
    00132   vl::EKey       key_out     = Key_None;
    00133   vlWin32::translateKeyEvent(nChar, nFlags, unicode_out, key_out);
    00134   dispatchKeyPressEvent(unicode_out, key_out);
    00135 }*/
    00136 //-----------------------------------------------------------------------------
    00137 void MDIWindow::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
    00138 {
    00139   unsigned short unicode_out = 0;
    00140   vl::EKey       key_out     = Key_None;
    00141   vlWin32::translateKeyEvent(nChar, nFlags, unicode_out, key_out);
    00142   dispatchKeyPressEvent(unicode_out, key_out);
    00143 }
    00144 //-----------------------------------------------------------------------------
    00145 void MDIWindow::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
    00146 {
    00147   unsigned short unicode_out = 0;
    00148   vl::EKey       key_out     = Key_None;
    00149   vlWin32::translateKeyEvent(nChar, nFlags, unicode_out, key_out);
    00150   dispatchKeyReleaseEvent(unicode_out, key_out);
    00151 }
    00152 //-----------------------------------------------------------------------------
    00153 void MDIWindow::countAndCapture()
    00154 {
    00155   mMouseDownCount++;
    00156   if (mMouseDownCount == 1)
    00157     ::SetCapture(hwnd());
    00158 }
    00159 //-----------------------------------------------------------------------------
    00160 void MDIWindow::countAndRelease()
    00161 {
    00162   mMouseDownCount--;
    00163   if (mMouseDownCount <= 0)
    00164   {
    00165     ReleaseCapture();
    00166     mMouseDownCount = 0;
    00167   }
    00168 }
    00169 //-----------------------------------------------------------------------------
    00170 void MDIWindow::OnLButtonDblClk(UINT nFlags, CPoint point)
    00171 {
    00172   countAndCapture();
    00173   dispatchMouseDownEvent( LeftButton, point.x, point.y );
    00174 }
    00175 //-----------------------------------------------------------------------------
    00176 void MDIWindow::OnLButtonDown(UINT nFlags, CPoint point)
    00177 {
    00178   countAndCapture();
    00179   dispatchMouseDownEvent( LeftButton, point.x, point.y );
    00180 }
    00181 //-----------------------------------------------------------------------------
    00182 void MDIWindow::OnLButtonUp(UINT nFlags, CPoint point)
    00183 {
    00184   countAndRelease();
    00185   dispatchMouseUpEvent( LeftButton, point.x, point.y );
    00186 }
    00187 //-----------------------------------------------------------------------------
    00188 void MDIWindow::OnMButtonDblClk(UINT nFlags, CPoint point)
    00189 {
    00190   countAndCapture();
    00191   dispatchMouseDownEvent( MiddleButton, point.x, point.y );
    00192 }
    00193 //-----------------------------------------------------------------------------
    00194 void MDIWindow::OnMButtonDown(UINT nFlags, CPoint point)
    00195 {
    00196   countAndCapture();
    00197   dispatchMouseDownEvent( MiddleButton, point.x, point.y );
    00198 }
    00199 //-----------------------------------------------------------------------------
    00200 void MDIWindow::OnMButtonUp(UINT nFlags, CPoint point)
    00201 {
    00202   countAndRelease();
    00203   dispatchMouseUpEvent( MiddleButton, point.x, point.y );
    00204 }
    00205 //-----------------------------------------------------------------------------
    00206 void MDIWindow::OnMouseMove(UINT nFlags, CPoint point)
    00207 {
    00208   dispatchMouseMoveEvent( point.x, point.y );
    00209 }
    00210 //-----------------------------------------------------------------------------
    00211 BOOL MDIWindow::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
    00212 {
    00213   dispatchMouseWheelEvent (zDelta/120);
    00214   return FALSE;
    00215 }
    00216 //-----------------------------------------------------------------------------
    00217 void MDIWindow::OnRButtonDblClk(UINT nFlags, CPoint point)
    00218 {
    00219   countAndCapture();
    00220   dispatchMouseDownEvent( RightButton, point.x, point.y );
    00221 }
    00222 //-----------------------------------------------------------------------------
    00223 void MDIWindow::OnRButtonDown(UINT nFlags, CPoint point)
    00224 {
    00225   countAndCapture();
    00226   dispatchMouseDownEvent( RightButton, point.x, point.y );
    00227 }
    00228 //-----------------------------------------------------------------------------
    00229 void MDIWindow::OnRButtonUp(UINT nFlags, CPoint point)
    00230 {
    00231   countAndRelease();
    00232   dispatchMouseUpEvent( RightButton, point.x, point.y );
    00233 }
    00234 //-----------------------------------------------------------------------------
    00235 void MDIWindow::OnDropFiles(HDROP hDrop)
    00236 {
    00237   int count = DragQueryFile(hDrop, 0xFFFFFFFF, 0, 0);
    00238   const int char_count = 1024;
    00239   std::vector<String> files;
    00240   for(int i=0; i<count; ++i)
    00241   {
    00242     wchar_t file_path[char_count];
    00243     memset(file_path, 0, char_count);
    00244     DragQueryFile(hDrop,i,file_path,char_count);
    00245     files.push_back(file_path);
    00246   }
    00247   dispatchFileDroppedEvent(files);
    00248 }
    00249 //-----------------------------------------------------------------------------
    00250 void MDIWindow::OnSize (UINT nType, int cx, int cy)
    00251 {
    00252   CWnd::OnSize(nType, cx, cy);
    00253
    00254   if (0 >= cx || 0 >= cy || nType == SIZE_MINIMIZED)
    00255     return;
    00256
    00257   framebuffer()->setWidth(cx);
    00258   framebuffer()->setHeight(cy);
    00259   dispatchResizeEvent(cx, cy);
    00260 }
    00261 //-----------------------------------------------------------------------------

Visualization Library v2011.09.1162 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu Jan 26 2012 00:43:45.
Permission is granted to use this page to write and publish articles regarding Visualization Library.