Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[dad864]: AnimDialog.cpp Maximize Restore History

Download this file

AnimDialog.cpp    190 lines (162 with data), 4.7 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// AnimDialog.cpp : implementation file
//
#include "stdafx.h"
#include "chitem.h"
#include "AnimDialog.h"
#include "ChitemDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAnimDialog dialog
CAnimDialog::CAnimDialog(CWnd* pParent /*=NULL*/)
: CDialog(CAnimDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CAnimDialog)
m_filter = _T("");
//}}AFX_DATA_INIT
}
void CAnimDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAnimDialog)
DDX_Control(pDX, IDC_ICONRES, m_list_control);
DDX_Text(pDX, IDC_FILTER, m_filter);
DDV_MaxChars(pDX, m_filter, 8);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAnimDialog, CDialog)
//{{AFX_MSG_MAP(CAnimDialog)
ON_NOTIFY(NM_CLICK, IDC_ICONRES, OnClickIconres)
ON_NOTIFY(LVN_GETDISPINFO, IDC_ICONRES, OnGetdispinfoIconres)
ON_EN_KILLFOCUS(IDC_FILTER, OnKillfocusFilter)
//}}AFX_MSG_MAP
ON_NOTIFY(NM_CUSTOMDRAW, IDC_ICONRES, OnCustomdrawMyList)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAnimDialog message handlers
void CAnimDialog::GetItemImage(LV_DISPINFO *pDispInfo)
{
HBITMAP hb;
LVITEM *Item = &pDispInfo->item;
//m_list_control.GetItem(&Item);
read_bam_preview(Item->pszText, &the_bam, true);
the_bam.MakeBitmap(0,RGB(240,240,240),hb,BM_RESIZE,64,64);
imagelist.Replace(m_cnt,CBitmap::FromHandle(hb),CBitmap::FromHandle(hb));
Item->iImage = m_cnt;
m_cnt = (m_cnt+1)&255;
//m_list_control.SetItem(Item);
}
void CAnimDialog::RemoveItemImage(unsigned int item)
{
LVITEM Item;
char key[10];
Item.mask = (unsigned int) -1;
Item.iItem=item;
Item.iSubItem = 0;
Item.pszText = key;
Item.cchTextMax=8;
m_list_control.GetItem(&Item);
imagelist.Remove(Item.iImage);
Item.iImage=0;
m_list_control.SetItem(&Item);
}
void CAnimDialog::OnCustomdrawMyList(NMHDR *pNMHDR, LRESULT *pResult)
{
COLORREF crText = RGB(240,240,240);
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
*pResult = CDRF_DODEFAULT;
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
{
pLVCD->clrTextBk=crText;
*pResult = CDRF_NOTIFYITEMDRAW;
return;
}
if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
{
pLVCD->clrTextBk = crText;
*pResult = CDRF_DODEFAULT;
return;
}
}
void CAnimDialog::FillList()
{
POSITION pos;
CString key;
loc_entry fileloc;
int idx;
int itemcount;
m_list_control.DeleteAllItems();
idx=determinetype(m_restype);
if(!idx)
{
MessageBox("Internal error (no method for filling listbox)","Error",MB_ICONSTOP|MB_OK|MB_TASKMODAL);
return;
}
if (m_filter.IsEmpty()) {
itemcount = resources[idx]->GetCount();
} else {
itemcount = 0;
pos=resources[idx]->GetStartPosition();
while(pos) {
resources[idx]->GetNextAssoc(pos, key, fileloc);
if (key.Find(m_filter)!=-1) itemcount++;
}
}
m_list_control.SetItemCount(itemcount);
}
void CAnimDialog::OnClickIconres(NMHDR* pNMHDR, LRESULT* pResult)
{
LVHITTESTINFO htinfo;
NM_LISTVIEW *pNMListView = (NM_LISTVIEW*)pNMHDR;
htinfo.pt=pNMListView->ptAction;
m_item=m_list_control.SubItemHitTest(&htinfo);
if(m_item<0) return;
m_picked=m_list_control.GetItemText(m_item,0);
*pResult = 0;
OnOK();
}
BOOL CAnimDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_cnt = 0;
imagelist.Create(64, 64, ILC_COLORDDB, 256, 0);
imagelist.SetImageCount(256);
m_list_control.SetImageList(&imagelist, LVSIL_NORMAL);
FillList();
return TRUE;
}
void CAnimDialog::OnGetdispinfoIconres(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
// TODO: Add your control notification handler code here
if(pDispInfo->item.mask&LVIF_TEXT) {
int idx=determinetype(m_restype);
POSITION pos=resources[idx]->GetStartPosition();
CString key;
loc_entry fileloc;
int i = pDispInfo->item.iItem;
do {
resources[idx]->GetNextAssoc(pos,key,fileloc);
if (m_filter.IsEmpty() || (key.Find(m_filter)!=-1))
{
if (!i) break;
i--;
}
}
while(pos);
pDispInfo->item.pszText =
strncpy(pDispInfo->item.pszText,key,pDispInfo->item.cchTextMax);
}
if(pDispInfo->item.mask&LVIF_IMAGE) {
GetItemImage(pDispInfo);
}
*pResult = 0;
}
void CAnimDialog::OnKillfocusFilter()
{
UpdateData(UD_RETRIEVE);
FillList();
}