-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathToolBarDlg.cpp
More file actions
144 lines (125 loc) · 4.13 KB
/
ToolBarDlg.cpp
File metadata and controls
144 lines (125 loc) · 4.13 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
/////////////////////////////////////////////////////////////////////////////
// File: ToolBarDlg.cpp
// Version: 1.0.0.0
// Created: 15-april-2001
//
// Author: Thorsten Wack
// E-mail: wt@umsicht.fhg.de
//
// CToolBarDlg.cpp : implementation file
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is
// not sold for profit without the authors written consent, and
// providing that this notice and the authors name is included. If
// the source code in this file is used in any commercial application
// then a simple email would be nice.
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability if it causes any damage whatsoever.
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ToolBarDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CToolBarDlg dialog
CToolBarDlg::CToolBarDlg(CWnd* pParent /*=NULL*/)
: CDialog(CToolBarDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CToolBarDlg)
//}}AFX_DATA_INIT
m_pParent=pParent;
Create(CToolBarDlg::IDD, pParent);
}
void CToolBarDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CToolBarDlg)
DDX_Control(pDX, IDC_CHARSETCTRL, m_ToolBarBtnCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CToolBarDlg, CDialog)
//{{AFX_MSG_MAP(CToolBarDlg)
//}}AFX_MSG_MAP
ON_MESSAGE(CS_SELECTED, CharSetCtrlSelected)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CToolBarDlg message handlers
WNDPROC CToolBarDlg::m_MFCWndProc = NULL;
CToolBarDlg* CToolBarDlg::m_pDialog = NULL;
BOOL CToolBarDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Change of the default window procedure
WNDPROC temp = reinterpret_cast<WNDPROC>(
::SetWindowLong(GetSafeHwnd(),
GWL_WNDPROC,
reinterpret_cast<long>(NewWndProc) ));
if ( !m_MFCWndProc )
m_MFCWndProc = temp;
m_pDialog = this;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CToolBarDlg::CalculateRect()
{
CRect rect;
GetWindowRect(&rect);
int nImages=m_ToolBarBtnCtrl.m_pImageList->GetImageCount();
IMAGEINFO ImageInfo;
m_ToolBarBtnCtrl.m_pImageList->GetImageInfo(0, &ImageInfo);
rect.right=rect.left+
((ImageInfo.rcImage.right-ImageInfo.rcImage.left)+1)
*m_ToolBarBtnCtrl.GetCols()+2;
rect.bottom=rect.top+
((ImageInfo.rcImage.bottom-ImageInfo.rcImage.top)+1)
*m_ToolBarBtnCtrl.GetRows()+2;
MoveWindow(rect, TRUE);
m_ToolBarBtnCtrl.MoveWindow(CRect(0,0,rect.Width(), rect.Height()), TRUE);
}
BOOL CToolBarDlg::PreTranslateMessage(MSG* pMsg)
{
// Different management of the WM_KEYDOWN msg when is pressed the ENTER button
// (the default management closes the dialog) or the ESC (we want to close the
// dialog)
if ( pMsg->message == WM_KEYDOWN )
switch ( (int)pMsg->wParam )
{
case VK_RETURN:
m_pDialog->m_pParent->PostMessage( CS_SELECTED );
return TRUE;
case VK_ESCAPE:
m_pDialog->m_pParent->PostMessage( CS_ABORTED );
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
void CToolBarDlg::OnClose()
{
m_pDialog->m_pParent->PostMessage( CS_ABORTED );
CDialog::OnClose();
}
LRESULT CALLBACK CToolBarDlg::NewWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// The new window procedure manages only the dialog inactivate;
// the other msg are managed by default window procedure
if ( message == WM_ACTIVATE )
{
if ( wParam == 0 )
{
m_pDialog->m_pParent->PostMessage( CS_ABORTED );
return FALSE;
}
}
return ::CallWindowProc( m_MFCWndProc, hWnd, message, wParam, lParam );
}
LONG CToolBarDlg::CharSetCtrlSelected(WPARAM wParam , LPARAM lParam)
{
m_pDialog->m_pParent->PostMessage(CS_SELECTED);
return 0L;
}