Пример #1
0
LRESULT CALLBACK GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
{
#define msg ((PMSG)lParam)
	if (code == HC_ACTION)
	{
		switch (msg->message)
		{
			case WM_SYSCOMMAND:
			{
				Log("WM_SYSCOMMAND");
				HandleSysCommand(msg->wParam, msg->hwnd);
				break;
			}
		}
	}
		return CallNextHookEx(NULL, code, wParam, lParam);
#undef msg
}
void CXTPSkinObjectFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
    UINT nCmd = (nID & 0xFFF0);

    if ((nCmd == SC_MAXIMIZE) && m_pManager->HasApplyOptions(xtpSkinApplyMetrics | xtpSkinApplyFrame) &&
            ((GetExStyle() & WS_EX_MDICHILD) == WS_EX_MDICHILD) &&
            ((GetStyle() & WS_MAXIMIZE) == 0))
    {
        CXTPSkinObject::OnSysCommand(nID, lParam);

        RECT rc;
        GetParent()->GetClientRect(&rc);
        int cx = rc.right - rc.left;
        int cy = rc.bottom - rc.top;

        rc.left = -m_rcBorders.left;
        rc.top = -m_rcBorders.top;
        rc.right = cx + m_rcBorders.right;
        rc.bottom = cy + m_rcBorders.bottom;

        MoveWindow(rc.left, rc.top,
                   rc.right - rc.left, rc.bottom - rc.top, TRUE);
        return;
    }

    if (HandleSysCommand(nID, lParam))
        return;

    if ((nCmd == SC_MOVE) && (GetStyle() & WS_MINIMIZE) && (GetSkinManager()->GetApplyOptions() & xtpSkinApplyFrame))
    {
        DoDefWindowProc(WM_NCPAINT, 0, 0);
        RedrawFrame();
    }


    CXTPSkinObject::OnSysCommand(nID, lParam);

    if ((nCmd == SC_MINIMIZE) && (GetSkinManager()->GetApplyOptions() & xtpSkinApplyFrame))
    {
        RedrawFrame();
    }
}
Пример #3
0
LRESULT CALLBACK CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
{
#define msg ((PCWPSTRUCT)lParam)
	if (code == HC_ACTION)
	{
		switch (msg->message)
		{
			// I am not sure if this is required, lets leve it in
			case WM_ACTIVATE:
			{
				Log("WM_ACTIVATE");
				GetSystemMenu(msg->hwnd, FALSE);
				break;
			}

			// Populate menu
			case WM_INITMENUPOPUP:
			{
				Log("WM_INITMENUPOPUP");
				AddMenu(msg->hwnd, (HMENU)msg->wParam);
				break;
			}

			// Some applications trigger WM_INITMENUPOPUP never or to late, thats why we use WM_ENTERIDLE
			case WM_ENTERIDLE:
			{
				Log("WM_ENTERIDLE");
				if (msg->wParam == MSGF_MENU)
				{
					AddMenu(msg->hwnd, (HMENU)INVALID_HANDLE_VALUE);
					break;
				}
				break;
			}

			// Remove Entry again
			case WM_UNINITMENUPOPUP:
			{
				Log("WM_UNINITMENUPOPUP");
				RemoveMenu(msg->hwnd, (HMENU)msg->wParam);
				break;
			}

			// For those who doesn't fire WM_UNINITMENUPOPUP 
			case WM_MENUSELECT:
			{
				Log("WM_ENTERIDLE");
				if (msg->lParam == NULL && HIWORD(msg->wParam) == 0xFFFF)
				{
					RemoveMenu(msg->hwnd, (HMENU)INVALID_HANDLE_VALUE);
				}
				break;
			}

			// Do the command
			case WM_SYSCOMMAND:
			{
				Log("WM_SYSCOMMAND %X %X", msg->wParam, msg->hwnd);
				HandleSysCommand(msg->wParam, msg->hwnd);
				break;
			}
		}
	}
	return CallNextHookEx(NULL, code, wParam, lParam);
#undef msg
}
Пример #4
0
void HandleSysCommand(WPARAM wParam, HWND hwnd)
{
	if (wParam == MOVETOMENU_NEW)
	{
		// abort command, too many commands in a short period of time
		if (nLastCommand > GetTickCount64())
		{
			return;
		}
		Log("Getting RootWindow of %X", hwnd);
		HWND rootHwnd = GetAncestor(hwnd, GA_ROOTOWNER);
		if (rootHwnd != NULL)
		{
			hwnd = rootHwnd;
		}

		Log("Moving %X to new", hwnd);
		IVirtualDesktop *pNewDesktop = nullptr;
		HRESULT hr = pDesktopManagerInternal->CreateDesktopW(&pNewDesktop);
		if (FAILED(hr))
		{
			return;
		}
		GUID id;
		hr = pNewDesktop->GetID(&id);
		if (SUCCEEDED(hr))
		{
			HWND focusHwnd = NULL;
			if (!bSwitchDesktopAfterMove)
			{
				focusHwnd = hwnd;
				do
				{
					focusHwnd = GetNextWindow(focusHwnd, GW_HWNDNEXT);
				} while (focusHwnd && EnumWindowsProc(focusHwnd, NULL));
			}

			Log("pDesktopManager->MoveWindowToDesktop(%X, %X)", hwnd, id);
			hr = pDesktopManager->MoveWindowToDesktop(hwnd, id);
			if (SUCCEEDED(hr))
			{
				if (bSwitchDesktopAfterMove)
				{
					pDesktopManagerInternal->SwitchDesktop(pNewDesktop);
				}
				else if (focusHwnd)
				{
					SetForegroundWindow(focusHwnd);
				}
			}
			else
			{
				Log("Error %d on moving %X to %X", hr, hwnd, id);
			}
		}
		pNewDesktop->Release();
		nLastCommand = GetTickCount64() + COMMAND_TIMEOUT;
	}
	else if (wParam >= MOVETOMENU_START && wParam <= MOVETOMENU_LAST)
	{
		// abort command, too many commands in a short period of time
		if (nLastCommand > GetTickCount64())
		{
			return;
		}
		Log("Getting RootWindow of %X", hwnd);
		HWND rootHwnd = GetAncestor(hwnd, GA_ROOTOWNER);
		if (rootHwnd != NULL)
		{
			hwnd = rootHwnd;
		}

		Log("Moving %X to %X", hwnd, wParam);
		IObjectArray *pObjectArray = nullptr;
		HRESULT hr = pDesktopManagerInternal->GetDesktops(&pObjectArray);
		if (FAILED(hr))
		{
			Log("Failed to get desktops for %X", hwnd);
			return;
		}

		IVirtualDesktop *pDesktop = nullptr;
		if (SUCCEEDED(pObjectArray->GetAt((UINT)wParam - MOVETOMENU_START, __uuidof(IVirtualDesktop), (void**)&pDesktop)))
		{
			GUID id;
			hr = pDesktop->GetID(&id);

			if (SUCCEEDED(hr))
			{
				HWND focusHwnd = NULL;
				if (!bSwitchDesktopAfterMove)
				{
					focusHwnd = hwnd;
					do
					{
						focusHwnd = GetNextWindow(focusHwnd, GW_HWNDNEXT);
					} while (focusHwnd && EnumWindowsProc(focusHwnd, NULL));
				}

				Log("pDesktopManager->MoveWindowToDesktop(%X, %X)", hwnd, id);
				hr = pDesktopManager->MoveWindowToDesktop(hwnd, id);
				if (SUCCEEDED(hr))
				{
					// If there are no windows delete the desktop
					if (bDeleteEmptyDesktops)
					{
						IVirtualDesktop *pCurrentDesktop = nullptr;
						hr = pDesktopManagerInternal->GetCurrentDesktop(&pCurrentDesktop);
						if (SUCCEEDED(hr))
						{
							if (pCurrentDesktop != pDesktop)
							{
								if (EnumWindows((WNDENUMPROC)EnumWindowsProc, NULL) != FALSE)
								{
									Log("Removing Desktop");
									pDesktopManagerInternal->RemoveDesktop(pCurrentDesktop, pDesktop);
								}
							}
							pCurrentDesktop->Release();
						}
					}

					if (bSwitchDesktopAfterMove)
					{
						pDesktopManagerInternal->SwitchDesktop(pDesktop);
					}
					else if (focusHwnd != NULL)
					{
						SetForegroundWindow(focusHwnd);
					}
				}
				else
				{
					Log("Error %X on moving %X to %X", hr, hwnd, id);
				}
			}
			pDesktop->Release();
		}
		pObjectArray->Release();
		nLastCommand = GetTickCount64() + COMMAND_TIMEOUT;
	}
	else if (wParam == MOVETOMENU_LEFT)
	{
		UINT count;
		int index = GetCurrentDesktopIndex(&count);
		Log("Current Index is %d", index);
		Log("Current Count is %d", count);
		if (index == -1)
			return;
		if (index == MOVETOMENU_START)
			return;
		Log("Switch to %d", index - 1);
		HandleSysCommand(--index, hwnd);
	}
	else if (wParam == MOVETOMENU_RIGHT)
	{
		UINT count;
		int index = GetCurrentDesktopIndex(&count);
		Log("Current Index is %d", index);
		Log("Current Count is %d", count);
		if (index == -1)
			return;
		if (index == MOVETOMENU_LAST)
			return;
		if ((++index) <= (int)(count + MOVETOMENU_NEW))
		{
			Log("Switch to %d", index);
			HandleSysCommand(index, hwnd);

		}
		else if (bCreateNewDesktopOnMove)
		{
			Log("Create new desktop");
			HandleSysCommand(MOVETOMENU_NEW, hwnd);
		}
	}
}
Пример #5
0
LRESULT CSkinWin::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
{
    if ( !IsWindow(m_hWnd) )
        return 0;
    if ( !m_bInit  ) 
        return Default();
        
    switch ( msg )
    {
    case WM_SHOWWINDOW:
        //call setwindowpos to force OnNcCalcSize when hWnd is a dialog
        if ( wp )
            SetWindowPos( m_hWnd, 0, 0, 0, 400, 400, SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED );
        Default();
        return 0;
        break;
    //case WM_ERASEBKGND:
    case WM_INITMENUPOPUP:
        Default();
        return 0;
    //    return OnEraseBkgnd(CDC::FromHandle((HDC)wp) );
        /*
    case WM_INITMENU:
        //a hack, when popup sysmenu, redraw title bar
        HMENU h;
        h = (HMENU)wp;
        int c;
        h = GetSubMenu(h, 0);
        c = GetMenuItemID( h, 0 );
        if ( c == SC_RESTORE )
        {
            CRect r;
            GetClientRect( m_hWnd, r );
            OnNcPaint(0);
            r.bottom = GetSystemMetrics(SM_CYCAPTION);
            InvalidateRect( m_hWnd, r, TRUE );
            UpdateWindow( m_hWnd );
        }
        Default();
        return 0;
        */
    case WM_SYSCOMMAND:
        OnSysCommand( wp, lp );
        return 0;
    case WM_SETTEXT:
        return OnSetText( wp, lp );
    case WM_NCPAINT:
        OnNcPaint( (HRGN)wp );
        return 0;
    case WM_NCCALCSIZE:
        OnNcCalcSize( (BOOL)wp, (NCCALCSIZE_PARAMS *)lp );
        return 0;
    case WM_SIZE:
        OnSize( wp, LOWORD(lp), HIWORD(lp) );
        return 0;    
    case WM_NCACTIVATE:
        return OnNcActivate( (BOOL)wp );
    case WM_NCHITTEST:
        return OnNcHitTest(CPoint(LOWORD(lp), HIWORD(lp)));
    case WM_NCLBUTTONUP:
        OnNcLButtonUp(wp, CPoint(LOWORD(lp), HIWORD(lp)));
        return 0;
    case WM_NCLBUTTONDOWN:
        OnNcLButtonDown(wp, CPoint(LOWORD(lp), HIWORD(lp)));
        return 0;
   /* case WM_NCLBUTTONDBLCLK:
        OnNcLButtonDblClk(wp, CPoint(LOWORD(lp), HIWORD(lp)));
        return 0;*///liub_modify (去除双击弹出面板的响应事件)
    case WM_NCRBUTTONUP:
        OnNcRButtonUp(wp, CPoint(LOWORD(lp), HIWORD(lp)));
        return 0;
    case WM_NCRBUTTONDOWN:
        OnNcRButtonDown(wp, CPoint(LOWORD(lp), HIWORD(lp)));
        return 0;
    case WM_NCMOUSEMOVE:
        OnNcMouseMove( wp,CPoint(LOWORD(lp), HIWORD(lp)));
        return 0;
    case WM_GETMINMAXINFO:
        OnGetMinMaxInfo( (MINMAXINFO *)lp );
        return 0;
    case WM_WINDOWPOSCHANGING:
        OnWindowPosChanging((WINDOWPOS *)lp);
        return 0;
    case WM_SIZING:
        OnSizing( wp, (LPRECT)lp );
        return 0;
    case WM_ACTIVATE:
        OnActivate( wp, CWnd::FromHandle((HWND)lp), 0 );
        return 0;
    case WM_COMMAND:
        if ( !HandleSysCommand( wp, lp ) )
            Default();
        return 0;

#if 1
		// @@
	case WM_SETCURSOR:
		if (OnHitTestSetCursor(LOWORD(lp)))
			OnNcPaint(0);
		else
			Default();
		return 0;
#endif

    default:
        return Default();
    }
}
// WindowProc handles dispatching of messages and routing back to the base class or to Windows
LRESULT cef_dark_aero_window::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    bool callDefWindowProc = true;

    switch (message) 
    {

    case WM_MEASUREITEM:
        if (HandleMeasureItem((LPMEASUREITEMSTRUCT)lParam))
            return 0L;
        break;
    case WM_DRAWITEM:
        if (HandleDrawItem((LPDRAWITEMSTRUCT)lParam))
            return 0L;
        break;
    case WM_SETICON:
        mWindowIcon = 0;
        {
            RECT rectIcon;
            ComputeWindowIconRect(rectIcon);
            InvalidateRect(&rectIcon);
        }
        break;
    }

    // First let the DesktopWindowManager handler the message and tell us if 
    //  we should pass the message to the default window proc
    LRESULT lr = DwpCustomFrameProc(message, wParam, lParam, &callDefWindowProc);

    switch(message) {
    case WM_SYSCOMMAND:
        if (HandleSysCommand((UINT)wParam)) 
            return 0L;
        break;
    case WM_ACTIVATE:
        if (mReady) {
            UpdateMenuBar();
        }
        break;
    case WM_NCMOUSELEAVE:
        // NOTE: We want anyone else interested in this message
        //          to be notified. Otherwise the default implementation 
        //          may be in the wrong state
        HandleNcMouseLeave();
        break;
    case WM_NCMOUSEMOVE:
        {
            POINT pt;
            POINTSTOPOINT(pt, lParam);

            if (HandleNcMouseMove((UINT)wParam, &pt))
                return 0L;
        }
        break;
    case WM_NCLBUTTONDOWN:
        {
            POINT pt;
            POINTSTOPOINT(pt, lParam);
            if (HandleNcLeftButtonDown((UINT)wParam, &pt))
                return 0L;
        }
        break;
    case WM_NCLBUTTONUP:
        {
            POINT pt;
            POINTSTOPOINT(pt, lParam);
            if (HandleNcLeftButtonUp((UINT)wParam, &pt))
                return 0L;
        }
        break;
    }

    // call DefWindowProc?
    if (!callDefWindowProc) {
        return lr;
    }


    lr = cef_window::WindowProc(message, wParam, lParam);

    if (!mReady)
        return lr;

    switch (message)
    {
    case WM_SETTEXT:
    case WM_WINDOWPOSCHANGING:
    case WM_WINDOWPOSCHANGED:
    case WM_MOVE:
    case WM_SIZE:
    case WM_SIZING:
    case WM_EXITSIZEMOVE:
        UpdateNonClientArea();
        if (message == WM_WINDOWPOSCHANGED) 
        {
            RECT rect;
            ComputeMenuBarRect(rect);
            InvalidateRect(&rect, TRUE);
        }
        break;
    case WM_EXITMENULOOP:
        mMenuActiveIndex = -1;
        break;   
    }

    return lr;
}
Пример #7
0
void HandleSysCommand(WPARAM wParam, HWND hwnd)
{
	if (wParam == MOVETOMENU_NEW)
	{
		Log("Getting RootWindow of %X", hwnd);
		HWND rootHwnd = GetAncestor(hwnd, GA_ROOTOWNER);
		if (rootHwnd != NULL)
		{
			hwnd = rootHwnd;
		}

		Log("Moving %X to new", hwnd);
		IVirtualDesktop *pNewDesktop = nullptr;
		HRESULT hr = pDesktopManagerInternal->CreateDesktopW(&pNewDesktop);
		if (FAILED(hr))
		{
			return;
		}
		GUID id;
		hr = pNewDesktop->GetID(&id);
		if (SUCCEEDED(hr))
		{
			Log("pDesktopManager->MoveWindowToDesktop(%X, %X)", hwnd, id);
			hr = pDesktopManager->MoveWindowToDesktop(hwnd, id);
			if (SUCCEEDED(hr))
			{
				if (bSwitchDesktopAfterMove)
				{
					pDesktopManagerInternal->SwitchDesktop(pNewDesktop);
				}
			}
			else
			{
				Log("Error %d on moving %X to %X", hr, hwnd, id);
			}
		}
		pNewDesktop->Release();
	}
	else if (wParam >= MOVETOMENU_START && wParam <= MOVETOMENU_LAST)
	{
		Log("Getting RootWindow of %X", hwnd);
		HWND rootHwnd = GetAncestor(hwnd, GA_ROOTOWNER);
		if (rootHwnd != NULL)
		{
			hwnd = rootHwnd;
		}

		Log("Moving %X to %X", hwnd, wParam);
		IObjectArray *pObjectArray = nullptr;
		HRESULT hr = pDesktopManagerInternal->GetDesktops(&pObjectArray);
		if (FAILED(hr))
		{
			Log("Failed to get desktops for %X", hwnd);
			return;
		}

		IVirtualDesktop *pDesktop = nullptr;
		if (SUCCEEDED(pObjectArray->GetAt((UINT)wParam - MOVETOMENU_START, __uuidof(IVirtualDesktop), (void**)&pDesktop)))
		{
			GUID id;
			hr = pDesktop->GetID(&id);

			if (SUCCEEDED(hr))
			{
				Log("pDesktopManager->MoveWindowToDesktop(%X, %X)", hwnd, id);
				hr = pDesktopManager->MoveWindowToDesktop(hwnd, id);
				if (SUCCEEDED(hr))
				{
					if (bSwitchDesktopAfterMove)
					{
						pDesktopManagerInternal->SwitchDesktop(pDesktop);
					}
				}
				else
				{
					Log("Error %X on moving %X to %X", hr, hwnd, id);
				}
			}
			pDesktop->Release();
		}
		pObjectArray->Release();
	}
	else if (wParam == MOVETOMENU_LEFT)
	{
		UINT count;
		int index = GetCurrentDesktopIndex(&count);
		Log("Current Index is %d", index);
		Log("Current Count is %d", count);
		if (index == -1)
			return;
		if (index == MOVETOMENU_START)
			return;
		Log("Switch to %d", index - 1);
		HandleSysCommand(--index, hwnd);
	}
	else if (wParam == MOVETOMENU_RIGHT)
	{
		UINT count;
		int index = GetCurrentDesktopIndex(&count);
		Log("Current Index is %d", index);
		Log("Current Count is %d", count);
		if (index == -1)
			return;
		if (index == MOVETOMENU_LAST)
			return;
		if ((++index) <= (int)(count + MOVETOMENU_NEW))
		{
			Log("Switch to %d", index);
			HandleSysCommand(index, hwnd);

		}
		else
		{
			Log("Create new desktop");
			HandleSysCommand(MOVETOMENU_NEW, hwnd);
		}
	}
}