// BrowsDlg.cpp : implementation file // #include "stdafx.h" #include "mfcdemo.h" #include "BrowsDlg.h" #include "maindemo.h" extern CMfcdemoApp theApp; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CBrowseDlg dialog CBrowseDlg::CBrowseDlg(CWnd* pParent /*=NULL*/) : CDialog(CBrowseDlg::IDD, pParent) { //{{AFX_DATA_INIT(CBrowseDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT ASSERT(pParent != NULL); m_pMyOwner=pParent; m_nID = CBrowseDlg::IDD; } void CBrowseDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CBrowseDlg) DDX_Control(pDX, IDC_HIDDENLIST, m_HiddenList); DDX_Control(pDX, IDC_LEADIMGLISTCTRL1, m_LEADImageList); DDX_Control(pDX, IDC_LEADTHUMBCTRL1, m_LEADThumb); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CBrowseDlg, CDialog) //{{AFX_MSG_MAP(CBrowseDlg) ON_WM_SIZE() ON_WM_KEYDOWN() ON_WM_CLOSE() ON_WM_PALETTECHANGED() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CBrowseDlg message handlers void CBrowseDlg::OnCancel() { ((CMainFrame*)m_pMyOwner)->BrowseDone(); DestroyWindow(); } void CBrowseDlg::PostNcDestroy() { delete this; } BOOL CBrowseDlg::OnInitDialog() { CDialog::OnInitDialog(); CRect rcWin; GetClientRect(&rcWin); m_LEADImageList.MoveWindow(&rcWin, TRUE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CBrowseDlg::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); CRect rcWin; GetClientRect(&rcWin); m_LEADImageList.MoveWindow(&rcWin, TRUE); } BEGIN_EVENTSINK_MAP(CBrowseDlg, CDialog) //{{AFX_EVENTSINK_MAP(CBrowseDlg) ON_EVENT(CBrowseDlg, IDC_LEADTHUMBCTRL1, 1 /* ThumbnailEvent */, OnThumbnailEventLeadthumbctrl1, VTS_I4 VTS_BSTR VTS_I2 VTS_I2) ON_EVENT(CBrowseDlg, IDC_LEADIMGLISTCTRL1, 1 /* ItemSelected */, OnItemSelectedLeadimglistctrl1, VTS_I4) ON_EVENT(CBrowseDlg, IDC_LEADIMGLISTCTRL1, 3 /* Click */, OnClickLeadimglistctrl1, VTS_NONE) ON_EVENT(CBrowseDlg, IDC_LEADIMGLISTCTRL1, 6 /* KeyPress */, OnKeyPressLeadimglistctrl1, VTS_I2) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() BOOL CBrowseDlg::Create() { return CDialog::Create(m_nID, m_pMyOwner); } void CBrowseDlg::OnThumbnailEventLeadthumbctrl1(long Bitmap, LPCTSTR pszFilename, short nStatusCode, short nPercent) { MSG msg; // are there any messages in the queue (like a key being pressed) ? while( PeekMessage(&msg,NULL, 0, 0, PM_REMOVE) ) { TranslateMessage( &msg ); /* Translates virtual key codes. */ DispatchMessage( &msg ); /* Dispatches message to window. */ } if(nStatusCode == BROWSE_LOADING) //loading a file goto EVENTOUT; if(nStatusCode == 0) AddLEADListItem(pszFilename, Bitmap); EVENTOUT: if(((CMainFrame*)m_pMyOwner)->m_bBrowseQuit) m_LEADThumb.SetContinueBrowse(FALSE); else m_LEADThumb.SetContinueBrowse(TRUE); } void CBrowseDlg::AddLEADListItem(LPCTSTR pszFilename, long Bitmap) { CString FileTitle; CString Temp; int n; //add data to the list Temp = pszFilename; n = Temp.ReverseFind('\\'); n++; FileTitle = Temp.Right(Temp.GetLength()-n); m_HiddenList.AddString(pszFilename); m_LEADImageList.Insert(Bitmap, FileTitle, 0); m_LEADImageList.EnsureVisible(m_LEADImageList.GetCount() - 1); } void CBrowseDlg::OnItemSelectedLeadimglistctrl1(long nIndex) { CString csFile; if(!m_bBrowsing) { m_HiddenList.GetText(nIndex, csFile); theApp.OpenDocumentFile((LPCTSTR)csFile); SetActiveWindow(); } } void CBrowseDlg::OnClickLeadimglistctrl1() { ((CMainFrame*)m_pMyOwner)->m_bBrowseQuit = TRUE; } void CBrowseDlg::OnKeyPressLeadimglistctrl1(short KeyAscii) { ((CMainFrame*)m_pMyOwner)->m_bBrowseQuit = TRUE; } void CBrowseDlg::OnClose() { if(m_bBrowsing) ((CMainFrame*)m_pMyOwner)->m_bBrowseQuit = TRUE; else CDialog::OnClose(); } void CBrowseDlg::OnPaletteChanged(CWnd* pFocusWnd) { if(::IsWindow(m_LEADImageList.m_hWnd)) m_LEADImageList.SendMessage(WM_PALETTECHANGED, (WPARAM)pFocusWnd->m_hWnd, 0); }