Make the configuration dialog appear near the mouse pointer if

launched from the shell notification icon as requested by Roku's
Anthony Wood.
This commit is contained in:
Mike Crowe 2006-05-30 16:47:12 +00:00
parent aea1b16ddd
commit 94b4883cd2
5 changed files with 69 additions and 10 deletions

View File

@ -77,7 +77,7 @@ int Application::Run(LPCTSTR lpstrCmdLine, int nCmdShow)
EnableServerEvents(true);
if (ShowDialogAtStart(lpstrCmdLine, nCmdShow))
Configure();
Configure(false);
int nRet = theLoop.Run();
@ -100,7 +100,7 @@ void Application::Exit()
::PostQuitMessage(0);
}
void Application::Configure()
void Application::Configure(bool move_window)
{
if (m_dlg)
{
@ -112,7 +112,7 @@ void Application::Configure()
CheckCanConfigure();
// Other people may need to talk to the dialog while it exists.
CMainDlg dlg;
CMainDlg dlg(move_window);
m_dlg = &dlg;
dlg.DoModal();
m_dlg = NULL;

View File

@ -74,8 +74,9 @@ public:
return m_registered_activation_message;
}
// User actions
void Configure();
// Pass true to move the window so it is near the mouse
// cursor.
void Configure(bool move_window);
void Exit();
// Service control

View File

@ -20,7 +20,8 @@
#include "MainDlg.h"
#include "FireflyShell.h"
CMainDlg::CMainDlg()
CMainDlg::CMainDlg(bool move_window)
: m_window_move_required(move_window)
{
this->AddPage(m_pageConfig);
this->AddPage(m_pageAdvanced);
@ -57,3 +58,53 @@ LRESULT CMainDlg::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHand
return result;
}
void CMainDlg::PositionWindow()
{
POINT cursor_pt;
GetCursorPos(&cursor_pt);
CRect desktop_rect;
if (SystemParametersInfo(SPI_GETWORKAREA, 0, &desktop_rect, 0))
{
// Don't put it hard against the edge of the screen or task bar.
desktop_rect.DeflateRect(CSize(4, 4));
CRect window_rect;
GetWindowRect(&window_rect);
// First move the window so that it's middle is at the cursor position.
CPoint pos;
pos.x = cursor_pt.x - window_rect.Width()/2;
pos.y = cursor_pt.y - window_rect.Height()/2;
// Now make that window appear on the work area but in case it doesn't fit prefer to fit the
// top left.
if (pos.x + window_rect.Width() > desktop_rect.right)
pos.x = desktop_rect.right - window_rect.Width();
if (pos.y + window_rect.Height() > desktop_rect.bottom)
pos.y = desktop_rect.bottom - window_rect.Height();
if (pos.x < desktop_rect.left)
pos.x = desktop_rect.left;
if (pos.y < desktop_rect.top)
pos.y = desktop_rect.top;
SetWindowPos(NULL, pos.x, pos.y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
}
}
void CMainDlg::OnMove(CPoint pt)
{
if (m_window_move_required)
{
// We don't want to recurse.
m_window_move_required = false;
PositionWindow();
}
else
{
SetMsgHandled(false);
}
}

View File

@ -32,16 +32,23 @@ class CMainDlg : public CPropertySheetImpl<CMainDlg>
CAdvancedPage m_pageAdvanced;
CLogPage m_pageLog;
CAboutPage m_pageAbout;
bool m_window_move_required;
BEGIN_MSG_MAP(CMainDlg)
MESSAGE_HANDLER(WM_COMMAND, OnCommand)
MSG_WM_MOVE(OnMove)
CHAIN_MSG_MAP(base)
END_MSG_MAP()
LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
void OnMove(CPoint);
void PositionWindow();
public:
CMainDlg();
// Pass true if you want the window to be moved to near the mouse pointer.
// This is usually only the case if the window is displayed as a result of
// clicking on the shell notification icon.
CMainDlg(bool move_window);
};
#endif // MAINDLG_H

View File

@ -139,7 +139,7 @@ LRESULT CNotifyIcon::OnNotifyIconMessage(UINT uMsg, WPARAM wParam, LPARAM lParam
switch (lParam)
{
case WM_LBUTTONDBLCLK:
GetApplication()->Configure();
GetApplication()->Configure(true);
bHandled = true;
return 0L;
case WM_RBUTTONDOWN:
@ -175,7 +175,7 @@ void CNotifyIcon::OnContextMenu()
LRESULT CNotifyIcon::OnConfigure(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
GetApplication()->Configure();
GetApplication()->Configure(true);
return 0;
}
@ -190,7 +190,7 @@ LRESULT CNotifyIcon::OnRegisteredActivation(UINT, WPARAM, LPARAM, BOOL &bHandled
{
ATLTRACE(_T("Activate\n"));
bHandled = true;
GetApplication()->Configure();
GetApplication()->Configure(false);
// We return a magic number so that the caller knows we've been found
// and can give up.