Exemplo n.º 1
0
void CApplicationImpl::AddItemWindow(HWND hWnd)
{
	// Calculate position of the new item window.
	CPoint pointTopLeft(0, 0);

	if (m_listItemWindows.empty())
	{
		 CWindow(hWnd).CenterWindow();
		 pointTopLeft = CWindowRect(hWnd).TopLeft();
	}
	else
	{
		CWindowRect rcLast(m_listItemWindows.back().first);
		pointTopLeft.x = max(pointTopLeft.x, rcLast.left);
		pointTopLeft.y = max(pointTopLeft.y, rcLast.top);

		pointTopLeft.Offset(GetSystemMetrics(SM_CYCAPTION), GetSystemMetrics(SM_CYCAPTION));
		CWindowRect rc(hWnd);
		rc.OffsetRect(pointTopLeft);
		CWindowRect rcDesktop(GetDesktopWindow());
		if (!rcDesktop.PtInRect(rc.BottomRight()))
		{
			pointTopLeft.SetPoint(0, 0);
		}
		SetWindowPos(hWnd, NULL, pointTopLeft.x, pointTopLeft.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
	}

	// add to the list
	m_listItemWindows.push_back(std::make_pair(hWnd, pointTopLeft));
}
Exemplo n.º 2
0
void winutils::AdjustScreenRect(CRect& rc)
{
	CWindowRect rcDesktop(::GetDesktopWindow());
	CWindowRect rcTaskBar(::FindWindow(_T("Shell_TrayWnd"), NULL));
	CRect rcDesk;
	rcDesk.SubtractRect(rcDesktop, rcTaskBar);

	if (rc.right > rcDesk.right)
	{
		rc.MoveToX(rcDesk.right - rc.Width());
	}
	if (rc.bottom > rcDesk.bottom)
	{
		rc.MoveToY(rcDesk.bottom - rc.Height());
	}
	if (rc.left < rcDesk.left)
	{
		rc.MoveToX(rcDesk.left);
	}
	if (rc.top < rcDesk.top)
	{
		rc.MoveToY(rcDesk.top);
	}
}
Exemplo n.º 3
0
void CRichToolTipCtrl::OnShow(NMHDR* /*pNMHDR*/, LRESULT* pResult)
{
  *pResult = 0;

  // the control is about to be displayed
  // we can update the edit control, and re-set the text

  // make sure the edit control is using the correct font and colours
  // and make sure we don't have any formatting effects set
  m_edit.SetBackgroundColor(FALSE, GetTipBkColor());
  m_edit.SetWindowText(_T(""));
  CHARFORMAT cf;
  ZeroMemory(&cf, sizeof(CHARFORMAT));
  cf.cbSize = sizeof(CHARFORMAT);
  cf.dwMask = CFM_BOLD | CFM_COLOR | CFM_ITALIC | CFM_PROTECTED | CFM_STRIKEOUT | CFM_UNDERLINE;
  cf.crTextColor = GetTipTextColor();
  m_edit.SetDefaultCharFormat(cf);
  m_edit.SetFont(GetFont());

  CString sText;
  GetWindowText(sText);
  m_edit.StreamTextIn(sText);

  SetWindowText(_T(""));

  // find out how big the tip window should be
  CSize size = CalculateMinimiumRichEditSize();

  // set the tool-tip's drawing rect
  size.cx += 5; // add a few more on, cos we'll use them for a margin later
  size.cy += 5;

  // it seems that if any text is right-aligned, or centered, then
  // it just creeps over the right-hand edge
  // the best we can do to see if it has any right or centre text
  // is to see if the RTF contains "\qr" or "\qc" tags, and add a bit on
  // (we don't cater for text having "\qr" or "\qc" somewhere in it; 
  // in this case we add on the extra anyway. If we cared we could look for 
  // a "\qr" which is not really a "\\qr", but that could be quite expensive)
  int nPos = sText.Find(_T("\\q"));
  if (nPos >= 0 && (sText[nPos + 2] == _T('r') || sText[nPos + 2] == _T('c')))
    size.cx += 5;

  // calc the new tip window size and position, and move it
  CRect rc;
  GetWindowRect(rc);
  // position the tip with its left edge at the mouse's x
  CPoint ptCursor;
  GetCursorPos(&ptCursor);
  rc.left = ptCursor.x;
  rc.top = ptCursor.y + 16;
  // move it to the left if it's going to go off the edge of the screen
  // but don't move it off the left of the current desktop
  int cxScreen = ::GetSystemMetrics(SM_CXSCREEN);
  int cyScreen = ::GetSystemMetrics(SM_CYSCREEN);
  CRect rcDesktop(0, 0, cxScreen, cyScreen);
  // adjust the desktop rect for the monitor that contains the cursor
  if (! rcDesktop.PtInRect(ptCursor))
  {
    HMONITOR hMonitor = MonitorFromPoint(ptCursor, MONITOR_DEFAULTTONEAREST);
    if (hMonitor != NULL)
    {
      MONITORINFO mi;
      mi.cbSize = sizeof(MONITORINFO);
      if (GetMonitorInfo(hMonitor, &mi))
	rcDesktop = mi.rcMonitor;
    }
  }
  if ((size.cx + rc.left) > rcDesktop.Width())
    rc.left = max(rcDesktop.left, rc.left - ((rc.left + size.cx) - rcDesktop.Width()));
  // position it above the mouse if it would go off the bottom of the screen
  // but don't move it off the top of the screen
  if ((size.cy + rc.top) > rcDesktop.Height())
    rc.top = max(rcDesktop.top, (ptCursor.y - 16) - size.cy);
  rc.right = rc.left + (size.cx);
  rc.bottom = rc.top + (size.cy);

  MoveWindow(&rc);
  *pResult = TRUE;  // we've moved it
}