// MainDlg.h : interface of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////
#pragma once
#include "CaptionButton.h"
#include "AppBar.h"
class CMainDlg : public CDialogImpl<CMainDlg>, public CUpdateUI<CMainDlg>,
public CMessageFilter, public CIdleHandler,
public CCaptionButton<CMainDlg>,
public CAppBar<CMainDlg>
{
public:
enum { IDD = IDD_MAINDLG };
enum {
ID_PUSH_PIN = WM_USER + 100,
ID_UP_PIN = WM_USER + 101,
ID_DOWN_PIN = WM_USER + 102,
ID_LEFT_PIN = WM_USER + 103,
ID_RIGHT_PIN= WM_USER + 104
};
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)
CHAIN_MSG_MAP(CCaptionButton<CMainDlg>)
CHAIN_MSG_MAP(CAppBar<CMainDlg>)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
COMMAND_ID_HANDLER(ID_PUSH_PIN, OnPushPin)
COMMAND_ID_HANDLER(ID_LEFT_PIN, OnLeftPin)
COMMAND_ID_HANDLER(ID_RIGHT_PIN, OnRightPin)
COMMAND_ID_HANDLER(ID_UP_PIN, OnUpPin)
COMMAND_ID_HANDLER(ID_DOWN_PIN, OnDownPin)
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);
//add caption buttons
CImageList il;
il.Create(IDB_PIN, 16, 5, RGB(255, 255, 255));
AddButton(ID_PUSH_PIN, 16, 16, il, "Stay visible");
CImageList il2;
il2.Create(IDB_UP, 16, 5, RGB(255, 255, 255));
AddButton(ID_UP_PIN, 16, 8, il2, "Dock top");
CImageList il3;
il3.Create(IDB_DOWN, 16, 5, RGB(255, 255, 255));
AddButton(ID_DOWN_PIN, 16, 8, il3, "Dock bottom");
CImageList il4;
il4.Create(IDB_LEFT, 8, 5, RGB(255, 255, 255));
AddButton(ID_LEFT_PIN, 8, 16, il4, "Dock left");
CImageList il5;
il5.Create(IDB_RIGHT, 8, 5, RGB(255, 255, 255));
AddButton(ID_RIGHT_PIN, 8, 16, il5, "Dock right");
//disable a caption button
EnableButton(2, false);
//initialize appbar
InitAppBar(APPBAR_DOCKING_ALL, true, false);
return TRUE;
}
POINT GetButtonPos(int index)
{
CRect rcWnd;
GetWindowRect(&rcWnd);
rcWnd.OffsetRect(-rcWnd.TopLeft());
rcWnd.DeflateRect(2, 2);
//locate the top right base point
CPoint pt(rcWnd.right, rcWnd.top);
pt.x -= 20;
pt.y += 2;
switch (index)
{
case 0://autohide pin
pt.x -= 16;
break;
case 1://up
pt.x -= 18+16+10;
break;
case 2://down
pt.x -= 18+16+10;
pt.y += 8;
break;
case 3://left
pt.x -= 16+18+10+10;
break;
case 4://right
pt.x -= 16+10;
break;
}
return pt;
}
LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CAboutDlg dlg;
dlg.DoModal();
return 0;
}
LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CloseDialog(wID);
return 0;
}
void CloseDialog(int nVal)
{
DestroyWindow();
::PostQuitMessage(nVal);
}
LRESULT OnPushPin(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
static bool bChecked = false;
//change check status
bChecked = !bChecked;
CheckButton(0, bChecked);
SetAutoHide(!bChecked);
return 0;
}
LRESULT OnLeftPin(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
DockAppBar(APPBAR_DOCKING_LEFT);
return 0;
}
LRESULT OnRightPin(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
DockAppBar(APPBAR_DOCKING_RIGHT);
return 0;
}
LRESULT OnUpPin(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
DockAppBar(APPBAR_DOCKING_TOP);
return 0;
}
LRESULT OnDownPin(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
DockAppBar(APPBAR_DOCKING_BOTTOM);
return 0;
}
};