|
#include "StdAfx.h"
#include "resource.h"
#include "ToolBarParentWnd.h"
CToolBarParentWnd::CToolBarParentWnd(void)
{
m_nButtonID = -1;
m_nButtonState = 0;
m_ToolbarWnd = NULL;
}
CToolBarParentWnd::~CToolBarParentWnd(void)
{
}
LRESULT CToolBarParentWnd::OnNotifySetButtonInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
int buttonID = (int)wParam;
TBBUTTONINFO buttonInfo;
memset(&buttonInfo, 0, sizeof(TBBUTTONINFO));
buttonInfo.cbSize = sizeof(TBBUTTONINFO);
buttonInfo.dwMask = TBIF_STYLE | TBIF_STATE;
buttonInfo.fsStyle = BTNS_DROPDOWN |BTNS_CHECK;
buttonInfo.fsState = TBSTATE_CHECKED|TBSTATE_ENABLED;
::SendMessage(m_ToolbarWnd, TB_SETBUTTONINFO, wParam, (LPARAM)&buttonInfo);
return S_OK;
}
LRESULT CToolBarParentWnd::OnNotifyDropDown(WPARAM wParam, LPNMHDR lpnmhdr, BOOL& /*bHandled*/)
{
if (m_pBrowserWndInfo == NULL)
{
return DefWindowProc(WM_NOTIFY, wParam, (LPARAM)lpnmhdr);
}
LPNMTOOLBAR lpnmtb = (LPNMTOOLBAR) lpnmhdr;
if (lpnmtb != NULL && m_nButtonID == lpnmtb->iItem)
{
OnDropDown(lpnmtb);
return S_OK;
}
return DefWindowProc(WM_NOTIFY, wParam, (LPARAM)lpnmhdr);
}
LRESULT CToolBarParentWnd::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
if (m_pBrowserWndInfo == NULL)
{
return DefWindowProc(uMsg, wParam, lParam);
}
if ((int)wParam == m_nButtonID)
{
if (m_pBrowserWndInfo->nButtonState != TBSTATE_CHECKED)
{
m_pBrowserWndInfo->nButtonState = TBSTATE_CHECKED;
SetButtonCheck(TRUE);
}
else
{
m_pBrowserWndInfo->nButtonState = 0;
SetButtonCheck(FALSE);
}
return S_OK;
}
return DefWindowProc(uMsg, wParam, lParam);
}
void CToolBarParentWnd::SetToolbarWnd(HWND hToolbarWnd)
{
LoadMenu();
m_ToolbarWnd = hToolbarWnd;
}
void CToolBarParentWnd::SetButtonID(int nID)
{
m_nButtonID = nID;
}
int CToolBarParentWnd::GetButtonID()
{
return m_nButtonID;
}
void CToolBarParentWnd::SetBrowserWndInfo(BrowserWndInfo *pBrowserWndInfo)
{
m_pBrowserWndInfo = pBrowserWndInfo;
if (m_pBrowserWndInfo != NULL
&& m_pBrowserWndInfo->nButtonState == TBSTATE_CHECKED
&& m_ToolbarWnd != NULL
&& m_nButtonID != -1)
{
SetButtonCheck(TRUE);
}
}
BrowserWndInfo * CToolBarParentWnd::GetBrowserWndInfo()
{
return m_pBrowserWndInfo;
}
void CToolBarParentWnd::NotifySetButtonInfo(int buttonID)
{
PostMessage(WM_NOTIFY_SETBUTTONINFO, (WPARAM)buttonID, (LPARAM)0);
}
void CToolBarParentWnd::OnDropDown(LPNMTOOLBAR lpnmtb)
{
BOOL bRightAlign = FALSE;
POINT pt;
pt.x = lpnmtb->rcButton.left;
pt.y = lpnmtb->rcButton.bottom;
::ClientToScreen(m_ToolbarWnd, &pt);
RECT rcWorkArea;
SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea,0);
if(rcWorkArea.right-pt.x < 150)
{
bRightAlign = TRUE;
pt.x = lpnmtb->rcButton.right;
pt.y = lpnmtb->rcButton.bottom;
::ClientToScreen(m_ToolbarWnd, &pt);
}
UINT nFlags = TPM_NONOTIFY|TPM_RETURNCMD|TPM_LEFTBUTTON;
if (bRightAlign)
{
nFlags |= TPM_RIGHTALIGN;
}
else
{
nFlags |= TPM_LEFTALIGN;
}
int nCommand = TrackPopupMenu(m_hMemuTrackPopup, nFlags, pt.x, pt.y, 0,
m_pBrowserWndInfo->hBrowserWnd, 0);
switch(nCommand)
{
case ID_POPUP_HELP:
MessageBox(L"Help About", L"DropButton", 0);
break;
case ID_POPUP_UNREG:
MessageBox(L"Uninstall DropButton", L"DropButton", 0);
break;
default:
break;
}
}
void CToolBarParentWnd::SetButtonCheck(BOOL bChecked)
{
SendMessage(m_ToolbarWnd, TB_CHECKBUTTON, m_nButtonID, MAKELONG(bChecked, 0));
}
void CToolBarParentWnd::LoadMenu()
{
HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();
m_hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU_POPUP));
m_hMemuTrackPopup = ::GetSubMenu(m_hMenu, 0);
}
void CToolBarParentWnd::ReleaseMenu()
{
DestroyMenu(m_hMemuTrackPopup);
DestroyMenu(m_hMenu);
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.