97 virtual bool Start(
void) = NULL;
102 virtual void Stop(
void) = NULL;
282 ::SetRectEmpty(&m_in.m_corsorRect);
292 m_in.m_pListener = P;
306 m_pWatcher = pWatcher;
308 if ( ! m_in.m_cursorImage.IsNull() )
310 m_in.m_hParent = hParent;
311 if ( m_pWatcher->
Start() )
314 m_in.m_cursores.SetSize(len);
317 if ( ! m_in.CheckIndex(i) )
336 if ( m_pWatcher != NULL )
339 m_in.m_cursores.RemoveAll();
356 m_in.m_cursorImage = bmp;
357 m_in.m_cursorMaskColor = color;
358 m_in.m_cursorHotspot.x = hotspotX;
359 m_in.m_cursorHotspot.y = hotspotY;
360 return ! m_in.m_cursorImage.IsNull();
389 if ( m_IconToBitmap(bmp, hotspot, hCursor, color) )
391 m_in.m_cursorImage = bmp;
392 m_in.m_cursorMaskColor = color;
393 m_in.m_cursorHotspot = hotspot;
394 return ! m_in.m_cursorImage.IsNull();
407 return m_in.m_cursores.GetSize();
419 return (m_RefCursorManager(index) != NULL);
435 CCursorManager* P = m_GetCursorManager(index);
438 POINT po = { hotspotX, hotspotY };
439 return P->SetImage(bmp, color, po);
466 bool SetCursorImage(INDEX index, HCURSOR hCursor, COLORREF color = RGB(255, 0, 255))
469 CCursorManager* P = m_GetCursorManager(index);
474 if ( m_IconToBitmap(bmp, hotspot, hCursor, color) )
476 return P->SetImage(bmp, color, hotspot);
492 CCursorManager* P = m_GetCursorManager(index);
511 CCursorManager* P = m_GetCursorManager(index);
531 CCursorManager* P = m_GetCursorManager(index);
534 return P->SetPos(x, y);
548 const CCursorManager* P = m_RefCursorManager(index);
566 const CCursorManager* P = m_RefCursorManager(index);
569 return P->GetButtonState();
584 CCursorWindow(
void) : m_rgn(NULL), m_isChild(false)
593 bool HasCursorImage(
void)
const
595 return ! m_image.IsEmpty();
601 bool Create(HWND hParent)
603 if ( HasCursorImage() )
606 DWORD style = WS_POPUP;
607 HWND hWnd = HWND_TOPMOST;
608 if ( hParent != NULL )
614 HWND hFocus = ::GetFocus();
615 CStr className =
"TNBLIB:MultiMouseMan_";
616 if ( m_win.Create(
this, NULL, className, style, NULL, hParent) )
618 m_win.ModifyStyleEx(0, WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE | WS_EX_TOPMOST);
621 m_win.ModifyStyleEx(0, WS_EX_LAYERED);
622 ::SetLayeredWindowAttributes(m_win, RGB(0, 0, 0), 0, 0);
625 const SIZE& sz = m_image.GetSize();
626 ::SetWindowPos(m_win, hWnd, 0, 0, sz.cx, sz.cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS);
627 HRGN rgn = ::CreateRectRgn(0, 0, 0, 0);
628 ::CombineRgn(rgn, m_rgn, NULL, RGN_COPY);
629 ::SetWindowRgn(m_win, rgn, TRUE);
638 void Move(
int x,
int y)
640 if ( ::IsWindow(m_win) )
642 HWND hWnd = HWND_TOPMOST;
643 UINT flags = SWP_NOSIZE | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS;
647 flags |= SWP_NOZORDER;
649 ::SetWindowPos(m_win, hWnd, x - m_hotspot.x, y - m_hotspot.y, 0, 0, flags);
653 bool SetImage(
CBitmapHandle bmp, COLORREF color,
const POINT& hotspot)
655 if ( m_image.Set(bmp) )
658 m_rgn = m_image.CreateRgn(color);
660 if ( ::IsWindow(m_win) )
662 const SIZE& sz = m_image.GetSize();
663 ::SetWindowPos(m_win, NULL, 0, 0, sz.cx, sz.cy, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS);
664 HRGN rgn = ::CreateRectRgn(0, 0, 0, 0);
665 ::CombineRgn(rgn, m_rgn, NULL, RGN_COPY);
666 ::SetWindowRgn(m_win, rgn, TRUE);
667 ::InvalidateRgn(m_win, m_rgn, TRUE);
674 void Show(
bool isShow)
676 ::ShowWindow(m_win, isShow ? SW_SHOW : SW_HIDE);
680 virtual bool OnWindowMessage(LRESULT& _result, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
682 if ( message == WM_SETFOCUS )
684 ::SetFocus(
reinterpret_cast<HWND
>(wParam));
687 else if ( message == WM_PAINT )
690 HDC dc = ::BeginPaint(hWnd, &ps);
691 ::SelectClipRgn(dc, m_rgn);
692 m_image.Draw(dc, 0, 0);
693 ::EndPaint(hWnd, &ps);
696 else if ( message == WM_DESTROY )
703 void m_DeleteRgn(
void)
707 _DeleteObject(m_rgn);
726 CCursorManager(
void) : m_button(0), m_hRgn(NULL)
731 bool Create(HWND hParent,
CBitmapHandle bmp, COLORREF color,
const POINT& hotspot)
735 if ( m_win.SetImage(bmp, color, hotspot) )
738 if ( hParent != NULL )
741 ::GetClientRect(hParent, &rc);
748 ::EnumDisplayMonitors(NULL, NULL, ms_MonitorEnumProc,
reinterpret_cast<LPARAM
>(
this));
750 return m_win.Create(hParent);
755 bool SetImage(
CBitmapHandle bmp, COLORREF color,
const POINT& hotspot)
757 return m_win.SetImage(bmp, color, hotspot);
760 void Show(
bool isShow)
765 void Clip(
const RECT& rect)
767 if ( m_hRgn != NULL )
769 _DeleteObject(m_hRgn);
771 m_hRgn = ::CreateRectRgnIndirect(&rect);
774 bool SetPos(
int x,
int y)
776 if ( m_hRgn != NULL && ! ::PtInRegion(m_hRgn, x, y) )
780 if ( ::PtInRegion(m_hRgn, m_pos.x, y) )
783 int f = (m_pos.x > x) ? 1 : -1;
784 loop ( i, abs(m_pos.x - x) )
787 if ( ::PtInRegion(m_hRgn, x, y) )
794 else if ( ::PtInRegion(m_hRgn, x, m_pos.y) )
797 int f = (m_pos.y > y) ? 1 : -1;
798 loop ( i, abs(m_pos.y - y) )
801 if ( ::PtInRegion(m_hRgn, x, y) )
811 int f = (m_pos.y > y) ? 1 : -1;
812 loop ( i, abs(m_pos.y - y) )
815 if ( ::PtInRegion(m_hRgn, m_pos.x, y) )
821 f = (m_pos.x > x) ? 1 : -1;
822 loop ( i, abs(m_pos.x - x) )
825 if ( ::PtInRegion(m_hRgn, x, y) )
837 if ( m_pos.x != x || m_pos.y != y )
841 m_win.Move(m_pos.x, m_pos.y);
847 bool MovePos(
int dx,
int dy)
849 return SetPos(m_pos.x + dx, m_pos.y + dy);
852 const POINT& GetPos(
void)
const
862 void SetButtonFlags(WORD buttonFlags)
866 if ( (buttonFlags &
_BIT(i)) != 0 )
870 m_button |=
_BIT(i / 2);
874 m_button &= ~_BIT(i / 2);
882 static BOOL CALLBACK ms_MonitorEnumProc(
883 HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
885 CCursorManager* P =
reinterpret_cast<CCursorManager*
>(dwData);
886 HRGN& r1 = P->m_hRgn;
887 HRGN r2 = ::CreateRectRgnIndirect(lprcMonitor);
888 VERIFY( ::CombineRgn(r1, r1, r2, RGN_OR) != ERROR );
904 CInner(
void) : m_pListener(NULL)
911 bool CheckIndex(INDEX index)
913 if ( ! m_cursores.IsInRange(index) )
915 m_cursores.SetSize(index + 1);
917 if ( m_cursores[index] == NULL )
919 CCursorManager* P =
new CCursorManager;
920 if ( ! P->Create(m_hParent, m_cursorImage, m_cursorMaskColor, m_cursorHotspot) )
922 _GetLastError(
"CreateWindow");
926 if ( ! ::IsRectEmpty(&m_corsorRect) )
928 P->Clip(m_corsorRect);
930 m_cursores.Set(index, P);
935 virtual void OnMultiMouseEvent(INDEX index,
const RAWMOUSE& mouse)
938 if ( m_pListener != NULL )
940 m_pListener->OnMultiMouseEvent(index, mouse);
942 CCursorManager* P = m_cursores[index];
948 const POINT& po = P->GetPos();
949 P->SetButtonFlags(mouse.usButtonFlags);
950 if ( P->MovePos(mouse.lLastX, mouse.lLastY) )
953 if ( m_pListener != NULL )
955 m_pListener->OnMultiMouseMove(index, P->GetButtonState(), po.x, po.y);
958 if ( m_pListener != NULL )
960 if ( (mouse.usButtonFlags & RI_MOUSE_WHEEL) != 0 )
962 short d = mouse.usButtonData;
963 m_pListener->OnMultiMouseWheel(index, d);
967 if ( (mouse.usButtonFlags &
_BIT(i)) != 0 )
980 virtual void OnMultiMouseDevice(INDEX index, EDevice device)
983 if ( device == Device_Remove )
985 if ( m_pListener != NULL )
987 m_pListener->OnMultiMouseDevice(index, device);
991 if ( ! CheckIndex(index) )
995 if ( m_pListener != NULL )
997 m_pListener->OnMultiMouseDevice(index, device);
1000 IParentListener* m_pListener;
1004 COLORREF m_cursorMaskColor;
1005 POINT m_cursorHotspot;
1011 bool m_IconToBitmap(
CBitmapHandle& _bmp, POINT& _hotspot, HCURSOR hCursor, COLORREF color)
1014 if ( ::GetIconInfo(hCursor, &ii) )
1016 HBITMAP h = ii.hbmColor;
1022 if ( ::GetObject(h,
sizeof(BITMAP), &bm) > 0 )
1025 bi.
Set(bm.bmWidth, bm.bmHeight, color);
1026 HDC dc = bi.
GetDC();
1027 ::DrawIconEx(dc, 0, 0, hCursor, 0, 0, 0, NULL, DI_NORMAL);
1030 _hotspot.x = ii.xHotspot;
1031 _hotspot.y = ii.yHotspot;
1039 const CCursorManager* m_RefCursorManager(INDEX index)
const
1041 if ( m_in.m_cursores.IsInRange(index) )
1043 return m_in.m_cursores[index];
1049 CCursorManager* m_GetCursorManager(INDEX index)
1051 m_in.CheckIndex(index);
1052 return m_in.m_cursores[index];
#define loop(VAR, CNT)
loop構文.
HDC GetDC(void)
[取得]デバイスコンテキストハンドル取得.
bool Set(int cx, int cy, COLORREF color=CLR_INVALID)
[設定] イメージ設定.
bool ReleaseDC(void)
[設定] デバイスコンテキストハンドル返却.
bool SetCursorImage(INDEX index, HCURSOR hCursor, COLORREF color=RGB(255, 0, 255))
[設定] カーソルイメージ設定.
void SetListener(IListener *P)
[登録] リスナー登録.
CMultiMouseManager(void)
コンストラクタ
bool SetCursorPos(INDEX index, int x, int y)
[設定] カーソル位置設定.
bool SetDefaultCursorImage(int hotspotX, int hotspotY, CBitmapHandle bmp, COLORREF color=CLR_AUTOSELECT)
[設定] デフォルトカーソルイメージ設定.
bool ShowCursor(INDEX index, bool isShow)
[表示] カーソル表示.
bool SetDefaultCursorImage(CBitmapHandle bmp, COLORREF color=CLR_AUTOSELECT)
[設定] デフォルトカーソルイメージ設定.
bool SetDefaultCursorImage(HCURSOR hCursor, COLORREF color=RGB(255, 0, 255))
[設定] デフォルトカーソルイメージ設定.
POINT GetCursorPos(INDEX index) const
[取得] カーソル位置取得.
BYTE GetButtonState(INDEX index) const
[取得] ボタン状態取得.
size_t GetMouseCount(void) const
[取得] マウス数取得.
bool ClipCursor(INDEX index, const RECT &rect)
[設定] カーソル稼動範囲設定.
bool IsValid(INDEX index) const
[確認] マウス有効確認.
bool SetCursorImage(INDEX index, CBitmapHandle bmp, COLORREF color=CLR_AUTOSELECT)
[設定] カーソルイメージ設定.
bool Start(IMultiMouseWatcher *pWatcher, HWND hParent=NULL)
[設定] 開始.
bool SetCursorImage(INDEX index, int hotspotX, int hotspotY, CBitmapHandle bmp, COLORREF color=CLR_AUTOSELECT)
[設定] カーソルイメージ設定.
#define EXCLUSIVE(CLS)
簡易排他制御マクロ.
void Zero(V &value)
[設定] ゼロクリア.
virtual void OnMultiMouseDevice(INDEX index, EDevice device)=0
[通知] デバイス変化通知.
virtual void OnMultiMouseMove(INDEX index, BYTE buttonFlags, int x, int y)=0
[通知] 移動通知.
virtual ~IListener(void)
デストラクタ
static DWORD MakeMouseEventFlags(EButton button, EEvent event)
[作成] マウスイベントフラグ作成.
virtual void OnMultiMouseWheel(INDEX index, int d)=0
[通知] ホイール通知.
virtual void OnMultiMouseButton(INDEX index, EButton button, EEvent event, int x, int y)=0
[通知] ボタン通知.
virtual void OnMultiMouseEvent(INDEX index, const RAWMOUSE &mouse)
[通知] イベント通知.
virtual void OnMultiMouseDevice(INDEX index, EDevice device)=0
[通知] デバイス変化通知.
virtual void OnMultiMouseEvent(INDEX index, const RAWMOUSE &mouse)=0
[通知] イベント通知.
virtual ~IListener(void)
デストラクタ
virtual void Stop(void)
[設定] 監視停止.
virtual void SetListener(IListener *P)
[登録] リスナー登録.
virtual size_t GetMouseCount(void) const
[取得] マウス数取得.
virtual bool Start(void)
[設定] 監視開始.