Welcome to mirror list, hosted at ThFree Co, Russian Federation.

selectobject.h « windirstat - github.com/windirstat/windirstat.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 40163d154b19e76faa8d1ea7a8fe1fffa194915d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// selectobject.h - Declaration and implementation of Device Context helper classes.
//
// WinDirStat - Directory Statistics
// Copyright (C) 2003-2005 Bernhard Seifert
// Copyright (C) 2004-2017 WinDirStat Team (windirstat.net)
//
// 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
//


// Example:
// Instead of writing
//     CGdiObject *old = pdc->SelectObject(&brush); ...; pdc->SelectObject(old);
// we can simply write
//     CSelectObject sobrush(pdc, &brush);
// and the destructor will reselect the old object.

#ifndef __SELECTOBJECT_H_VER__
#define __SELECTOBJECT_H_VER__ 2017112219
#if (defined(_MSC_VER) && (_MSC_VER >= 1020)) || defined(__MCPP)
#pragma once
#endif /* Check for "#pragma once" support */
#include "stdafx.h"

class CSelectObject
{
public:
    CSelectObject(CDC *pdc, CGdiObject *pObject)
    { m_pOldObject = pdc->SelectObject(pObject); m_pdc = pdc; }
    ~CSelectObject()
    { m_pdc->SelectObject(m_pOldObject); }
protected:
    CDC *m_pdc;
    CGdiObject *m_pOldObject;
};

class CSelectStockObject
{
public:
    CSelectStockObject(CDC *pdc, int nIndex)
    { m_pOldObject = pdc->SelectStockObject(nIndex); m_pdc = pdc; }
    ~CSelectStockObject()
    { m_pdc->SelectObject(m_pOldObject); }
protected:
    CDC *m_pdc;
    CGdiObject *m_pOldObject;
};

class CSetBkMode
{
public:
    CSetBkMode(CDC *pdc, int mode)
    { m_pdc = pdc; m_oldMode = pdc->SetBkMode(mode); }
    ~CSetBkMode()
    { m_pdc->SetBkMode(m_oldMode); }
protected:
    CDC *m_pdc;
    int m_oldMode;
};

class CSetTextColor
{
public:
    CSetTextColor(CDC *pdc, COLORREF color)
    { m_pdc = pdc; m_oldColor = pdc->SetTextColor(color); }
    ~CSetTextColor()
    { m_pdc->SetTextColor(m_oldColor); }
protected:
    CDC *m_pdc;
    COLORREF m_oldColor;
};

class CSetBkColor
{
public:
    CSetBkColor(CDC *pdc, COLORREF color)
    { m_pdc = pdc; m_oldColor = pdc->SetBkColor(color); }
    ~CSetBkColor()
    { m_pdc->SetBkColor(m_oldColor); }
protected:
    CDC *m_pdc;
    COLORREF m_oldColor;
};

class CSaveDC
{
public:
    CSaveDC(CDC *pdc) { m_pdc = pdc; m_save = pdc->SaveDC(); }
    ~CSaveDC() { m_pdc->RestoreDC(m_save); }
protected:
    CDC *m_pdc;
    int m_save;
};

inline BOOL CreateRectRgn(CRgn& rgn, CRect rc)
{
    return rgn.CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
}

inline COLORREF MakeShadowColor(COLORREF c, int percent)
{
    return RGB(
        RGB_GET_RVALUE(c) * percent / 100,
        RGB_GET_GVALUE(c) * percent / 100,
        RGB_GET_BVALUE(c) * percent / 100
    );
}

#endif /* __SELECTOBJECT_H_VER__ */