Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | // DeviceContext base class, wrapping Windows HDC, plus some |
| 20 | // helper classes tailored to particular types of DC, such as |
| 21 | // window and device DCs. |
| 22 | |
| 23 | #ifndef __RFB_WIN32_DEVICECONTEXT_H__ |
| 24 | #define __RFB_WIN32_DEVICECONTEXT_H__ |
| 25 | |
| 26 | #include <windows.h> |
| 27 | #include <rfb/PixelFormat.h> |
| 28 | #include <rfb/Rect.h> |
| 29 | #include <rfb_win32/TCharArray.h> |
| 30 | |
| 31 | namespace rfb { |
| 32 | |
| 33 | namespace win32 { |
| 34 | |
| 35 | // Base class, providing methods to get the bounding (clip) box, |
| 36 | // and the pixel format, and access to the HDC itself. |
| 37 | class DeviceContext { |
| 38 | public: |
| 39 | DeviceContext() : dc(0) {} |
| 40 | virtual ~DeviceContext() {} |
| 41 | operator HDC() const {return dc;} |
| 42 | PixelFormat getPF() const; |
| 43 | static PixelFormat getPF(HDC dc); |
| 44 | Rect getClipBox() const; |
| 45 | static Rect getClipBox(HDC dc); |
| 46 | protected: |
| 47 | HDC dc; |
| 48 | }; |
| 49 | |
| 50 | // -=- DeviceContext that opens a specific display device |
| 51 | class DeviceDC : public DeviceContext { |
| 52 | public: |
| 53 | DeviceDC(const TCHAR* deviceName); |
| 54 | ~DeviceDC(); |
| 55 | }; |
| 56 | |
| 57 | // Get a DC for a particular window's client area. |
| 58 | class WindowDC : public DeviceContext { |
| 59 | public: |
| 60 | WindowDC(HWND wnd); |
| 61 | virtual ~WindowDC(); |
| 62 | protected: |
| 63 | HWND hwnd; |
| 64 | }; |
| 65 | |
| 66 | // Create a new DC, compatible with an existing one. |
| 67 | class CompatibleDC : public DeviceContext { |
| 68 | public: |
| 69 | CompatibleDC(HDC existing); |
| 70 | virtual ~CompatibleDC(); |
| 71 | }; |
| 72 | |
| 73 | // Create a new DC, compatible with an existing one, and |
| 74 | // select the specified bitmap into it. |
| 75 | class BitmapDC : public CompatibleDC { |
| 76 | public: |
| 77 | BitmapDC(HDC hdc, HBITMAP hbitmap); |
| 78 | ~BitmapDC(); |
| 79 | protected: |
| 80 | HBITMAP oldBitmap; |
| 81 | }; |
| 82 | |
| 83 | }; |
| 84 | }; |
| 85 | |
| 86 | #endif |