// MainDlg.h : interface of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////
#pragma once
#include "appbar.h"
#include "resource.h"
#include "aboutdlg.h"
class CMainDlg : public CDialogImpl<CMainDlg>, public CUpdateUI<CMainDlg>,
public CMessageFilter, public CIdleHandler,public CAppBar<CMainDlg>
{
public:
enum { IDD = IDD_MAINDLG };
virtual BOOL PreTranslateMessage(MSG* pMsg)
{
return CWindow::IsDialogMessage(pMsg);
}
virtual BOOL OnIdle()
{
return FALSE;
}
BEGIN_UPDATE_UI_MAP(CMainDlg)
END_UPDATE_UI_MAP()
BEGIN_MSG_MAP(CMainDlg)
COMMAND_HANDLER(IDC_CHECK_KEEPSIZE, BN_CLICKED, OnClickedKeepsize)
CHAIN_MSG_MAP(CAppBar<CMainDlg>)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
COMMAND_ID_HANDLER(IDC_DOCK_LEFT, OnLeft)
COMMAND_ID_HANDLER(IDC_DOCK_RIGHT, OnRight)
COMMAND_ID_HANDLER(IDC_DOCK_TOP, OnTop)
COMMAND_ID_HANDLER(IDC_DOCK_BOTTOM, OnBottom)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
COMMAND_HANDLER(IDC_BTN_UNDOCK, BN_CLICKED, OnClickedUndock)
COMMAND_HANDLER(IDC_CHECK_AUTOHIDE, BN_CLICKED, OnClickedAutohide)
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);
InitAppBar(APPBAR_DOCKING_ALL, false);
return TRUE;
}
LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CAboutDlg dlg;
dlg.DoModal();
return 0;
}
LRESULT OnLeft(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
DockAppBar(APPBAR_DOCKING_LEFT);
return 0;
}
LRESULT OnRight(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
DockAppBar(APPBAR_DOCKING_RIGHT);
return 0;
}
LRESULT OnTop(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
DockAppBar(APPBAR_DOCKING_TOP);
return 0;
}
LRESULT OnBottom(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
DockAppBar(APPBAR_DOCKING_BOTTOM);
return 0;
}
LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CloseDialog(wID);
return 0;
}
void CloseDialog(int nVal)
{
DestroyWindow();
::PostQuitMessage(nVal);
}
LRESULT OnClickedUndock(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
DockAppBar(APPBAR_DOCKING_NONE);
return 0;
}
LRESULT OnClickedAutohide(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
int nChecked = IsDlgButtonChecked(IDC_CHECK_AUTOHIDE);
SetAutoHide(nChecked==BST_CHECKED);
return 0;
}
LRESULT OnClickedKeepsize(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
int nChecked = IsDlgButtonChecked(IDC_CHECK_KEEPSIZE);
SetKeepSize(nChecked==BST_CHECKED);
return 0;
}
};