// MainDlg.h : interface of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////
#pragma once
class CMainDlg : public CDialogImpl<CMainDlg>, public CUpdateUI<CMainDlg>,
public CMessageFilter, public CIdleHandler
{
public:
enum { IDD = IDD_MAINDLG };
CWTLVirtualList<Ctitles> m_view;
virtual BOOL PreTranslateMessage(MSG* pMsg)
{
// return CWindow::IsDialogMessage(pMsg);
// Changed so escape key is handled by edit not by dialog
pMsg;
return FALSE;
}
virtual BOOL OnIdle()
{
return FALSE;
}
BEGIN_UPDATE_UI_MAP(CMainDlg)
END_UPDATE_UI_MAP()
BEGIN_MSG_MAP(CMainDlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
COMMAND_ID_HANDLER(IDOK, OnOK)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
COMMAND_ID_HANDLER(ID_DATA_NEW, OnDataNew)
COMMAND_ID_HANDLER(ID_DATA_COPY, OnDataCopy)
COMMAND_ID_HANDLER(ID_DATA_DELETE, OnDataDelete)
COMMAND_ID_HANDLER(ID_DATA_DELETEALL, OnDataDeleteAll)
COMMAND_ID_HANDLER(ID_MOVE_FIRST, OnMoveFirst)
COMMAND_ID_HANDLER(ID_MOVE_LAST, OnMoveLast)
COMMAND_ID_HANDLER(ID_MOVE_PREVIOUS, OnMovePrevious)
COMMAND_ID_HANDLER(ID_MOVE_NEXT, OnMoveNext)
REFLECT_NOTIFICATIONS()
END_MSG_MAP()
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
// center the dialog on the screen
CenterWindow();
// set icons
HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
SetIcon(hIcon, TRUE);
HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
SetIcon(hIconSmall, FALSE);
// register object for message filtering and idle updates
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
pLoop->AddMessageFilter(this);
pLoop->AddIdleHandler(this);
UIAddChildWindowContainer(m_hWnd);
// Initialize the virtual list view
m_view.Init(GetDlgItem(IDC_LIST1));
// Set first visible column width. Needed because the default
// width is set to the control's width on the dialog
int col = 0;
if (!m_view.GetShowBookmarks()) col = 1;
m_view.SetColumnWidth(col, LVSCW_AUTOSIZE_USEHEADER);
// Set the background color of alternating rows
m_view.SetBarColor(BLUEBAR);
return TRUE;
}
LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
// unregister message filtering and idle updates
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
pLoop->RemoveMessageFilter(this);
pLoop->RemoveIdleHandler(this);
return 0;
}
LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CAboutDlg dlg;
dlg.DoModal();
return 0;
}
LRESULT OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
// TODO: Add validation code
CloseDialog(wID);
return 0;
}
LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CloseDialog(wID);
return 0;
}
LRESULT OnDataNew(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
// Example of how to insert a new blank row. Make sure to initialize any
// key values and non-null fields before Insert is called. After that, non-
// mandatory values can be manually entered in the listview
m_view.m_data.ClearRecordMemory(); // Set all variables to 0
TCHAR* TitleID = _T("ZZ9998"); // Non-null key value is required
_tcsncpy_s(m_view.m_data.m_title_id, _tcslen(TitleID) + 1, TitleID, _TRUNCATE);
DBTIMESTAMP pubdate = { 0 }; // Non-null date value is required
pubdate.year = 2010;
pubdate.month = 12;
pubdate.day = 31;
m_view.m_data.m_pubdate = pubdate;
return m_view.OnDataNew(wNotifyCode, wID, hWndCtl, bHandled);
}
LRESULT OnDataCopy(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
// Example of how to copy an existing selected row by not initializing the
// active record memory to 0s. TitleID is a required value and must be
// supplied for the insert to succeed
TCHAR* TitleID = _T("ZZ9999");
_tcsncpy_s(m_view.m_data.m_title_id, _tcslen(TitleID) + 1, TitleID, _TRUNCATE);
return m_view.OnDataNew(wNotifyCode, wID, hWndCtl, bHandled);
}
LRESULT OnDataDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
return m_view.OnDataDelete(wNotifyCode, wID, hWndCtl, bHandled);
}
LRESULT OnDataDeleteAll(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
return m_view.OnDataDeleteAll(wNotifyCode, wID, hWndCtl, bHandled);
}
LRESULT OnMoveFirst(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
return m_view.OnMoveFirst(wNotifyCode, wID, hWndCtl, bHandled);
}
LRESULT OnMoveLast(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
return m_view.OnMoveLast(wNotifyCode, wID, hWndCtl, bHandled);
}
LRESULT OnMovePrevious(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
return m_view.OnMovePrevious(wNotifyCode, wID, hWndCtl, bHandled);
}
LRESULT OnMoveNext(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
return m_view.OnMoveNext(wNotifyCode, wID, hWndCtl, bHandled);
}
void CloseDialog(int nVal)
{
DestroyWindow();
::PostQuitMessage(nVal);
}
};