【VC开源代码栏目提醒】:网学会员为需要VC开源代码的朋友们搜集整理了APBARDLG.CPP相关资料,希望对各位网友有所帮助!
// ApBarDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ApBarDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAppBarDlg dialog
CAppBarDlg::CAppBarDlg(int iResource, CWnd* pParent /*=NULL*/)
: CDialog(iResource, pParent)
{
//{{AFX_DATA_INIT(CAppBarDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_bMoving = FALSE;
m_bHidden = FALSE;
m_bOnTop = FALSE;
}
BEGIN_MESSAGE_MAP(CAppBarDlg, CDialog)
//{{AFX_MSG_MAP(CAppBarDlg)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_ACTIVATE()
ON_WM_WINDOWPOSCHANGED()
ON_WM_SIZE()
ON_WM_MOVE()
ON_WM_RBUTTONDOWN()
ON_WM_TIMER()
ON_WM_NCHITTEST()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAppBarDlg message handlers
int CAppBarDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
m_pAppBar = new CAppBar (m_hWnd);
ASSERT (m_pAppBar);
POPTIONS pOptions;
// Initialize the common control DLL
InitCommonControls();
// Allocate an OPTIONS struct and attach to the appbar
pOptions = (POPTIONS) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(OPTIONS));
if (pOptions)
{
pOptions->fAutoHide = m_bHidden;
pOptions->fOnTop = m_bOnTop;
pOptions->uSide = ABE_TOP;
// Calculate the Height and the width
DWORD dwUnits;
dwUnits = GetDialogBaseUnits ();
pOptions->cyHeight = (CY_DEFHEIGHT*HIWORD (dwUnits)) / 8;
pOptions->cxWidth = (CX_DEFWIDTH*LOWORD (dwUnits)) / 4;
if (!m_pAppBar->SetAppbarData (pOptions))
{
ASSERT (FALSE);
}
}
else
{
return FALSE;
}
// Register the appbar and attach it to the top by default
m_pAppBar->Register ();
m_pAppBar->SetSide (ABE_TOP);
return TRUE;
}
void CAppBarDlg::OnDestroy()
{
ASSERT (m_pAppBar);
if (m_pAppBar)
{
POPTIONS pOptions = m_pAppBar->GetAppbarData();
// Make sure the appbar is unregistered
if (m_pAppBar->IsRegistered ())
{
m_pAppBar->UnRegister ();
}
delete m_pAppBar;
m_pAppBar = NULL;
}
CDialog::OnDestroy ();
}
void CAppBarDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
ASSERT (m_pAppBar);
CWnd::OnActivate(nState, pWndOther, bMinimized);
APPBARDATA abd;
// Always send the activate message to the system
abd.cbSize = sizeof(APPBARDATA);
abd.hWnd = m_hWnd;
abd.lParam = 0;
SHAppBarMessage(ABM_ACTIVATE, &abd);
// Now determine if we're getting or losing activation
switch (nState)
{
case WA_ACTIVE:
case WA_CLICKACTIVE:
// If we're gaining activation, make sure we're visible
m_pAppBar->UnHide();
KillTimer(IDT_AUTOHIDE);
break;
case WA_INACTIVE:
// If we're losing activation, check to see if we need to autohide.
m_pAppBar->Hide();
break;
}
}
void CAppBarDlg::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
{
ASSERT (m_pAppBar);
CWnd::OnWindowPosChanged(lpwndpos);
APPBARDATA abd;
abd.cbSize = sizeof(APPBARDATA);
abd.hWnd = m_hWnd;
abd.lParam = 0;
SHAppBarMessage (ABM_WINDOWPOSCHANGED, &abd);
CWnd::OnWindowPosChanged(lpwndpos);
}
void CAppBarDlg::OnSize(UINT nType, int cx, int cy)
{
ASSERT (m_pAppBar);
CString strTemp;
CDialog::OnSize(nType, cx, cy);
POPTIONS pOpt = m_pAppBar->GetAppbarData();
RECT rcWindow;
if (m_bMoving || pOpt->fAutoHide)
{
return;
}
// Make sure that client area has dimension
if (!pOpt->fHiding && ((cx == 0) || (cy == 0)))
{
#ifdef LOG
strTemp.LoadString (IDS_ZERO_DIMENSION);
gLog.WriteError (strTemp);
#endif
}
// Let the system know the appbar size has changed
m_pAppBar->Size ();
// Update the stored height and widths if the appbar is not hidden
if (!pOpt->fHiding)
{
GetWindowRect(&rcWindow);
if (pOpt->uSide == ABE_TOP || pOpt->uSide == ABE_BOTTOM)
{
pOpt->cyHeight = rcWindow.bottom - rcWindow.top;
}
else
{
pOpt->cxWidth = rcWindow.right - rcWindow.left;
}
}
}
void CAppBarDlg::OnMove(int x, int y)
{
ASSERT (m_pAppBar);
CDialog::OnMove(x, y);
POPTIONS pOpt = m_pAppBar->GetAppbarData();
if (m_bMoving || pOpt->fAutoHide)
{
return;
}
m_pAppBar->Size();
}
void CAppBarDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Popup menu here.
CDialog::OnRButtonDown(nFlags, point);
}
void CAppBarDlg::OnTimer(UINT nIDEvent)
{
ASSERT (m_pAppBar);
POPTIONS pOpt = m_pAppBar->GetAppbarData();
POINT pt;
RECT rc;
HWND hwndActive;
switch (nIDEvent)
{
// The AUTOHIDE timer has fired. Check to see if the mouse is over our
// window and if not hide the appbar.
case IDT_AUTOHIDE:
if ((pOpt->fAutoHide) && (!pOpt->fHiding))
{
// Get the mouse position, the window position, and active
// window
GetCursorPos(&pt);
GetWindowRect(&rc);
hwndActive = (HWND) GetForegroundWindow();
// If the mouse is outside of our window, or we are not active,
// or at least one window is active, or we are not the parent
// of an active window, the hide the appbar window.
if ((!PtInRect(&rc, pt)) && (hwndActive != m_hWnd) &&
(hwndActive != NULL) /*MOREWORK && (GetWindowOwner(hwndActive) != hwnd)*/)
{
KillTimer (nIDEvent);
m_pAppBar->Hide ();
}
}
break;
// The period between the time the user has entered our window and the
// time we should show the window has expired.
case IDT_AUTOUNHIDE:
// Kill the timer, we only need it to fire once.
KillTimer (nIDEvent);
GetWindowRect (&rc);
if ((pOpt->fAutoHide) && (pOpt->fHiding))
{
// Check to see if the cursor is still in the appbar. If so,
// the unhide the window.
GetCursorPos(&pt);
if (PtInRect(&rc, pt))
{
m_pAppBar->UnHide ();
}
}
break;
}
CDialog::OnTimer(nIDEvent);
}
UINT CAppBarDlg::OnNcHitTest(CPoint point)
{
ASSERT (m_pAppBar);
POPTIONS pOpt = m_pAppBar->GetAppbarData ();
LRESULT lHitTest;
// Take care of the autohide stuff if needed
m_pAppBar->SetAutoUnhideTimer ();
// Let DefWindowProc() tell us where the mouse is
lHitTest = CWnd::OnNcHitTest(point);
// We want to disable sizing in all directions except the inside edge.
if ((pOpt->uSide == ABE_TOP) && (lHitTest == HTBOTTOM))
return HTBOTTOM;
if ((pOpt->uSide == ABE_BOTTOM) && (lHitTest == HTTOP))
return HTTOP;
if ((pOpt->uSide == ABE_LEFT) && (lHitTest == HTRIGHT))
return HTRIGHT;
if ((pOpt->uSide == ABE_RIGHT) && (lHitTest == HTLEFT))
return HTLEFT;
return HTCLIENT;
}
void CAppBarDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
ASSERT (m_pAppBar);
POPTIONS pOpt = m_pAppBar->GetAppbarData();
m_bMoving = TRUE;
SetCap
上一篇:
AnnounceDlg.cpp
下一篇:
法律专业开题报告范文