Send notification if another monitor is selected

svn path=/trunk/; revision=29300
This commit is contained in:
Thomas Bluemel 2007-09-29 19:12:21 +00:00
parent e809e77341
commit b595efe8ae
2 changed files with 118 additions and 3 deletions

View file

@ -43,6 +43,54 @@ typedef struct _MONITORSELWND
HBRUSH hbrDisabled;
} MONITORSELWND, *PMONITORSELWND;
static LRESULT
MonSelNotify(IN PMONITORSELWND infoPtr,
IN UINT code,
IN OUT PVOID data)
{
LRESULT Ret = 0;
if (infoPtr->hNotify != NULL)
{
LPNMHDR pnmh = (LPNMHDR)data;
pnmh->hwndFrom = infoPtr->hSelf;
pnmh->idFrom = GetWindowLongPtr(infoPtr->hSelf,
GWLP_ID);
pnmh->code = code;
Ret = SendMessage(infoPtr->hNotify,
WM_NOTIFY,
(WPARAM)pnmh->idFrom,
(LPARAM)pnmh);
}
return Ret;
}
static LRESULT
MonSelNotifyMonitor(IN PMONITORSELWND infoPtr,
IN UINT code,
IN INT Index,
IN OUT PMONSL_MONNMHDR pmonnmh)
{
pmonnmh->Index = Index;
if (Index >= 0)
{
pmonnmh->MonitorInfo = infoPtr->MonitorInfo[Index];
}
else
{
ZeroMemory(&pmonnmh->MonitorInfo,
sizeof(pmonnmh->MonitorInfo));
}
return MonSelNotify(infoPtr,
code,
pmonnmh);
}
static HFONT
MonSelChangeFont(IN OUT PMONITORSELWND infoPtr,
IN HFONT hFont,
@ -450,7 +498,8 @@ MonSelGetMonitorInfo(IN PMONITORSELWND infoPtr,
static BOOL
MonSelSetCurSelMonitor(IN OUT PMONITORSELWND infoPtr,
IN INT Index)
IN INT Index,
IN BOOL bNotify)
{
INT PrevSel;
BOOL PreventSelect = FALSE;
@ -466,6 +515,21 @@ MonSelSetCurSelMonitor(IN OUT PMONITORSELWND infoPtr,
PreventSelect = TRUE;
}
if (!PreventSelect && bNotify)
{
MONSL_MONNMMONITORCHANGING nmi;
nmi.PreviousSelected = infoPtr->SelectedMonitor;
nmi.AllowChanging = TRUE;
MonSelNotifyMonitor(infoPtr,
MSLN_MONITORCHANGING,
Index,
&nmi.hdr);
PreventSelect = (nmi.AllowChanging == FALSE);
}
if (!PreventSelect)
{
PrevSel = infoPtr->SelectedMonitor;
@ -479,6 +543,16 @@ MonSelSetCurSelMonitor(IN OUT PMONITORSELWND infoPtr,
if (infoPtr->SelectedMonitor >= 0)
MonSelRepaintSelected(infoPtr);
if (bNotify)
{
MONSL_MONNMHDR nm;
MonSelNotifyMonitor(infoPtr,
MSLN_MONITORCHANGED,
Index,
&nm);
}
}
}
@ -494,6 +568,7 @@ MonSelCreate(IN OUT PMONITORSELWND infoPtr)
infoPtr->SelectionFrame.cx = infoPtr->SelectionFrame.cy = 4;
infoPtr->Margin.cx = infoPtr->Margin.cy = 20;
infoPtr->SelectedMonitor = -1;
infoPtr->ControlExStyle = MSLM_EX_ALLOWSELECTDISABLED;
return;
}
@ -813,7 +888,8 @@ MonitorSelWndProc(IN HWND hwnd,
if (Index >= 0 || (infoPtr->ControlExStyle & MSLM_EX_ALLOWSELECTNONE))
{
MonSelSetCurSelMonitor(infoPtr,
Index);
Index,
TRUE);
}
/* fall through */
@ -965,7 +1041,8 @@ MonitorSelWndProc(IN HWND hwnd,
case MSLM_SETCURSEL:
{
Ret = MonSelSetCurSelMonitor(infoPtr,
(INT)wParam);
(INT)wParam,
FALSE);
break;
}

View file

@ -16,6 +16,44 @@ typedef struct _MONSL_MONINFO
LPARAM lParam;
} MONSL_MONINFO, *PMONSL_MONINFO;
typedef struct _MONSL_MONNMHDR
{
NMHDR hdr;
INT Index;
/* NOTE: MonitorInfo is only valid if Index >= 0 */
MONSL_MONINFO MonitorInfo;
} MONSL_MONNMHDR, *PMONSL_MONNMHDR;
typedef struct _MONSL_MONNMMONITORCHANGING
{
/* Used with MSLN_MONITORCHANGING */
MONSL_MONNMHDR hdr;
INT PreviousSelected;
BOOL AllowChanging;
} MONSL_MONNMMONITORCHANGING, *PMONSL_MONNMMONITORCHANGING;
/*
* MSLN_MONITORCHANGING
* This notification code is sent through WM_NOTIFY before another monitor
* can be selected. This notification is not sent in response to a
* MSLM_SETCURSEL message.
*
* lParam: PMONSL_MONNMMONITORCHANGING
* Change AllowChanging to FALSE to prevent the new monitor to
* be selected.
*/
#define MSLN_MONITORCHANGING 101
/*
* MSLN_MONITORCHANGED
* This notification code is sent through WM_NOTIFY after a new monitor
* was selected. This notification is not sent in response to a
* MSLM_SETCURSEL message.
*
* lParam: PMONSL_MONNMHDR
*/
#define MSLN_MONITORCHANGED 101
/*
* MSLM_SETMONITORSINFO
* wParam: DWORD