从文件加载位图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#pragma once

// ZBitmap从文件加载位图资源
class ZBitmap
{
private:
HBITMAP m_hBitmap;
CString m_FileName;
public:
ZBitmap(const char* pFileName);
ZBitmap();
virtual ~ZBitmap();
public:
HBITMAP GetHandle();
BOOL LoadBitmapTo(const char* pFileName);

private: // stop copy
ZBitmap (const ZBitmap&);
ZBitmap operator=(const ZBitmap&);
};
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
#include "StdAfx.h"
#include "ZLoadBitmap.h"

// ZBitmap
ZBitmap::ZBitmap()
: m_hBitmap(NULL)
, m_FileName(_T(""))
{

}

ZBitmap::ZBitmap(const char* pFileName)
: m_hBitmap(NULL)
, m_FileName(pFileName)
{
this->LoadBitmapTo(pFileName);
}

ZBitmap::~ZBitmap()
{
if (NULL != m_hBitmap)
{
::DeleteObject(m_hBitmap);
m_hBitmap = NULL;
}
}

BOOL ZBitmap::LoadBitmapTo(const char* pFileName)
{
if (NULL != m_hBitmap)
{
::DeleteObject(m_hBitmap);
m_hBitmap = NULL;
}
m_hBitmap = (HBITMAP)LoadImage(NULL, pFileName, IMAGE_BITMAP, 0,0, LR_LOADFROMFILE); // 载入
if (NULL == m_hBitmap)
{
return FALSE;
}
return TRUE;
}
HBITMAP ZBitmap::GetHandle()
{
return m_hBitmap;
}

加载图标

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#pragma once
// 从文件加载图标资源
class ZIcon
{
public:
HICON GetHandle();
BOOL LoadIconTo(const char* pFileName);
private:
HICON m_hIcon;
CString m_FileName;
public:
ZIcon(const char *pFileName);
ZIcon();
virtual ~ZIcon();
private: // stop copy
ZIcon (const ZIcon&);
ZIcon operator=(const ZIcon&);
};
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
#include "StdAfx.h"
#include "ZIcon.h"

ZIcon::ZIcon()
: m_hIcon(NULL)
, m_FileName(_T(""))
{

}

ZIcon::ZIcon(const char* pFileName)
: m_hIcon(NULL)
, m_FileName(pFileName)
{
this->LoadIconTo(pFileName);
}

ZIcon::~ZIcon()
{
if (NULL != m_hIcon)
{
::DeleteObject(m_hIcon);
m_hIcon = NULL;
}
}

BOOL ZIcon::LoadIconTo(const char* pFileName)
{
if (NULL != m_hIcon)
{
::DeleteObject(m_hIcon);
m_hIcon = NULL;
}
m_hIcon = (HICON)LoadImage(NULL, pFileName, IMAGE_ICON, 0,0, LR_LOADFROMFILE);
if (NULL == m_hIcon)
{
return FALSE;
}
return TRUE;
}

HICON ZIcon::GetHandle()
{
return m_hIcon;
}