-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitmapDialog.cpp
More file actions
168 lines (128 loc) · 4.29 KB
/
Copy pathBitmapDialog.cpp
File metadata and controls
168 lines (128 loc) · 4.29 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// BitmapDialog.cpp : implementation file
//
#include "stdafx.h"
#include "WECompressor.h"
#include "BitmapDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBitmapDialog dialog
CBitmapDialog::CBitmapDialog(CString filepath,int ID1,int ID2,int Colors,CWnd* pParent /*=NULL*/)
: CDialog(CBitmapDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CBitmapDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_hBmpNew = NULL;
m_BMPFileTmp = filepath;
m_ID1 = ID1;
m_ID2 = ID2;
m_Colors = Colors;
}
CBitmapDialog::~CBitmapDialog()
{
m_dcMem.DeleteDC();
if (m_BMPFileTmp != "")
CFile::Remove(m_BMPFileTmp);
}
BOOL CBitmapDialog::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CClientDC dc(this);
m_dcMem.CreateCompatibleDC( &dc );
OnShow();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBitmapDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBitmapDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBitmapDialog, CDialog)
//{{AFX_MSG_MAP(CBitmapDialog)
ON_WM_PAINT()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBitmapDialog message handlers
void CBitmapDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
CBitmap *pBitmapOld = m_dcMem.SelectObject(CBitmap::FromHandle((HBITMAP) m_hBmpNew));
CRect RectDlg;
GetClientRect(&RectDlg);
dc.SetStretchBltMode(COLORONCOLOR);
dc.StretchBlt(0, 0,
RectDlg.Width(), RectDlg.Height(),
&m_dcMem,
0, 0,
m_bmInfo.bmWidth, m_bmInfo.bmHeight, SRCCOPY);
m_dcMem.SelectObject(pBitmapOld);
}
void CBitmapDialog::OnShow()
{
if(m_hBmpNew != NULL )
DeleteObject(m_hBmpNew);
m_hBmpNew = (HBITMAP) LoadImage (
AfxGetInstanceHandle(), // handle to instance
m_BMPFileTmp, // name or identifier of the image
IMAGE_BITMAP, // image types
0, // desired width
0, // desired height
LR_LOADFROMFILE);
if ( m_hBmpNew == NULL )
AfxMessageBox("Load Image Failed");
// put the HBITMAP info into the CBitmap (but not the bitmap itself)
else
{
// Convert to screen coordinates using static as base,
// then to DIALOG (instead of static) client coords
// using dialog as base
GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo );
//GetObject( (HPALETTE) m_hBmpNew , sizeof(WORD), &ColNum );
VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMem, m_hBmpNew ) );
CString TitleTmp;
SetWindowPos(&wndTop,0,0,m_bmInfo.bmWidth*2,m_bmInfo.bmHeight*2,SWP_NOMOVE);//offsetx,offsety+m_bmInfo.bmHeight,m_size.cx,18);
if (m_Colors == 16)
m_nBits = 4;
else
m_nBits = 8;
if (m_ID1 == 0)
TitleTmp.Format("200%% - %ux%u %u %s",m_bmInfo.bmWidth,m_bmInfo.bmHeight,m_Colors,
CString(MAKEINTRESOURCE(IDS_TITLE_COLORS)));
else
TitleTmp.Format("200%% - %s %d + %s %d - %ux%u %u %s (%d BIT)",
CString(MAKEINTRESOURCE(IDS_TITLE_IMAGE)),
m_ID1, CString(MAKEINTRESOURCE(IDS_TITLE_PALETTE)),m_ID2,m_bmInfo.bmWidth,
m_bmInfo.bmHeight,m_Colors,CString(MAKEINTRESOURCE(IDS_TITLE_COLORS)),m_nBits);
this->SetWindowText(TitleTmp);
InvalidateRect(NULL,FALSE);
}
}
void CBitmapDialog::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
UINT nZoom;
CString TitleTmp;
nZoom = (cx * 100) / m_bmInfo.bmWidth;
if (m_ID1 == 0)
TitleTmp.Format("%d%% - %ux%u %u %s",nZoom,m_bmInfo.bmWidth,m_bmInfo.bmHeight,m_Colors,
CString(MAKEINTRESOURCE(IDS_TITLE_COLORS)));
else
TitleTmp.Format("%d%% - %s %d + %s %d - %ux%u %u %s (%d BIT)",
nZoom,CString(MAKEINTRESOURCE(IDS_TITLE_IMAGE)),
m_ID1, CString(MAKEINTRESOURCE(IDS_TITLE_PALETTE)),m_ID2,m_bmInfo.bmWidth,
m_bmInfo.bmHeight,m_Colors,CString(MAKEINTRESOURCE(IDS_TITLE_COLORS)),m_nBits);
this->SetWindowText(TitleTmp);
InvalidateRect(NULL,FALSE);
}