OWLNext
7.0
Borland's Object Windows Library for the modern age
Toggle main menu visibility
Loading...
Searching...
No Matches
icon.cpp
Go to the documentation of this file.
1
//----------------------------------------------------------------------------
2
// ObjectWindows
3
// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4
//
5
/// \file
6
/// Implementation of class TIcon, a GDI Icon object encapsulation
7
//----------------------------------------------------------------------------
8
#include <
owl/pch.h
>
9
#include <
owl/gdiobjec.h
>
10
#include <
owl/shellitm.h
>
11
12
namespace
owl
{
13
14
OWL_DIAGINFO
;
15
DIAG_DECLARE_GROUP
(OwlGDI);
// General GDI diagnostic group
16
17
//
18
/// Creates a TIcon object and sets the Handle data member to the given borrowed
19
/// handle. The ShouldDelete data member defaults to false, ensuring that the
20
/// borrowed handle will not be deleted when the C++ object is destroyed.
21
//
22
TIcon::TIcon
(HICON handle,
TAutoDelete
autoDelete)
23
:
24
TGdiBase
(handle, autoDelete)
25
{
26
}
27
28
//
29
/// Creates a copy of the given icon object.
30
//
31
TIcon::TIcon
(HINSTANCE,
const
TIcon
& icon)
32
{
33
Handle
= ::CopyIcon(icon);
34
CheckValid
();
35
}
36
37
//
38
/// Creates an icon object from the given resource.
39
//
40
TIcon::TIcon
(HINSTANCE instance,
TResId
resId)
41
{
42
Handle
= ::LoadIcon(instance, resId);
43
ShouldDelete
= (instance !=
nullptr
);
44
CheckValid
();
45
}
46
47
//
48
/// Creates an icon object from the given resource file.
49
//
50
TIcon::TIcon
(HINSTANCE instance,
const
tstring
& fileName,
int
index)
51
{
52
Handle
=
TShell::ExtractIcon
(instance, fileName.c_str(), index);
53
54
if
(
reinterpret_cast<
INT_PTR
>
(
Handle
) == 1)
55
Handle
=
nullptr
;
56
CheckValid
();
57
}
58
59
//
60
/// Creates an icon object with the given values.
61
//
62
TIcon::TIcon
(HINSTANCE instance,
const
TSize
& size,
int
planes,
int
bitsPixel,
63
const
void
* andBits,
const
void
* xorBits)
64
{
65
Handle
= ::CreateIcon(instance, size.cx, size.cy,
66
uint8
(planes),
uint8
(bitsPixel),
67
static_cast<
const
uint8
*
>
(andBits),
static_cast<
const
uint8
*
>
(xorBits));
68
CheckValid
();
69
}
70
71
//
72
/// Creates an icon object of the given size from the bits found in the resBits
73
/// buffer.
74
//
75
TIcon::TIcon
(
const
void
* resBits,
uint32
resSize)
76
{
77
Handle
= CreateIconFromResource((PBYTE)resBits, resSize,
true
, 0x00030000);
78
CheckValid
();
79
}
80
81
//
82
/// Creates an icon object with the given ICONINFO information.
83
//
84
TIcon::TIcon
(
const
ICONINFO& iconInfo)
85
{
86
WARN
(!iconInfo.fIcon,
"TIcon constructor called with ICONINFO::fIcon == false"
);
// Turn this into a precondition?
87
ICONINFO i = iconInfo;
// Make a clone, since CreateIconIndirect is not const-correct.
88
Handle
= CreateIconIndirect(&i);
89
CheckValid
();
90
}
91
92
#if defined(OWL5_COMPAT)
93
94
//
95
/// Creates an icon object with the given ICONINFO information.
96
/// This overload is deprecated. Use the overload that takes a reference instead.
97
//
98
TIcon::TIcon
(
const
ICONINFO* iconInfo)
99
{
100
//IconInfo->fIcon = true; // assume the user setup the struct OK
101
Handle
= CreateIconIndirect((PICONINFO)iconInfo);
102
CheckValid
();
103
}
104
105
#endif
106
107
//
108
/// Destroys the icon and frees any memory that the icon occupied.
109
//
110
TIcon::~TIcon
()
111
{
112
if
(
ShouldDelete
&&
Handle
)
113
::DestroyIcon(
static_cast<
HICON
>
(
Handle
));
114
}
115
116
//
117
/// Retrieves information about this icon.
118
/// Throws TXGdi on failure.
119
//
120
auto
TIcon::GetInfo
() const ->
TInfo
121
{
122
auto
i =
GetIconInfoEx
();
123
CHECK
(i.fIcon != FALSE);
124
i.szModName[
MAX_PATH
- 1] =
_T
(
'\0'
);
// Ensure termination.
125
i.szResName[
MAX_PATH
- 1] =
_T
(
'\0'
);
// Ensure termination.
126
return
TInfo
127
{
128
TPoint
{
static_cast<
int
>
(i.xHotspot),
static_cast<
int
>
(i.yHotspot)},
129
TBitmap
{i.hbmMask,
AutoDelete
},
// Takes ownership.
130
TBitmap
{i.hbmColor,
AutoDelete
},
// Takes ownership.
131
i.wResID,
132
tstring
{&i.szModName[0]},
133
tstring
{&i.szResName[0]}
134
};
135
}
136
137
//
138
/// Retrieves information about this icon.
139
/// Wrapper for the Windows API function of the same name. Throws TXGdi on failure.
140
///
141
/// \note GetIconInfo creates bitmaps for the hbmMask and hbmColor members of ICONINFO. The calling
142
/// application must manage these bitmaps and delete them when they are no longer necessary (using
143
/// the Windows API function ::DeleteObject explicitly, or by passing ownership of the handles to
144
/// TBitmap with the parameter `autoDelete` set to TAutoDelete::AutoDelete).
145
///
146
/// \sa http://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-geticoninfo
147
//
148
auto
TIcon::GetIconInfo
() const -> ICONINFO
149
{
150
auto
i = ICONINFO{};
151
const
auto
r =
::GetIconInfo
(
GetHandle
(), &i);
152
if
(!r || i.fIcon == FALSE)
throw
TXGdi
(IDS_GDIFAILURE,
GetHandle
());
153
return
i;
154
}
155
156
//
157
/// Retrieves information about this icon.
158
/// Wrapper for the Windows API function of the same name. Throws TXGdi on failure.
159
///
160
/// \note GetIconInfoEx creates bitmaps for the hbmMask and hbmColor members of ICONINFOEX. The calling
161
/// application must manage these bitmaps and delete them when they are no longer necessary (using
162
/// the Windows API function ::DeleteObject explicitly, or by passing ownership of the handles to
163
/// TBitmap with the parameter `autoDelete` set to TAutoDelete::AutoDelete).
164
///
165
/// \sa http://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-geticoninfoexa
166
//
167
auto
TIcon::GetIconInfoEx
() const -> ICONINFOEX
168
{
169
auto
i = ICONINFOEX{
sizeof
(ICONINFOEX)};
170
const
auto
r =
::GetIconInfoEx
(
GetHandle
(), &i);
171
if
(!r || i.fIcon == FALSE)
throw
TXGdi
(IDS_GDIFAILURE,
GetHandle
());
172
return
i;
173
}
174
175
}
// OWL namespace
176
/* ========================================================================== */
177
CHECK
#define CHECK(condition)
Definition
checks.h:239
WARN
#define WARN(condition, message)
Definition
checks.h:273
owl::TBitmap
TBitmap is the GDI bitmap class derived from TGdiObject.
Definition
gdiobjec.h:510
owl::TGdiBase::TGdiBase
TGdiBase()
This default constructor sets Handle to 0 and ShouldDelete to true.
Definition
gdibase.cpp:22
owl::TGdiBase::CheckValid
void CheckValid(uint resId=IDS_GDIFAILURE)
Definition
gdibase.cpp:49
owl::TGdiBase::ShouldDelete
bool ShouldDelete
Should object delete GDI handle in dtor?
Definition
gdibase.h:82
owl::TGdiBase::Handle
HANDLE Handle
GDI handle of this object.
Definition
gdibase.h:81
owl::TIcon::GetIconInfo
auto GetIconInfo() const -> ICONINFO
Retrieves information about this icon.
Definition
icon.cpp:148
owl::TIcon::TIcon
TIcon(HICON handle, TAutoDelete autoDelete=NoAutoDelete)
Creates a TIcon object and sets the Handle data member to the given borrowed handle.
Definition
icon.cpp:22
owl::TIcon::GetIconInfoEx
auto GetIconInfoEx() const -> ICONINFOEX
Retrieves information about this icon.
Definition
icon.cpp:167
owl::TIcon::GetInfo
auto GetInfo() const -> TInfo
Retrieves information about this icon.
Definition
icon.cpp:120
owl::TIcon::~TIcon
~TIcon()
Destroys the icon and frees any memory that the icon occupied.
Definition
icon.cpp:110
owl::TIcon::GetHandle
HICON GetHandle() const
Returns the handle of the icon with type HICON.
Definition
gdiobjec.h:1574
owl::TPoint
TPoint is a support class, derived from tagPOINT.
Definition
geometry.h:87
owl::TResId
Definition
wsyscls.h:206
owl::TShell::ExtractIcon
static HICON ExtractIcon(HINSTANCE, LPCTSTR, UINT)
Invokes 'ExtractIcon' indirectly.
Definition
shellitm.cpp:114
owl::TSize
The tagSIZE struct is defined as.
Definition
geometry.h:234
owl::TXGdi::TXGdi
TXGdi(uint resId=IDS_GDIFAILURE, HANDLE handle=0)
Constructs a TXGdi object with a default IDS_GDIFAILURE message.
Definition
gdibase.cpp:82
MAX_PATH
#define MAX_PATH
Definition
cygwin.h:98
_T
#define _T(x)
Definition
cygwin.h:51
gdiobjec.h
Definition of abstract GDI object class and derived classes.
owl::TAutoDelete
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition
gdibase.h:70
owl::AutoDelete
@ AutoDelete
Definition
gdibase.h:70
pch.h
owl
Object Windows Library (OWLNext Core).
Definition
animctrl.h:22
owl::uint8
unsigned char uint8
Definition
number.h:32
owl::uint32
unsigned long uint32
Definition
number.h:34
owl::OWL_DIAGINFO
OWL_DIAGINFO
Definition
animctrl.cpp:14
owl::tstring
std::string tstring
Definition
defs.h:79
owl::DIAG_DECLARE_GROUP
DIAG_DECLARE_GROUP(OwlThread)
shellitm.h
Definitions of Win95 Shell Clases: TShellItem, TShellItemIterator, TPidl, TShellMalloc.
owl::TIcon::TInfo
Definition
gdiobjec.h:696
source
owlcore
icon.cpp
Generated by
1.18.0