//鼠标消息
VOID CPasswordKeyboard::OnLButtonUp(UINT nFlags, CPoint Point)
{
	__super::OnLButtonUp(nFlags,Point);

	//取消捕获
	if (m_bMouseDown==true)
	{
		//取消捕获
		ReleaseCapture();

		//设置变量
		m_bMouseDown=false;

		//获取光标
		CPoint MousePoint;
		GetCursorPos(&MousePoint);
		ScreenToClient(&MousePoint);

		//更新位置
		WORD wHoverRow=m_wHoverRow;
		WORD wHoverLine=m_wHoverLine;
		SetCurrentStation(MousePoint);

		//点击处理
		if ((m_wHoverRow==wHoverRow)&&(m_wHoverLine==wHoverLine))
		{
			//关闭按钮
			if ((m_wHoverLine==LINE_FUNCTION)&&(m_wHoverRow==ROW_CLOSE_KEY))
			{
				//设置焦点
				CONTAINING_RECORD(this,CPasswordControl,m_PasswordKeyboard)->m_edPassword.SetFocus();

				//销毁窗口
				DestroyWindow();

				return;
			}

			//虚拟编码
			WORD wViraulCode=GetVirualKeyCode(m_wHoverLine,m_wHoverRow);

			//按钮处理
			switch (wViraulCode)
			{
			case VK_SHIFT:		//切换按钮
				{
					//设置变量
					m_bShiftStatus=!m_bShiftStatus;

					break;
				}
			case VK_CAPITAL:	//大写按钮
				{
					//变量定义
					INPUT Input[2];
					ZeroMemory(Input,sizeof(Input));

					//设置变量
					Input[1].ki.dwFlags=KEYEVENTF_KEYUP;   
					Input[0].type=Input[1].type=INPUT_KEYBOARD;
					Input[0].ki.wVk=Input[1].ki.wVk=wViraulCode;

					//模拟输入
					SendInput(CountArray(Input),Input,sizeof(INPUT));

					break;
				}
			default:			//默认按钮
				{
					//设置变量
					m_bShiftStatus=(GetKeyState(VK_SHIFT)&0xF0)>0;

					//发送消息
					CPasswordControl * pPasswordControl=CONTAINING_RECORD(this,CPasswordControl,m_PasswordKeyboard);
					if (pPasswordControl!=NULL) pPasswordControl->m_edPassword.SendMessage(WM_CHAR,wViraulCode,0L);

					break;
				}
			}
		}

		//更新界面
		RedrawWindow(NULL,NULL,RDW_FRAME|RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASENOW);
	}

	return;
}
Exemple #2
0
LRESULT CALLBACK
winWindowProc (HWND hwnd, UINT message, 
	       WPARAM wParam, LPARAM lParam)
{
  static winPrivScreenPtr	s_pScreenPriv = NULL;
  static winScreenInfo		*s_pScreenInfo = NULL;
  static ScreenPtr		s_pScreen = NULL;
  static HWND			s_hwndLastPrivates = NULL;
  static HINSTANCE		s_hInstance;
  static Bool			s_fTracking = FALSE;
  static unsigned long		s_ulServerGeneration = 0;
  static UINT			s_uTaskbarRestart = 0;
  int				iScanCode;
  int				i;

#if CYGDEBUG
  winDebugWin32Message("winWindowProc", hwnd, message, wParam, lParam);
#endif
  
  /* Watch for server regeneration */
  if (g_ulServerGeneration != s_ulServerGeneration)
    {
      /* Store new server generation */
      s_ulServerGeneration = g_ulServerGeneration;
    }

  /* Only retrieve new privates pointers if window handle is null or changed */
  if ((s_pScreenPriv == NULL || hwnd != s_hwndLastPrivates)
      && (s_pScreenPriv = GetProp (hwnd, WIN_SCR_PROP)) != NULL)
    {
#if CYGDEBUG
      winDebug ("winWindowProc - Setting privates handle\n");
#endif
      s_pScreenInfo = s_pScreenPriv->pScreenInfo;
      s_pScreen = s_pScreenInfo->pScreen;
      s_hwndLastPrivates = hwnd;
    }
  else if (s_pScreenPriv == NULL)
    {
      /* For safety, handle case that should never happen */
      s_pScreenInfo = NULL;
      s_pScreen = NULL;
      s_hwndLastPrivates = NULL;
    }

  /* Branch on message type */
  switch (message)
    {
    case WM_TRAYICON:
      return winHandleIconMessage (hwnd, message, wParam, lParam,
				   s_pScreenPriv);

    case WM_CREATE:
#if CYGDEBUG
      winDebug ("winWindowProc - WM_CREATE\n");
#endif
      
      /*
       * Add a property to our display window that references
       * this screens' privates.
       *
       * This allows the window procedure to refer to the
       * appropriate window DC and shadow DC for the window that
       * it is processing.  We use this to repaint exposed
       * areas of our display window.
       */
      s_pScreenPriv = ((LPCREATESTRUCT) lParam)->lpCreateParams;
      s_hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
      s_pScreenInfo = s_pScreenPriv->pScreenInfo;
      s_pScreen = s_pScreenInfo->pScreen;
      s_hwndLastPrivates = hwnd;
      s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
      SetProp (hwnd, WIN_SCR_PROP, s_pScreenPriv);

      /* Setup tray icon */
      if (!s_pScreenInfo->fNoTrayIcon)
	{
	  /*
	   * NOTE: The WM_CREATE message is processed before CreateWindowEx
	   * returns, so s_pScreenPriv->hwndScreen is invalid at this point.
	   * We go ahead and copy our hwnd parameter over top of the screen
	   * privates hwndScreen so that we have a valid value for
	   * that member.  Otherwise, the tray icon will disappear
	   * the first time you move the mouse over top of it.
	   */
	  
	  s_pScreenPriv->hwndScreen = hwnd;

	  winInitNotifyIcon (s_pScreenPriv);
	}
      return 0;

    case WM_DISPLAYCHANGE:
      /*
        WM_DISPLAYCHANGE seems to be sent when the monitor layout or
        any monitor's resolution or depth changes, but it's lParam and
        wParam always indicate the resolution and bpp for the primary
        monitor (so ignore that as we could be on any monitor...)
       */

      /* We cannot handle a display mode change during initialization */
      if (s_pScreenInfo == NULL)
	FatalError ("winWindowProc - WM_DISPLAYCHANGE - The display "
		    "mode changed while we were intializing.  This is "
		    "very bad and unexpected.  Exiting.\n");

      /*
       * We do not care about display changes with
       * fullscreen DirectDraw engines, because those engines set
       * their own mode when they become active.
       */
      if (s_pScreenInfo->fFullScreen
	  && (s_pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD
	      || s_pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL
#ifdef XWIN_PRIMARYFB
	      || s_pScreenInfo->dwEngine == WIN_SERVER_PRIMARY_DD
#endif
	      ))
	{
	  break;
	}

      ErrorF ("winWindowProc - WM_DISPLAYCHANGE - new width: %d "
	      "new height: %d new bpp: %d\n",
	      LOWORD (lParam), HIWORD (lParam), wParam);

      /* 0 bpp has no defined meaning, ignore this message */
      if (wParam == 0)
        break;

      /*
       * Check for a disruptive change in depth.
       * We can only display a message for a disruptive depth change,
       * we cannot do anything to correct the situation.
       */
      /*
        XXX: maybe we need to check if GetSystemMetrics(SM_SAMEDISPLAYFORMAT)
        has changed as well...
      */
      if (s_pScreenInfo->dwBPP != GetDeviceCaps (s_pScreenPriv->hdcScreen, BITSPIXEL))
        {
          if ((s_pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD
               || s_pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL
#ifdef XWIN_PRIMARYFB
               || s_pScreenInfo->dwEngine == WIN_SERVER_PRIMARY_DD
#endif
               ))
            {
              /* Cannot display the visual until the depth is restored */
              ErrorF ("winWindowProc - Disruptive change in depth\n");

              /* Display depth change dialog */
              winDisplayDepthChangeDialog (s_pScreenPriv);

              /* Flag that we have an invalid screen depth */
              s_pScreenPriv->fBadDepth = TRUE;

              /* Minimize the display window */
              ShowWindow (hwnd, SW_MINIMIZE);
            }
          else
            {
              /* For GDI, performance may suffer until original depth is restored */
              ErrorF ("winWindowProc - Performance may be non-optimal after change in depth\n");
            }
        }
      else
        {
          /* Flag that we have a valid screen depth */
          s_pScreenPriv->fBadDepth = FALSE;
        }

      /*
        If we could cheaply check if this WM_DISPLAYCHANGE change
        affects the monitor(s) which this X screen is displayed on
        then we should do so here.  For the moment, assume it does.
        (this is probably usually the case so that might be an
        overoptimization)
      */
	{
	  /*
             In rootless modes which are monitor or virtual desktop size
             use RandR to resize the X screen
          */
          if ((!s_pScreenInfo->fUserGaveHeightAndWidth) &&
              (s_pScreenInfo->iResizeMode == resizeWithRandr) &&
              (FALSE
#ifdef XWIN_MULTIWINDOWEXTWM
               || s_pScreenInfo->fMWExtWM
#endif
               || s_pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOW
               || s_pScreenInfo->fMultiWindow
#endif
               ))
	    {
              DWORD dwWidth, dwHeight;

              if (s_pScreenInfo->fMultipleMonitors)
                {
                  /* resize to new virtual desktop size */
                  dwWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
                  dwHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
                }
              else
                {
                  /* resize to new size of specified monitor */
                  struct GetMonitorInfoData data;
                  if (QueryMonitor(s_pScreenInfo->iMonitor, &data))
                    {
                      if (data.bMonitorSpecifiedExists == TRUE)
                        {
                          dwWidth = data.monitorWidth;
                          dwHeight = data.monitorHeight;
                          /*
                             XXX: monitor may have changed position,
                             so we might need to update xinerama data
                          */
                        }
                      else
                        {
                          ErrorF ("Monitor number %d no longer exists!\n", s_pScreenInfo->iMonitor);
                        }
                    }
                }

              /*
                XXX: probably a small bug here: we don't compute the work area
                and allow for task bar

                XXX: generally, we don't allow for the task bar being moved after
                the server is started
               */

              /* Set screen size to match new size, if it is different to current */
              if ((s_pScreenInfo->dwWidth != dwWidth) ||
                  (s_pScreenInfo->dwHeight != dwHeight))
                {
                  winDoRandRScreenSetSize(s_pScreen,
                                          dwWidth,
                                          dwHeight,
                                          (dwWidth * 25.4) / monitorResolution,
                                          (dwHeight * 25.4) / monitorResolution);
                }
	    }
          else
            {
              /*
               * We can simply recreate the same-sized primary surface when
               * the display dimensions change.
               */

              /*
               * NOTE: The non-DirectDraw engines set the ReleasePrimarySurface
               * and CreatePrimarySurface function pointers to point
               * to the no operation function, NoopDDA.  This allows us
               * to blindly call these functions, even if they are not
               * relevant to the current engine (e.g., Shadow GDI).
               */

              winDebug ("winWindowProc - WM_DISPLAYCHANGE - Releasing and recreating primary surface\n");

              /* Release the old primary surface */
              (*s_pScreenPriv->pwinReleasePrimarySurface) (s_pScreen);

              /* Create the new primary surface */
              (*s_pScreenPriv->pwinCreatePrimarySurface) (s_pScreen);
            }
	}

      break;

    case WM_SIZE:
      {
	SCROLLINFO		si;
	RECT			rcWindow;
	int			iWidth, iHeight;

#if CYGDEBUG
	winDebug ("winWindowProc - WM_SIZE\n");
#endif

	/* Break if we do not allow resizing */
	if ((s_pScreenInfo->iResizeMode == notAllowed)
	    || !s_pScreenInfo->fDecoration
#ifdef XWIN_MULTIWINDOWEXTWM
	    || s_pScreenInfo->fMWExtWM
#endif
	    || s_pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOW
	    || s_pScreenInfo->fMultiWindow
#endif
	    || s_pScreenInfo->fFullScreen)
	  break;

	/* No need to resize if we get minimized */
	if (wParam == SIZE_MINIMIZED)
	  return 0;

        ErrorF ("winWindowProc - WM_SIZE - new client area w: %d h: %d\n",
                LOWORD (lParam), HIWORD (lParam));

        if (s_pScreenInfo->iResizeMode == resizeWithRandr)
          {
            /* Actual resizing is done on WM_EXITSIZEMOVE */
            return 0;
          }

        /* Otherwise iResizeMode == resizeWithScrollbars */

	/*
	 * Get the size of the whole window, including client area,
	 * scrollbars, and non-client area decorations (caption, borders).
	 * We do this because we need to check if the client area
	 * without scrollbars is large enough to display the whole visual.
	 * The new client area size passed by lParam already subtracts
	 * the size of the scrollbars if they are currently displayed.
	 * So checking is LOWORD(lParam) == visual_width and
	 * HIWORD(lParam) == visual_height will never tell us to hide
	 * the scrollbars because the client area would always be too small.
	 * GetClientRect returns the same sizes given by lParam, so we
	 * cannot use GetClientRect either.
	 */
	GetWindowRect (hwnd, &rcWindow);
	iWidth = rcWindow.right - rcWindow.left;
	iHeight = rcWindow.bottom - rcWindow.top;

	/* Subtract the frame size from the window size. */
	iWidth -= 2 * GetSystemMetrics (SM_CXSIZEFRAME);
	iHeight -= (2 * GetSystemMetrics (SM_CYSIZEFRAME)
		    + GetSystemMetrics (SM_CYCAPTION));

	/*
	 * Update scrollbar page sizes.
	 * NOTE: If page size == range, then the scrollbar is
	 * automatically hidden.
	 */

	/* Is the naked client area large enough to show the whole visual? */
	if (iWidth < s_pScreenInfo->dwWidth
	    || iHeight < s_pScreenInfo->dwHeight)
	  {
	    /* Client area too small to display visual, use scrollbars */
	    iWidth -= GetSystemMetrics (SM_CXVSCROLL);
	    iHeight -= GetSystemMetrics (SM_CYHSCROLL);
	  }
	
	/* Set the horizontal scrollbar page size */
	si.cbSize = sizeof (si);
	si.fMask = SIF_PAGE | SIF_RANGE;
	si.nMin = 0;
	si.nMax = s_pScreenInfo->dwWidth - 1;
	si.nPage = iWidth;
	SetScrollInfo (hwnd, SB_HORZ, &si, TRUE);
	
	/* Set the vertical scrollbar page size */
	si.cbSize = sizeof (si);
	si.fMask = SIF_PAGE | SIF_RANGE;
	si.nMin = 0;
	si.nMax = s_pScreenInfo->dwHeight - 1;
	si.nPage = iHeight;
	SetScrollInfo (hwnd, SB_VERT, &si, TRUE);

	/*
	 * NOTE: Scrollbars may have moved if they were at the 
	 * far right/bottom, so we query their current position.
	 */
	
	/* Get the horizontal scrollbar position and set the offset */
	si.cbSize = sizeof (si);
	si.fMask = SIF_POS;
	GetScrollInfo (hwnd, SB_HORZ, &si);
	s_pScreenInfo->dwXOffset = -si.nPos;
	
	/* Get the vertical scrollbar position and set the offset */
	si.cbSize = sizeof (si);
	si.fMask = SIF_POS;
	GetScrollInfo (hwnd, SB_VERT, &si);
	s_pScreenInfo->dwYOffset = -si.nPos;
      }
      return 0;

    case WM_ENTERSIZEMOVE:
      ErrorF("winWindowProc - WM_ENTERSIZEMOVE\n");
      break;

    case WM_EXITSIZEMOVE:
      ErrorF("winWindowProc - WM_EXITSIZEMOVE\n");

      if (s_pScreenInfo->iResizeMode == resizeWithRandr)
        {
          /* Set screen size to match new client area, if it is different to current */
          RECT rcClient;
          DWORD dwWidth, dwHeight;

          GetClientRect (hwnd, &rcClient);
          dwWidth = rcClient.right - rcClient.left;
          dwHeight = rcClient.bottom - rcClient.top;

          if ((s_pScreenInfo->dwWidth != dwWidth) ||
              (s_pScreenInfo->dwHeight != dwHeight))
            {
              /* mm = dots * (25.4 mm / inch) / (dots / inch) */
              winDoRandRScreenSetSize(s_pScreen,
                                      dwWidth,
                                      dwHeight,
                                      (dwWidth * 25.4) / monitorResolution,
                                      (dwHeight * 25.4) / monitorResolution);
            }
        }

      break;

    case WM_VSCROLL:
      {
	SCROLLINFO		si;
	int			iVertPos;

#if CYGDEBUG
	winDebug ("winWindowProc - WM_VSCROLL\n");
#endif
      
	/* Get vertical scroll bar info */
	si.cbSize = sizeof (si);
	si.fMask = SIF_ALL;
	GetScrollInfo (hwnd, SB_VERT, &si);

	/* Save the vertical position for comparison later */
	iVertPos = si.nPos;

	/*
	 * Don't forget:
	 * moving the scrollbar to the DOWN, scroll the content UP
	 */
	switch (LOWORD(wParam))
	  {
	  case SB_TOP:
	    si.nPos = si.nMin;
	    break;
	  
	  case SB_BOTTOM:
	    si.nPos = si.nMax - si.nPage + 1;
	    break;

	  case SB_LINEUP:
	    si.nPos -= 1;
	    break;
	  
	  case SB_LINEDOWN:
	    si.nPos += 1;
	    break;
	  
	  case SB_PAGEUP:
	    si.nPos -= si.nPage;
	    break;
	  
	  case SB_PAGEDOWN:
	    si.nPos += si.nPage;
	    break;

	  case SB_THUMBTRACK:
	    si.nPos = si.nTrackPos;
	    break;

	  default:
	    break;
	  }

	/*
	 * We retrieve the position after setting it,
	 * because Windows may adjust it.
	 */
	si.fMask = SIF_POS;
	SetScrollInfo (hwnd, SB_VERT, &si, TRUE);
	GetScrollInfo (hwnd, SB_VERT, &si);
      
	/* Scroll the window if the position has changed */
	if (si.nPos != iVertPos)
	  {
	    /* Save the new offset for bit block transfers, etc. */
	    s_pScreenInfo->dwYOffset = -si.nPos;

	    /* Change displayed region in the window */
	    ScrollWindowEx (hwnd,
			    0,
			    iVertPos - si.nPos,
			    NULL,
			    NULL,
			    NULL,
			    NULL,
			    SW_INVALIDATE);
	  
	    /* Redraw the window contents */
	    UpdateWindow (hwnd);
	  }
      }
      return 0;

    case WM_HSCROLL:
      {
	SCROLLINFO		si;
	int			iHorzPos;

#if CYGDEBUG
	winDebug ("winWindowProc - WM_HSCROLL\n");
#endif
      
	/* Get horizontal scroll bar info */
	si.cbSize = sizeof (si);
	si.fMask = SIF_ALL;
	GetScrollInfo (hwnd, SB_HORZ, &si);

	/* Save the horizontal position for comparison later */
	iHorzPos = si.nPos;

	/*
	 * Don't forget:
	 * moving the scrollbar to the RIGHT, scroll the content LEFT
	 */
	switch (LOWORD(wParam))
	  {
	  case SB_LEFT:
	    si.nPos = si.nMin;
	    break;
	  
	  case SB_RIGHT:
	    si.nPos = si.nMax - si.nPage + 1;
	    break;

	  case SB_LINELEFT:
	    si.nPos -= 1;
	    break;
	  
	  case SB_LINERIGHT:
	    si.nPos += 1;
	    break;
	  
	  case SB_PAGELEFT:
	    si.nPos -= si.nPage;
	    break;
	  
	  case SB_PAGERIGHT:
	    si.nPos += si.nPage;
	    break;

	  case SB_THUMBTRACK:
	    si.nPos = si.nTrackPos;
	    break;

	  default:
	    break;
	  }

	/*
	 * We retrieve the position after setting it,
	 * because Windows may adjust it.
	 */
	si.fMask = SIF_POS;
	SetScrollInfo (hwnd, SB_HORZ, &si, TRUE);
	GetScrollInfo (hwnd, SB_HORZ, &si);
      
	/* Scroll the window if the position has changed */
	if (si.nPos != iHorzPos)
	  {
	    /* Save the new offset for bit block transfers, etc. */
	    s_pScreenInfo->dwXOffset = -si.nPos;

	    /* Change displayed region in the window */
	    ScrollWindowEx (hwnd,
			    iHorzPos - si.nPos,
			    0,
			    NULL,
			    NULL,
			    NULL,
			    NULL,
			    SW_INVALIDATE);
	  
	    /* Redraw the window contents */
	    UpdateWindow (hwnd);
	  }
      }
      return 0;

    case WM_GETMINMAXINFO:
      {
	MINMAXINFO		*pMinMaxInfo = (MINMAXINFO *) lParam;
	int			iCaptionHeight;
	int			iBorderHeight, iBorderWidth;

#if CYGDEBUG	
	winDebug ("winWindowProc - WM_GETMINMAXINFO - pScreenInfo: %08x\n",
		s_pScreenInfo);
#endif

	/* Can't do anything without screen info */
	if (s_pScreenInfo == NULL
	    || (s_pScreenInfo->iResizeMode != resizeWithScrollbars)
	    || s_pScreenInfo->fFullScreen
	    || !s_pScreenInfo->fDecoration
#ifdef XWIN_MULTIWINDOWEXTWM
	    || s_pScreenInfo->fMWExtWM
#endif
	    || s_pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOW
	    || s_pScreenInfo->fMultiWindow
#endif
	    )
	  break;

	/*
	 * Here we can override the maximum tracking size, which
	 * is the largest size that can be assigned to our window
	 * via the sizing border.
	 */

	/*
	 * FIXME: Do we only need to do this once, since our visual size
	 * does not change?  Does Windows store this value statically
	 * once we have set it once?
	 */

	/* Get the border and caption sizes */
	iCaptionHeight = GetSystemMetrics (SM_CYCAPTION);
	iBorderWidth = 2 * GetSystemMetrics (SM_CXSIZEFRAME);
	iBorderHeight = 2 * GetSystemMetrics (SM_CYSIZEFRAME);
	
	/* Allow the full visual to be displayed */
	pMinMaxInfo->ptMaxTrackSize.x
	  = s_pScreenInfo->dwWidth + iBorderWidth;
	pMinMaxInfo->ptMaxTrackSize.y
	  = s_pScreenInfo->dwHeight + iBorderHeight + iCaptionHeight;
      }
      return 0;

    case WM_ERASEBKGND:
#if CYGDEBUG
      winDebug ("winWindowProc - WM_ERASEBKGND\n");
#endif
      /*
       * Pretend that we did erase the background but we don't care,
       * the application uses the full window estate. This avoids some
       * flickering when resizing.
       */
      return TRUE;

    case WM_PAINT:
#if CYGDEBUG
      winDebug ("winWindowProc - WM_PAINT\n");
#endif
      /* Only paint if we have privates and the server is enabled */
      if (s_pScreenPriv == NULL
	  || !s_pScreenPriv->fEnabled
	  || (s_pScreenInfo->fFullScreen && !s_pScreenPriv->fActive)
	  || s_pScreenPriv->fBadDepth)
	{
	  /* We don't want to paint */
	  break;
	}

      /* Break out here if we don't have a valid paint routine */
      if (s_pScreenPriv->pwinBltExposedRegions == NULL)
	break;
      
      /* Call the engine dependent repainter */
      (*s_pScreenPriv->pwinBltExposedRegions) (s_pScreen);
      return 0;

    case WM_PALETTECHANGED:
      {
#if CYGDEBUG
	winDebug ("winWindowProc - WM_PALETTECHANGED\n");
#endif
	/*
	 * Don't process if we don't have privates or a colormap,
	 * or if we have an invalid depth.
	 */
	if (s_pScreenPriv == NULL
	    || s_pScreenPriv->pcmapInstalled == NULL
	    || s_pScreenPriv->fBadDepth)
	  break;

	/* Return if we caused the palette to change */
	if ((HWND) wParam == hwnd)
	  {
	    /* Redraw the screen */
	    (*s_pScreenPriv->pwinRedrawScreen) (s_pScreen);
	    return 0;
	  }
	
	/* Reinstall the windows palette */
	(*s_pScreenPriv->pwinRealizeInstalledPalette) (s_pScreen);
	
	/* Redraw the screen */
	(*s_pScreenPriv->pwinRedrawScreen) (s_pScreen);
	return 0;
      }

    case WM_MOUSEMOVE:
      /* We can't do anything without privates */
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;

      /* We can't do anything without g_pwinPointer */
      if (g_pwinPointer == NULL)
        break;

      /* Has the mouse pointer crossed screens? */
      if (s_pScreen != miPointerGetScreen(g_pwinPointer))
	miPointerSetScreen (g_pwinPointer, s_pScreenInfo->dwScreen,
			       GET_X_LPARAM(lParam)-s_pScreenInfo->dwXOffset,
			       GET_Y_LPARAM(lParam)-s_pScreenInfo->dwYOffset);

      /* Are we tracking yet? */
      if (!s_fTracking)
	{
	  TRACKMOUSEEVENT		tme;
	  
	  /* Setup data structure */
	  ZeroMemory (&tme, sizeof (tme));
	  tme.cbSize = sizeof (tme);
	  tme.dwFlags = TME_LEAVE;
	  tme.hwndTrack = hwnd;

	  /* Call the tracking function */
	  if (!TrackMouseEvent(&tme))
	    ErrorF ("winWindowProc - TrackMouseEvent failed\n");

	  /* Flag that we are tracking now */
	  s_fTracking = TRUE;
	}

      /* Hide or show the Windows mouse cursor */
      if (g_fSoftwareCursor && g_fCursor && (s_pScreenPriv->fActive || s_pScreenInfo->fLessPointer))
	{
	  /* Hide Windows cursor */
	  g_fCursor = FALSE;
	  ShowCursor (FALSE);
	}
      else if (g_fSoftwareCursor && !g_fCursor && !s_pScreenPriv->fActive
	       && !s_pScreenInfo->fLessPointer)
	{
	  /* Show Windows cursor */
	  g_fCursor = TRUE;
	  ShowCursor (TRUE);
	}
      
      /* Deliver absolute cursor position to X Server */
      winEnqueueMotion(GET_X_LPARAM(lParam)-s_pScreenInfo->dwXOffset,
		       GET_Y_LPARAM(lParam)-s_pScreenInfo->dwYOffset);
      return 0;

    case WM_NCMOUSEMOVE:
      /*
       * We break instead of returning 0 since we need to call
       * DefWindowProc to get the mouse cursor changes
       * and min/max/close button highlighting in Windows XP.
       * The Platform SDK says that you should return 0 if you
       * process this message, but it fails to mention that you
       * will give up any default functionality if you do return 0.
       */
      
      /* We can't do anything without privates */
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;
      
      /* Non-client mouse movement, show Windows cursor */
      if (g_fSoftwareCursor && !g_fCursor)
	{
	  g_fCursor = TRUE;
	  ShowCursor (TRUE);
	}
      break;

    case WM_MOUSELEAVE:
      /* Mouse has left our client area */

      /* Flag that we are no longer tracking */
      s_fTracking = FALSE;

      /* Show the mouse cursor, if necessary */
      if (g_fSoftwareCursor && !g_fCursor)
	{
	  g_fCursor = TRUE;
	  ShowCursor (TRUE);
	}
      return 0;

    case WM_LBUTTONDBLCLK:
    case WM_LBUTTONDOWN:
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;
      if (s_pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOWEXTWM
	  || s_pScreenInfo->fMWExtWM
#endif
	  )
	SetCapture (hwnd);
      return winMouseButtonsHandle (s_pScreen, ButtonPress, Button1, wParam);
      
    case WM_LBUTTONUP:
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;
      if (s_pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOWEXTWM
	  || s_pScreenInfo->fMWExtWM
#endif
	  )
	ReleaseCapture ();
      return winMouseButtonsHandle (s_pScreen, ButtonRelease, Button1, wParam);

    case WM_MBUTTONDBLCLK:
    case WM_MBUTTONDOWN:
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;
      if (s_pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOWEXTWM
	  || s_pScreenInfo->fMWExtWM
#endif
	  )
	SetCapture (hwnd);
      return winMouseButtonsHandle (s_pScreen, ButtonPress, Button2, wParam);
      
    case WM_MBUTTONUP:
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;
      if (s_pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOWEXTWM
	  || s_pScreenInfo->fMWExtWM
#endif
	  )
	ReleaseCapture ();
      return winMouseButtonsHandle (s_pScreen, ButtonRelease, Button2, wParam);
      
    case WM_RBUTTONDBLCLK:
    case WM_RBUTTONDOWN:
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;
      if (s_pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOWEXTWM
	  || s_pScreenInfo->fMWExtWM
#endif
	  )
	SetCapture (hwnd);
      return winMouseButtonsHandle (s_pScreen, ButtonPress, Button3, wParam);
      
    case WM_RBUTTONUP:
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;
      if (s_pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOWEXTWM
	  || s_pScreenInfo->fMWExtWM
#endif
	  )
	ReleaseCapture ();
      return winMouseButtonsHandle (s_pScreen, ButtonRelease, Button3, wParam);

    case WM_XBUTTONDBLCLK:
    case WM_XBUTTONDOWN:
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;
      if (s_pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOWEXTWM
	  || s_pScreenInfo->fMWExtWM
#endif
	  )
	SetCapture (hwnd);
      return winMouseButtonsHandle (s_pScreen, ButtonPress, HIWORD(wParam) + 5, wParam);
    case WM_XBUTTONUP:
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;
      if (s_pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOWEXTWM
	  || s_pScreenInfo->fMWExtWM
#endif
	  )
	ReleaseCapture ();
      return winMouseButtonsHandle (s_pScreen, ButtonRelease, HIWORD(wParam) + 5, wParam);

    case WM_TIMER:
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;

      /* Branch on the timer id */
      switch (wParam)
	{
	case WIN_E3B_TIMER_ID:
	  /* Send delayed button press */
	  winMouseButtonsSendEvent (ButtonPress,
				    s_pScreenPriv->iE3BCachedPress);

	  /* Kill this timer */
	  KillTimer (s_pScreenPriv->hwndScreen, WIN_E3B_TIMER_ID);

	  /* Clear screen privates flags */
	  s_pScreenPriv->iE3BCachedPress = 0;
	  break;

	case WIN_POLLING_MOUSE_TIMER_ID:
	  {
	    POINT		point;
	    WPARAM		wL, wM, wR, wShift, wCtrl;
	    LPARAM		lPos;
	    
	    /* Get the current position of the mouse cursor */
	    GetCursorPos (&point);
	    
	    /* Map from screen (-X, -Y) to root (0, 0) */
	    point.x -= GetSystemMetrics (SM_XVIRTUALSCREEN);
	    point.y -= GetSystemMetrics (SM_YVIRTUALSCREEN);
	    
	    /* Deliver absolute cursor position to X Server */
	    winEnqueueMotion(point.x , point.y);

	    /* Check if a button was released but we didn't see it */
	    GetCursorPos (&point);
	    wL = (GetKeyState (VK_LBUTTON) & 0x8000)?MK_LBUTTON:0;
	    wM = (GetKeyState (VK_MBUTTON) & 0x8000)?MK_MBUTTON:0;
	    wR = (GetKeyState (VK_RBUTTON) & 0x8000)?MK_RBUTTON:0;
	    wShift = (GetKeyState (VK_SHIFT) & 0x8000)?MK_SHIFT:0;
	    wCtrl = (GetKeyState (VK_CONTROL) & 0x8000)?MK_CONTROL:0;
	    lPos = MAKELPARAM(point.x, point.y);
	    if (g_fButton[0] & !wL)
	    PostMessage (hwnd, WM_LBUTTONUP, wCtrl|wM|wR|wShift, lPos);
	    if (g_fButton[1] & !wM)
	      PostMessage (hwnd, WM_MBUTTONUP, wCtrl|wL|wR|wShift, lPos);
	    if (g_fButton[2] & !wR)
	      PostMessage (hwnd, WM_RBUTTONUP, wCtrl|wL|wM|wShift, lPos);
	  }
	}
      return 0;

    case WM_CTLCOLORSCROLLBAR:
      FatalError ("winWindowProc - WM_CTLCOLORSCROLLBAR - We are not "
		  "supposed to get this message.  Exiting.\n");
      return 0;

    case WM_MOUSEWHEEL:
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;
#if CYGDEBUG
      winDebug ("winWindowProc - WM_MOUSEWHEEL\n");
#endif
      winMouseWheel (s_pScreen, GET_WHEEL_DELTA_WPARAM(wParam));
      break;

    case WM_SETFOCUS:
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;

      /* Restore the state of all mode keys */
      winRestoreModeKeyStates ();

      /* Add the keyboard hook if possible */
      if (g_fKeyboardHookLL)
	g_fKeyboardHookLL = winInstallKeyboardHookLL ();
      return 0;

    case WM_KILLFOCUS:
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;

      /* Release any pressed keys */
      winKeybdReleaseKeys ();

      /* Remove our keyboard hook if it is installed */
      winRemoveKeyboardHookLL ();
      return 0;

    case WM_SYSKEYDOWN:
    case WM_KEYDOWN:
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;

      /*
       * FIXME: Catching Alt-F4 like this is really terrible.  This should
       * be generalized to handle other Windows keyboard signals.  Actually,
       * the list keys to catch and the actions to perform when caught should
       * be configurable; that way user's can customize the keys that they
       * need to have passed through to their window manager or apps, or they
       * can remap certain actions to new key codes that do not conflict
       * with the X apps that they are using.  Yeah, that'll take awhile.
       */
      if ((s_pScreenInfo->fUseWinKillKey && wParam == VK_F4
	   && (GetKeyState (VK_MENU) & 0x8000))
	  || (s_pScreenInfo->fUseUnixKillKey && wParam == VK_BACK
	      && (GetKeyState (VK_MENU) & 0x8000)
	      && (GetKeyState (VK_CONTROL) & 0x8000)))
	{
	  /*
	   * Better leave this message here, just in case some unsuspecting
	   * user enters Alt + F4 and is surprised when the application
	   * quits.
	   */
	  ErrorF ("winWindowProc - WM_*KEYDOWN - Closekey hit, quitting\n");
	  
	  /* Display Exit dialog */
	  winDisplayExitDialog (s_pScreenPriv);
	  return 0;
	}
      
      /*
       * Don't do anything for the Windows keys, as focus will soon
       * be returned to Windows.  We may be able to trap the Windows keys,
       * but we should determine if that is desirable before doing so.
       */
      if ((wParam == VK_LWIN || wParam == VK_RWIN) && !g_fKeyboardHookLL)
	break;

      /* Discard fake Ctrl_L events that precede AltGR on non-US keyboards */
      if (winIsFakeCtrl_L (message, wParam, lParam))
	return 0;

      /* 
       * Discard presses generated from Windows auto-repeat
       */
      if (lParam & (1<<30))
      {
        switch (wParam)
        {
          /* ago: Pressing LControl while RControl is pressed is 
           * Indicated as repeat. Fix this!
           */
          case VK_CONTROL:
          case VK_SHIFT:
            if (winCheckKeyPressed(wParam, lParam))
              return 0;
            break;
          default:
            return 0;
        }
      } 
      
      /* Translate Windows key code to X scan code */
      winTranslateKey (wParam, lParam, &iScanCode);

      /* Ignore repeats for CapsLock */
      if (wParam == VK_CAPITAL)
	lParam = 1;

      /* Send the key event(s) */
      for (i = 0; i < LOWORD(lParam); ++i)
	winSendKeyEvent (iScanCode, TRUE);
      return 0;

    case WM_SYSKEYUP:
    case WM_KEYUP:
      if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
	break;

      /*
       * Don't do anything for the Windows keys, as focus will soon
       * be returned to Windows.  We may be able to trap the Windows keys,
       * but we should determine if that is desirable before doing so.
       */
      if ((wParam == VK_LWIN || wParam == VK_RWIN) && !g_fKeyboardHookLL)
	break;

      /* Ignore the fake Ctrl_L that follows an AltGr release */
      if (winIsFakeCtrl_L (message, wParam, lParam))
	return 0;

      /* Enqueue a keyup event */
      winTranslateKey (wParam, lParam, &iScanCode);
      winSendKeyEvent (iScanCode, FALSE);

      /* Release all pressed shift keys */
      if (wParam == VK_SHIFT) 
        winFixShiftKeys (iScanCode);
      return 0;

    case WM_HOTKEY:
      if (s_pScreenPriv == NULL)
	break;

      /* Call the engine-specific hot key handler */
      (*s_pScreenPriv->pwinHotKeyAltTab) (s_pScreen);
      return 0;

    case WM_ACTIVATE:
      if (s_pScreenPriv == NULL
	  || s_pScreenInfo->fIgnoreInput)
	break;

      /* TODO: Override display of window when we have a bad depth */
      if (LOWORD(wParam) != WA_INACTIVE && s_pScreenPriv->fBadDepth)
	{
	  ErrorF ("winWindowProc - WM_ACTIVATE - Bad depth, trying "
		  "to override window activation\n");

	  /* Minimize the window */
	  ShowWindow (hwnd, SW_MINIMIZE);

	  /* Display dialog box */
	  if (g_hDlgDepthChange != NULL)
	    {
	      /* Make the existing dialog box active */
	      SetActiveWindow (g_hDlgDepthChange);
	    }
	  else
	    {
	      /* TODO: Recreate the dialog box and bring to the top */
	      ShowWindow (g_hDlgDepthChange, SW_SHOWDEFAULT);
	    }

	  /* Don't do any other processing of this message */
	  return 0;
	}

#if CYGDEBUG
      winDebug ("winWindowProc - WM_ACTIVATE\n");
#endif

      /*
       * Focus is being changed to another window.
       * The other window may or may not belong to
       * our process.
       */

      /* Clear any lingering wheel delta */
      s_pScreenPriv->iDeltaZ = 0;

      /* Reshow the Windows mouse cursor if we are being deactivated */
      if (g_fSoftwareCursor && LOWORD(wParam) == WA_INACTIVE
	  && !g_fCursor)
	{
	  /* Show Windows cursor */
	  g_fCursor = TRUE;
	  ShowCursor (TRUE);
	}
      return 0;

    case WM_ACTIVATEAPP:
      if (s_pScreenPriv == NULL
	  || s_pScreenInfo->fIgnoreInput)
	break;

#if CYGDEBUG || TRUE
      winDebug ("winWindowProc - WM_ACTIVATEAPP\n");
#endif

      /* Activate or deactivate */
      s_pScreenPriv->fActive = wParam;

      /* Reshow the Windows mouse cursor if we are being deactivated */
      if (g_fSoftwareCursor && !s_pScreenPriv->fActive
	  && !g_fCursor)
	{
	  /* Show Windows cursor */
	  g_fCursor = TRUE;
	  ShowCursor (TRUE);
	}

#ifdef XWIN_CLIPBOARD
      /* Make sure the clipboard chain is ok. */
      winFixClipboardChain ();
#endif

      /* Call engine specific screen activation/deactivation function */
      (*s_pScreenPriv->pwinActivateApp) (s_pScreen);

#ifdef XWIN_MULTIWINDOWEXTWM
      if (s_pScreenPriv->fActive)
	{
	  /* Restack all window unless using built-in wm. */
	  if (s_pScreenInfo->fInternalWM && s_pScreenInfo->fAnotherWMRunning)
	    winMWExtWMRestackWindows (s_pScreen);
	}
#endif

      return 0;

    case WM_COMMAND:
      switch (LOWORD (wParam))
	{
	case ID_APP_EXIT:
	  /* Display Exit dialog */
	  winDisplayExitDialog (s_pScreenPriv);
	  return 0;

#ifdef XWIN_MULTIWINDOW
	case ID_APP_HIDE_ROOT:
	  if (s_pScreenPriv->fRootWindowShown)
	    ShowWindow (s_pScreenPriv->hwndScreen, SW_HIDE);
	  else
	    ShowWindow (s_pScreenPriv->hwndScreen, SW_SHOW);
	  s_pScreenPriv->fRootWindowShown = !s_pScreenPriv->fRootWindowShown;
	  return 0;
#endif

	case ID_APP_ABOUT:
	  /* Display the About box */
	  winDisplayAboutDialog (s_pScreenPriv);
	  return 0;

	default:
	  /* It's probably one of the custom menus... */
	  if (HandleCustomWM_COMMAND (0, LOWORD (wParam)))
	    return 0;
	}
      break;

    case WM_ENDSESSION:
    case WM_GIVEUP:
      /* Tell X that we are giving up */
#ifdef XWIN_MULTIWINDOW
      if (s_pScreenInfo->fMultiWindow)
	winDeinitMultiWindowWM ();
#endif
      GiveUp (0);
      return 0;

    case WM_CLOSE:
      /* Display Exit dialog */
      winDisplayExitDialog (s_pScreenPriv);
      return 0;

    case WM_SETCURSOR:
      if (LOWORD(lParam) == HTCLIENT)
	{
	  if (!g_fSoftwareCursor) SetCursor (s_pScreenPriv->cursor.handle);
	  return TRUE;
	}
      break;

#ifdef XWIN_MULTIWINDOWEXTWM
    case WM_MANAGE:
      ErrorF ("winWindowProc - WM_MANAGE\n");
      s_pScreenInfo->fAnotherWMRunning = FALSE;

      if (s_pScreenInfo->fInternalWM)
	{
	  EnumThreadWindows (g_dwCurrentThreadID, winMWExtWMDecorateWindow, 0);
	  //RootlessRepositionWindows (s_pScreen);
	}
      break;

    case WM_UNMANAGE:
      ErrorF ("winWindowProc - WM_UNMANAGE\n");
      s_pScreenInfo->fAnotherWMRunning = TRUE;

      if (s_pScreenInfo->fInternalWM)
	{
	  EnumThreadWindows (g_dwCurrentThreadID, winMWExtWMDecorateWindow, 0);
	  winMWExtWMRestackWindows (s_pScreen);
	}
      break;
#endif

    default:
      if(message == s_uTaskbarRestart)
	{
	  winInitNotifyIcon (s_pScreenPriv);
	}
      break;
    }

  return DefWindowProc (hwnd, message, wParam, lParam);
}
Exemple #3
0
void CBrushPaletteWnd::OnPaint() 
{
  {
  CPaintDC dc(this); // device context for painting
  }
  // skip if already drawing
  extern BOOL _bInTestGame; 
	if( _bInTestGame) return;

  if( m_iTimerID == -1)
  {
    m_iTimerID = (int) SetTimer( 1, 10, NULL);
  }

  POINT ptMouse;
  GetCursorPos( &ptMouse); 
  ScreenToClient( &ptMouse);

  // if there is a valid drawport, and the drawport can be locked
  if( m_pDrawPort != NULL ) {
    m_pDrawPort->SetAsCurrent();

    CWorldEditorView *pWorldEditorView = theApp.GetActiveView();
    ASSERT( pWorldEditorView != NULL);
    // clear background
    m_pDrawPort->Fill( C_lGRAY|CT_OPAQUE);
    // erase z-buffer
    m_pDrawPort->FillZBuffer(ZBUF_BACK);
    // for all brushes
    for( INDEX iBrush=0; iBrush<CT_BRUSHES; iBrush++)
    {
      // get current brush's box in pixels inside window
      PIXaabbox2D boxBrush = GetBrushBBox( iBrush);
      RenderBrushShape( iBrush, boxBrush, m_pDrawPort);

      TIME tm=_pTimer->GetRealTimeTick();
      // if we are drawing selected brush
      if(iBrush==theApp.m_fCurrentTerrainBrush)
      {
        m_pDrawPort->SetAsCurrent();
        FLOAT fFactor=sin(tm*8)/2.0f+0.5f;
        COLOR colSelected=LerpColor(C_lGRAY,C_RED,fFactor);
        m_pDrawPort->DrawBorder(boxBrush.Min()(1)-1, boxBrush.Min()(2)-1, 
                                boxBrush.Max()(1)-boxBrush.Min()(1)+2, boxBrush.Max()(2)-boxBrush.Min()(2)+2,
                                colSelected|CT_OPAQUE);
      }
      PIXaabbox2D boxPoint( PIX2D( ptMouse.x, ptMouse.y), PIX2D(ptMouse.x, ptMouse.y) );
      if( (boxBrush & boxPoint) == boxPoint)
      {
        m_pDrawPort->SetAsCurrent();
        INDEX iRot=((ULONG)(tm*25.0f))&7;
        ULONG ulLineType=0x0f0f0f0f<<iRot;
        m_pDrawPort->DrawBorder(boxBrush.Min()(1)-1, boxBrush.Min()(2)-1, 
                                boxBrush.Max()(1)-boxBrush.Min()(1)+2, boxBrush.Max()(2)-boxBrush.Min()(2)+2,
                                C_BLUE|CT_OPAQUE, ulLineType);
      }
    }

    // if there is a valid viewport
    if (m_pViewPort!=NULL)
    {
      m_pViewPort->SwapBuffers();
    }
  }
}
void CQListCtrl::OnTimer(UINT_PTR nIDEvent) 
{
	//http://support.microsoft.com/kb/200054
	//OnTimer() Is Not Called Repeatedly for a List Control
	bool callBase = true;

	switch(nIDEvent)
	{
		case TIMER_SHOW_PROPERTIES:
			{
				if( theApp.m_bShowingQuickPaste )
					ShowFullDescription(true);
				KillTimer(TIMER_SHOW_PROPERTIES);

				callBase = false;
			}
			break;

		case TIMER_HIDE_SCROL:
			{
				CPoint cursorPos;
				GetCursorPos(&cursorPos);

				CRect crWindow;
				this->GetWindowRect(&crWindow);

				

				//check and see if they moved out of the scroll area
				//If they did tell our parent so
				if(MouseInScrollBarArea(crWindow, cursorPos) == false)
				{
					StopHideScrollBarTimer();
				}

				callBase = false;
			}
			break;

		case TIMER_SHOW_SCROLL:
			{
				CPoint cursorPos;
				GetCursorPos(&cursorPos);

				CRect crWindow;
				this->GetWindowRect(&crWindow);

				//Adjust for the v-scroll bar being off of the screen
				crWindow.right -= theApp.m_metrics.ScaleX(GetSystemMetrics(SM_CXVSCROLL));
				crWindow.bottom -= theApp.m_metrics.ScaleX(::GetSystemMetrics(SM_CXHSCROLL));

				//Check and see if we are still in the cursor area
				if(MouseInScrollBarArea(crWindow, cursorPos))
				{
					m_timerToHideScrollAreaSet = true;
					GetParent()->SendMessage(NM_SHOW_HIDE_SCROLLBARS, 1, 0);

					//Start looking to hide the scroll bars
					SetTimer(TIMER_HIDE_SCROL, 1000, NULL);
				}

				KillTimer(TIMER_SHOW_SCROLL);

				callBase = false;
			}
			break;
	}
	
	if(callBase)
	{
		CListCtrl::OnTimer(nIDEvent);
	}
}
Exemple #5
0
/*
===========
IN_MouseMove
===========
*/
void IN_MouseMove (usercmd_t *cmd)
{
	int					mx, my;
	HDC					hdc;
	int					i;
	DIDEVICEOBJECTDATA	od;
	DWORD				dwElements;
	HRESULT				hr;

	if (!mouseactive)
		return;

	if (dinput)
	{
		mx = 0;
		my = 0;

		for (;;)
		{
			dwElements = 1;

			hr = IDirectInputDevice_GetDeviceData(g_pMouse,
					sizeof(DIDEVICEOBJECTDATA), &od, &dwElements, 0);

			if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED))
			{
				dinput_acquired = true;
				IDirectInputDevice_Acquire(g_pMouse);
				break;
			}

			/* Unable to read data or no data available */
			if (FAILED(hr) || dwElements == 0)
			{
				break;
			}

			/* Look at the element to see what happened */

			switch (od.dwOfs)
			{
				case DIMOFS_X:
					mx += od.dwData;
					break;

				case DIMOFS_Y:
					my += od.dwData;
					break;

				case DIMOFS_BUTTON0:
					if (od.dwData & 0x80)
						mstate_di |= 1;
					else
						mstate_di &= ~1;
					break;

				case DIMOFS_BUTTON1:
					if (od.dwData & 0x80)
						mstate_di |= (1<<1);
					else
						mstate_di &= ~(1<<1);
					break;
					
				case DIMOFS_BUTTON2:
					if (od.dwData & 0x80)
						mstate_di |= (1<<2);
					else
						mstate_di &= ~(1<<2);
					break;
			}
		}

	// perform button actions
		for (i=0 ; i<mouse_buttons ; i++)
		{
			if ( (mstate_di & (1<<i)) &&
				!(mouse_oldbuttonstate & (1<<i)) )
			{
				Key_Event (K_MOUSE1 + i, true);
			}

			if ( !(mstate_di & (1<<i)) &&
				(mouse_oldbuttonstate & (1<<i)) )
			{
				Key_Event (K_MOUSE1 + i, false);
			}
		}	
			
		mouse_oldbuttonstate = mstate_di;
	}
	else
	{
		GetCursorPos (&current_pos);
		mx = current_pos.x - window_center_x + mx_accum;
		my = current_pos.y - window_center_y + my_accum;
		mx_accum = 0;
		my_accum = 0;
	}

//if (mx ||  my)
//	Con_DPrintf("mx=%d, my=%d\n", mx, my);

	if (m_filter.value)
	{
		mouse_x = (mx + old_mouse_x) * 0.5;
		mouse_y = (my + old_mouse_y) * 0.5;
	}
	else
	{
		mouse_x = mx;
		mouse_y = my;
	}

	old_mouse_x = mx;
	old_mouse_y = my;

	mouse_x *= sensitivity.value;
	mouse_y *= sensitivity.value;

// add mouse X/Y movement to cmd
	if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
		cmd->sidemove += m_side.value * mouse_x;
	else
		cl.viewangles[YAW] -= m_yaw.value * mouse_x;

	if (in_mlook.state & 1)
		V_StopPitchDrift ();
		
	if ( (in_mlook.state & 1) && !(in_strafe.state & 1))
	{
		cl.viewangles[PITCH] += m_pitch.value * mouse_y;
		if (cl.viewangles[PITCH] > 80)
			cl.viewangles[PITCH] = 80;
		if (cl.viewangles[PITCH] < -70)
			cl.viewangles[PITCH] = -70;
	}
	else
	{
		if ((in_strafe.state & 1) && noclip_anglehack)
			cmd->upmove -= m_forward.value * mouse_y;
		else
			cmd->forwardmove -= m_forward.value * mouse_y;
	}

// if the mouse has moved, force it to the center, so there's room to move
	if (mx || my)
	{
		SetCursorPos (window_center_x, window_center_y);
	}
}
void CGUIDialogKeyboardGeneric::MoveCursor(int iAmount)
{
  if (!m_strEditing.IsEmpty())
    return;
  SetCursorPos(GetCursorPos() + iAmount);
}
void CToolTipCtrlEx::OnPaint()
{
	POINT Pos;
	GetCursorPos(&Pos);
	CRect PRect;
	WindowFromPoint(Pos)->GetWindowRect(PRect);

	CPaintDC dc(this); // device context for painting
	CRect	Rect,R1;
	CRect	WRect;

	Orientations Orient=NW;
	BOOL	Over=0,Left=0;
	Over=Pos.y	>(PRect.top+(PRect.bottom-PRect.top)/2);
	Left=Pos.x	<(PRect.left+(PRect.right-PRect.left)/2);
	if(Over & Left)Orient=NW;
	else
	if(Over & !Left)Orient=NE;
	else
	if(!Over & Left)Orient=SW;
	else
	if(!Over & !Left)Orient=SE;

	dc.SelectObject(GetFont());

	CString	Tip=_T(""),TStr=_T("");
	GetWindowText(Tip);
	UINT Width=0;
	UINT Rows=1;
	UINT iPos=0;
	Tip.Replace(_T("\r"),_T(""));
	while(iPos<Tip.GetLength())
	{
		if(Tip.GetAt(iPos)=='\n')
		{
			CSize Sz1=dc.GetTextExtent(TStr);
			Width=(Width > Sz1.cx) ? Width : Sz1.cx;
			Rows+=1;
			TStr=_T("");
		}
		else
		{
			TStr+=Tip.GetAt(iPos);
		}
		iPos++;
	}
	if(TStr.GetLength())
	{
		CSize Sz1=dc.GetTextExtent(TStr);
		Width=(Width > Sz1.cx) ? Width : Sz1.cx;
	}
	if(Rows==1)
	{
		CSize Sz1=dc.GetTextExtent(Tip);
		Width=(Width > Sz1.cx) ? Width : Sz1.cx;
	}
	Width+=2;

	GetWindowRect(WRect);
	TEXTMETRIC TM;
	dc.GetTextMetrics(&TM);
	if(Over)
	{
		WRect.bottom=PRect.top;
		WRect.top=WRect.bottom-(Rows*(TM.tmHeight)+4);
	}
	else
	{
		WRect.top=PRect.bottom;
		WRect.bottom=WRect.top+(Rows*(TM.tmHeight)+4);
	}
	UINT T=WRect.Width()-(20+Width);
	WRect.left=Pos.x;
	WRect.right=WRect.left+20+Width;
	if(WRect.right>GetSystemMetrics(SM_CXSCREEN)-25)
	{
		WRect.OffsetRect(-(WRect.right-(GetSystemMetrics(SM_CXSCREEN)-25)),0);
	}
	MoveWindow(&WRect,1);
	ShowWindow(1);

	GetClientRect(Rect);
	dc.FillSolidRect(Rect,m_bkColor);
	R1=Rect;
	R1.right=R1.left+15;
	dc.FillSolidRect(R1,m_leftColor);
	Rect.left=R1.right+1;

	dc.SetBkMode(TRANSPARENT);
	Rect.top+=1;
	UINT iT=(Rect.Width()-Width)/2;
	Rect.left+=iT;
	dc.SetTextColor(m_textColor);
	if(Rows==1)
	{
		dc.DrawText(Tip,Rect,DT_LEFT|DT_VCENTER|DT_SINGLELINE);
	}
	else
	{
		dc.DrawText(Tip,Rect,DT_TOP|DT_LEFT|DT_WORDBREAK);
	}
	Rect.top-=1;
	Rect.left-=iT;
	GetClientRect(Rect);
//	Rect.InflateRect(1,1,1,1);
	dc.Draw3dRect(Rect,m_frameColor,m_frameColor);

	CPen	Pen,*OldPen=0;
	Pen.CreatePen(PS_SOLID,1,m_arrowColor);
	OldPen=dc.SelectObject(&Pen);
	switch(Orient)
	{
	case SE:
		{
			CPoint	ArrowPt=CPoint(R1.left+2,R1.top+2);
			POINT	Pt[18]=
			{
				{ArrowPt.x,     ArrowPt.y},
				{ArrowPt.x,		ArrowPt.y + 6},
				{ArrowPt.x + 1, ArrowPt.y + 6}, 
				{ArrowPt.x + 1, ArrowPt.y},
				{ArrowPt.x + 6, ArrowPt.y},
				{ArrowPt.x + 6, ArrowPt.y + 1},
				{ArrowPt.x + 2, ArrowPt.y + 1},
				{ArrowPt.x + 2, ArrowPt.y + 4},
				{ArrowPt.x + 5, ArrowPt.y + 7},
				{ArrowPt.x + 6, ArrowPt.y + 7},
				{ArrowPt.x + 3, ArrowPt.y + 4},
				{ArrowPt.x + 3, ArrowPt.y + 3},
				{ArrowPt.x + 6, ArrowPt.y + 6},
				{ArrowPt.x + 7, ArrowPt.y + 6},
				{ArrowPt.x + 3, ArrowPt.y + 2},
				{ArrowPt.x + 4, ArrowPt.y + 2},
				{ArrowPt.x + 7, ArrowPt.y + 5},
				{ArrowPt.x + 7, ArrowPt.y + 6}
			};
			dc.Polyline(Pt,18);
		}
		break;
	case SW:
		{
			CPoint	ArrowPt=CPoint(R1.right - 3, R1.top + 2);
			POINT	Pt[18]=
			{
				{ArrowPt.x,     ArrowPt.y},     {ArrowPt.x, ArrowPt.y + 6},
                {ArrowPt.x - 1, ArrowPt.y + 6}, {ArrowPt.x - 1, ArrowPt.y},
                {ArrowPt.x - 6, ArrowPt.y},     {ArrowPt.x - 6, ArrowPt.y + 1},
                {ArrowPt.x - 2, ArrowPt.y + 1}, {ArrowPt.x - 2, ArrowPt.y + 4},
                {ArrowPt.x - 5, ArrowPt.y + 7}, {ArrowPt.x - 6, ArrowPt.y + 7},
                {ArrowPt.x - 3, ArrowPt.y + 4}, {ArrowPt.x - 3, ArrowPt.y + 3},
                {ArrowPt.x - 6, ArrowPt.y + 6}, {ArrowPt.x - 7, ArrowPt.y + 6},
                {ArrowPt.x - 3, ArrowPt.y + 2}, {ArrowPt.x - 4, ArrowPt.y + 2},
                {ArrowPt.x - 7, ArrowPt.y + 5}, {ArrowPt.x - 7, ArrowPt.y + 6}
			};
			dc.Polyline(Pt,18);
		}
		break;
	case NE:
		{
			CPoint	ArrowPt=CPoint(R1.left+ 3, R1.bottom - 3);
			POINT	Pt[18]=
			{
				{ArrowPt.x,     ArrowPt.y},     {ArrowPt.x, ArrowPt.y - 6},
				{ArrowPt.x + 1, ArrowPt.y - 6}, {ArrowPt.x + 1, ArrowPt.y},
				{ArrowPt.x + 6, ArrowPt.y},     {ArrowPt.x + 6, ArrowPt.y - 1},
				{ArrowPt.x + 2, ArrowPt.y - 1}, {ArrowPt.x + 2, ArrowPt.y - 4},
				{ArrowPt.x + 5, ArrowPt.y - 7}, {ArrowPt.x + 6, ArrowPt.y - 7},
				{ArrowPt.x + 3, ArrowPt.y - 4}, {ArrowPt.x + 3, ArrowPt.y - 3},
				{ArrowPt.x + 6, ArrowPt.y - 6}, {ArrowPt.x + 7, ArrowPt.y - 6},
				{ArrowPt.x + 3, ArrowPt.y - 2}, {ArrowPt.x + 4, ArrowPt.y - 2},
				{ArrowPt.x + 7, ArrowPt.y - 5}, {ArrowPt.x + 7, ArrowPt.y - 6}
			};
			dc.Polyline(Pt,18);
		}
		break;
	case NW:
		{
			CPoint	ArrowPt=CPoint(R1.right- 3, R1.bottom - 3);
			POINT	Pt[18]=
			{
				{ArrowPt.x,     ArrowPt.y},     {ArrowPt.x, ArrowPt.y - 6},
				{ArrowPt.x - 1, ArrowPt.y - 6}, {ArrowPt.x - 1, ArrowPt.y},
				{ArrowPt.x - 6, ArrowPt.y},     {ArrowPt.x - 6, ArrowPt.y - 1},
				{ArrowPt.x - 2, ArrowPt.y - 1}, {ArrowPt.x - 2, ArrowPt.y - 4},
				{ArrowPt.x - 5, ArrowPt.y - 7}, {ArrowPt.x - 6, ArrowPt.y - 7},
				{ArrowPt.x - 3, ArrowPt.y - 4}, {ArrowPt.x - 3, ArrowPt.y - 3},
				{ArrowPt.x - 6, ArrowPt.y - 6}, {ArrowPt.x - 7, ArrowPt.y - 6},
				{ArrowPt.x - 3, ArrowPt.y - 2}, {ArrowPt.x - 4, ArrowPt.y - 2},
				{ArrowPt.x - 7, ArrowPt.y - 5}, {ArrowPt.x - 7, ArrowPt.y - 6}
			};
			dc.Polyline(Pt,18);
		}
		break;
	};
	dc.SelectObject(OldPen);
	Pen.DeleteObject();
}
Exemple #8
0
void GiveFocusToScreen(unsigned int ScreenIndex, tree_node *FocusNode, bool Mouse, bool UpdateFocus)
{
    screen_info *Screen = GetDisplayFromScreenID(ScreenIndex);
    if(Screen && Screen != KWMScreen.Current)
    {
        KWMScreen.PrevSpace = KWMScreen.Current->ActiveSpace;
        KWMScreen.Current = Screen;

        Screen->ActiveSpace = GetActiveSpaceOfDisplay(Screen);
        ShouldActiveSpaceBeManaged();
        space_info *Space = GetActiveSpaceOfScreen(Screen);

        DEBUG("GiveFocusToScreen() " << ScreenIndex << \
              ": Space transition ended " << KWMScreen.PrevSpace << \
              " -> " << Screen->ActiveSpace);

        if(UpdateFocus)
        {
            if(Space->Initialized && FocusNode)
            {
                DEBUG("Populated Screen 'Window -f Focus'");

                UpdateActiveWindowList(Screen);
                FilterWindowList(Screen);
                SetWindowFocusByNode(FocusNode);
                MoveCursorToCenterOfFocusedWindow();
            }
            else if(Space->Initialized && Space->RootNode)
            {
                DEBUG("Populated Screen Key/Mouse Focus");

                UpdateActiveWindowList(Screen);
                FilterWindowList(Screen);

                bool WindowBelowCursor = IsAnyWindowBelowCursor();
                if(Mouse && !WindowBelowCursor)
                    ClearFocusedWindow();
                else if(Mouse && WindowBelowCursor)
                    FocusWindowBelowCursor();

                if(!Mouse)
                {
                    if(Space->FocusedWindowID == -1)
                    {
                        if(Space->Settings.Mode == SpaceModeBSP)
                        {
                            void *FocusNode = NULL;
                            GetFirstLeafNode(Space->RootNode, (void**)&FocusNode);
                            Space->FocusedWindowID = ((tree_node*)FocusNode)->WindowID;
                        }
                        else if(Space->Settings.Mode == SpaceModeMonocle)
                        {
                            if(Space->RootNode->List)
                                Space->FocusedWindowID = Space->RootNode->List->WindowID;
                        }
                    }

                    FocusWindowByID(Space->FocusedWindowID);
                    MoveCursorToCenterOfFocusedWindow();
                }
            }
            else
            {
                if(!Space->Initialized ||
                   Space->Settings.Mode == SpaceModeFloating ||
                   !Space->RootNode)
                {
                    DEBUG("Uninitialized Screen");
                    ClearFocusedWindow();

                    if(!Mouse)
                        CGWarpMouseCursorPosition(CGPointMake(Screen->X + (Screen->Width / 2), Screen->Y + (Screen->Height / 2)));

                    if(Space->Settings.Mode != SpaceModeFloating && !Space->RootNode)
                    {
                        CGPoint ClickPos = GetCursorPos();
                        CGEventRef ClickEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, ClickPos, kCGMouseButtonLeft);
                        CGEventSetFlags(ClickEvent, 0);
                        CGEventPost(kCGHIDEventTap, ClickEvent);
                        CFRelease(ClickEvent);

                        ClickEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseUp, ClickPos, kCGMouseButtonLeft);
                        CGEventSetFlags(ClickEvent, 0);
                        CGEventPost(kCGHIDEventTap, ClickEvent);
                        CFRelease(ClickEvent);
                    }
                }
            }
        }
    }
}
Exemple #9
0
void ShowTrayMenu() {

	POINT pt;
	GetCursorPos(&pt);

	WCHAR szBuff[MAX_LANGLEN];

	HMENU hmenu = CreatePopupMenu();
	for (int i = 0; i <= (IDM_EXIT - IDM_STTRAYNEXT); i++) {
		LangLoadString(IDS_STTRAYNEXT + i, szBuff, SIZEOF_ARRAY(szBuff));
		AppendMenu(hmenu, MF_STRING, IDM_STTRAYNEXT + i, szBuff);
	}
	InsertMenu(hmenu, IDM_CONFIG, MF_SEPARATOR | MF_BYCOMMAND, 0, NULL);
	InsertMenu(hmenu, IDM_EXIT, MF_SEPARATOR | MF_BYCOMMAND, 0, NULL);

	HMENU hmenuPopup = CreatePopupMenu();
	for (int i = 0; i <= (IDM_ABOUT - IDM_DOCUMENTATION); i++) {
		LangLoadString(IDS_DOCUMENTATION + i, szBuff, SIZEOF_ARRAY(szBuff));
		AppendMenu(hmenuPopup, MF_STRING, IDM_DOCUMENTATION + i, szBuff);
	}
	LangLoadString(IDS_HELP, szBuff, SIZEOF_ARRAY(szBuff));
	InsertMenu(hmenu, IDM_CONFIG, MF_STRING | MF_BYCOMMAND | MF_POPUP, 
		(UINT_PTR)hmenuPopup, szBuff);
	InsertMenu(hmenu, 4, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);

	hmenuPopup = CreatePopupMenu();
	for (int i = 0; i <= (IDM_NEWEXCLUSION - IDM_HIDE); i++) {
		LangLoadString(IDS_HIDE + i, szBuff, SIZEOF_ARRAY(szBuff));
		AppendMenu(hmenuPopup, MF_STRING, IDM_HIDE + i, szBuff);
	}
	InsertMenu(hmenuPopup, IDM_NEWEXCLUSION, MF_SEPARATOR | MF_BYCOMMAND, 0, NULL);
	InsertMenu(hmenuPopup, IDM_REPLACEALTTAB, MF_SEPARATOR | MF_BYCOMMAND, 0, NULL);
	CheckMenuItem(hmenuPopup, IDM_REPLACEALTTAB, !(g_dwFlags & TSF_NOREPLACEALTTAB) 
		? (MF_BYCOMMAND | MF_CHECKED) : (MF_BYCOMMAND | MF_UNCHECKED));
	CheckMenuItem(hmenuPopup, IDM_INSTSWITCHER, (g_dwFlags & TSF_INSTSWITCHER) 
		? (MF_BYCOMMAND | MF_CHECKED) : (MF_BYCOMMAND | MF_UNCHECKED));
	CheckMenuItem(hmenuPopup, IDM_STICKYALTTAB, (g_dwFlags & TSF_STICKYALTTAB) 
		? (MF_BYCOMMAND | MF_CHECKED) : (MF_BYCOMMAND | MF_UNCHECKED));
	CheckMenuItem(hmenuPopup, IDM_HOOKALTTAB, (g_dwFlags & TSF_HOOKALTTAB) 
		? (MF_BYCOMMAND | MF_CHECKED) : (MF_BYCOMMAND | MF_UNCHECKED));
//	CheckMenuItem(hmenuPopup, IDM_EXTMOUSE, (g_dwFlags & TSF_EXTMOUSE) 
//		? (MF_BYCOMMAND | MF_CHECKED) : (MF_BYCOMMAND | MF_UNCHECKED));
	LangLoadString(IDS_QUICKCONFIG, szBuff, SIZEOF_ARRAY(szBuff));
	InsertMenu(hmenu, IDM_CONFIG, MF_STRING | MF_BYCOMMAND | MF_POPUP, 
		(UINT_PTR)hmenuPopup, szBuff);

	SetForegroundWindow(g_hwndMain);
	UINT uMenuID = (UINT)TrackPopupMenu(hmenu, 
		TPM_RIGHTBUTTON | TPM_RIGHTALIGN | TPM_NONOTIFY | TPM_RETURNCMD, 
		pt.x, pt.y, 0, g_hwndMain, NULL);
	PostMessage(g_hwndMain, WM_NULL, 0, 0);
	DestroyMenu(hmenu);

	switch (uMenuID) {
		case IDM_STTRAYNEXT:
			ShowTaskSwitchWnd(IDH_STTRAYNEXT);
			break;
		case IDM_STITRAYNEXT:
			ShowTaskSwitchWnd(IDH_STITRAYNEXT);
			break;
		case IDM_CONFIG:
			ConfigTaskSwitchXP();
			break;
		case IDM_HIDE:
			ShowTrayIcon(FALSE);
			break;
		case IDM_REPLACEALTTAB:
			ReplaceAltTab((g_dwFlags & TSF_NOREPLACEALTTAB) 
				? (g_dwFlags & ~TSF_NOREPLACEALTTAB) : (g_dwFlags | TSF_NOREPLACEALTTAB));
			break;
		case IDM_INSTSWITCHER:
			ReplaceAltTab((g_dwFlags & TSF_INSTSWITCHER) 
				? (g_dwFlags & ~TSF_INSTSWITCHER) : (g_dwFlags | TSF_INSTSWITCHER));
			break;
		case IDM_STICKYALTTAB:
			g_dwFlags ^= TSF_STICKYALTTAB;
			break;
		case IDM_HOOKALTTAB:
			ReplaceAltTab((g_dwFlags & TSF_HOOKALTTAB) 
				? (g_dwFlags & ~TSF_HOOKALTTAB) : (g_dwFlags | TSF_HOOKALTTAB));
			break;
//		case IDM_EXTMOUSE:
//			EnableExtMouse(!(g_dwFlags & TSF_EXTMOUSE), g_dwFlags & TSF_WHEELTAB);
//			break;
		case IDM_NEWEXCLUSION:
			ConfigTaskSwitchXP(L"/newexcl");
			break;
		case IDM_DOCUMENTATION:
			HelpTaskSwitchXP();
			break;
		case IDM_HOMEPAGE:
			ShellExecute(NULL, L"open", L"http://www.ntwind.com/taskswitchxp/", NULL, NULL, SW_SHOWNORMAL);
			break;
		case IDM_ABOUT:
			ConfigTaskSwitchXP(L"/about");
			break;
		case IDM_EXIT:
			DestroyWindow(g_hwndMain);
			break;
	}
}
Exemple #10
0
int main()
{
    srand(time(NULL));

    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "Astroides");
    //used for getting the mouse posistion.
    sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
    const int window_height = desktop.height;
    const int window_width = desktop.width;

    window.setFramerateLimit(60);
    sf::Clock clock = sf::Clock();
    sf::Time elapsedTime;

    //BackGround
    sf::Texture backGroundTexture;
    sf::Sprite backGroundSprite;
    backGroundTexture.loadFromFile("Resorces/Img/background.png");
    backGroundSprite.setTexture(backGroundTexture);
    backGroundSprite.setPosition(0, 0);


    //Entities
    Player player = Player();
    EnemyManager eManager;
    ProjectileManager* projectileMgr = ProjectileManager::instance();
    InputManager* inputMgr = InputManager::instance();

    //set up world.
    sf::Vector2f worldBounds = sf::Vector2f(MAP_WIDTH, MAP_HEIGHT);

    int numPacksSwarmers = 10;
    int numSwarmersPerPack = 10;
    int numSwarmerEnemies = numPacksSwarmers * numSwarmersPerPack;
    int numFactories = 20;

    //create some Enemies
    for (int i = 0; i < numPacksSwarmers; i++)
    {
        for (int z = 0; z < numSwarmersPerPack; z++)
        {
            Swarmer * e = new Swarmer((1000 * i), (700 * i)); //Starts all enemy in the center of the screen.
            eManager.addEnemy(e);
        }
    }

    for (int i = 0; i < numFactories; i++)
    {
        Factory * f = new Factory(&eManager);
        eManager.addFactory(f);
    }


    // Start game loop
    while (window.isOpen())
    {
        // Process events
        sf::Event Event;
		
        while (window.pollEvent(Event))
		{
            if (Event.type == Event.KeyPressed && Event.key.code == sf::Keyboard::Escape)
            {
                window.close();
            }
            switch (Event.type)
            {				
                // Close window : exit
                case sf::Event::Closed:
                    window.close();
                    break;
                default:
                    break;
            }//end switch
        }//end while
		InputManager::instance()->UpdatePressedKeys(Event);
	
        player.Update(worldBounds);
        projectileMgr->Update(window);

        //Get the mouse posistion and send it to the swarm method.
        POINT mousePos;
        if (GetCursorPos(&mousePos))
        {
            if (ScreenToClient(window.getSystemHandle(), &mousePos))
            {
                //std::cout << "mouse pos : (" << mousePos.x << ", " << mousePos.y << ")" << std::endl;
                eManager.swarmEAI(player.GetPos());
            }
        }
        //eManager.flocking();
        eManager.CheckCollisions();
        eManager.UpdateFactories(&player);
        eManager.UpdatePredators(player.GetPos());
        eManager.CollisionSwarm(&player);
        eManager.CollisionPred(&player);

        //prepare frame
        window.clear();
        window.setView(player.getView());
        window.draw(backGroundSprite);
        player.Draw(window);
        projectileMgr->Draw(window);
        eManager.Draw(window, worldBounds);

        window.setView(player.getMiniMapView());
        window.draw(backGroundSprite);
        player.Draw(window);
        projectileMgr->Draw(window);
        eManager.Draw(window, worldBounds);

        // Finally, display rendered frame on screen
        window.display();
        clock.restart();
    } //loop back for next frame

    return EXIT_SUCCESS;

}
// Called from the Windows notification handler thread, in its message loop
LRESULT CALLBACK
DesktopIndicatorHandler::WndProc
(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
    // Check for our special notification message
    if ((uMessage != WM_DESKTOPINDICATOR_CLICK)) {
        return DefWindowProc(hWnd, uMessage, wParam, lParam);
    }
    DesktopIndicatorHandler *pthis = (DesktopIndicatorHandler *)
        GetWindowLong(hWnd, GWL_USERDATA);
    switch (lParam) {
    case WM_LBUTTONDBLCLK:
        // Execute the default action of the right-click popup menu
        pthis->restoreApplication();
        break;
    //case WM_LBUTTONDOWN:
    //case WM_RBUTTONDOWN:
    //case WM_LBUTTONUP:
        //break;
    case WM_RBUTTONUP: // Display popup menu on right click
        {
            SetForegroundWindow(hWnd);
            POINT pos;
            GetCursorPos(&pos);
            int cxMenuCheck = GetSystemMetrics(SM_CXMENUCHECK);
            int cyMenuCheck = GetSystemMetrics(SM_CYMENUCHECK);
            HMENU hMenu = CreatePopupMenu();
            UAppendMenu(hMenu, MF_STRING, MNU_RESTORE,
                pthis->m_lpwszItemRestore);     // L"Restore";
            UAppendMenu(hMenu, MF_STRING, MNU_ABOUT,
                pthis->m_lpwszItemAbout);       // L"About...";
            UAppendMenu(hMenu, MF_SEPARATOR, 0, (LPCWSTR)NULL);
            UAppendMenu(hMenu, MF_STRING, MNU_EXIT_AFTER,
                pthis->m_lpwszItemExitLater);   // L"Exit After Transfers";
            UAppendMenu(hMenu, MF_STRING, MNU_EXIT,
                pthis->m_lpwszItemExit);        // L"Exit";
            //Load 15x15 bitmaps for unchecked state of menu options
            //Remap colors  #000000, #808080, #C0C0C0, #DFDFDF, #FFFFFF
            //to 3D colors: DlgText, 3DDark, 3DFace, 3DLight, WindowBg
            HBITMAP hbmpRestore = (HBITMAP)LoadImageA(
                ::g_hInstance, MAKEINTRESOURCEA(IDB_RESTORE),
                IMAGE_BITMAP, cxMenuCheck, cyMenuCheck,
                LR_LOADMAP3DCOLORS);
            HBITMAP hbmpHelp = (HBITMAP)LoadImageA(
                ::g_hInstance, MAKEINTRESOURCEA(IDB_HELP),
                IMAGE_BITMAP, cxMenuCheck, cyMenuCheck,
                LR_LOADMAP3DCOLORS);
            HBITMAP hbmpWaitClose = (HBITMAP)LoadImageA(
                ::g_hInstance, MAKEINTRESOURCEA(IDB_WAITCLOSE),
                IMAGE_BITMAP, cxMenuCheck, cyMenuCheck,
                LR_LOADMAP3DCOLORS);
            HBITMAP hbmpClose = (HBITMAP)LoadImageA(
                ::g_hInstance, MAKEINTRESOURCEA(IDB_CLOSE),
                IMAGE_BITMAP, cxMenuCheck, cyMenuCheck,
                LR_LOADMAP3DCOLORS);
            SetMenuItemBitmaps(hMenu, MNU_RESTORE, MF_BYCOMMAND,
                hbmpRestore, (HBITMAP)NULL);
            SetMenuItemBitmaps(hMenu, MNU_ABOUT, MF_BYCOMMAND,
                hbmpHelp, (HBITMAP)NULL);
            SetMenuItemBitmaps(hMenu, MNU_EXIT_AFTER, MF_BYCOMMAND,
                hbmpWaitClose, (HBITMAP)NULL);
            SetMenuItemBitmaps(hMenu, MNU_EXIT, MF_BYCOMMAND,
                hbmpClose, (HBITMAP)NULL);
            SetMenuDefaultItem(hMenu, MNU_RESTORE, MF_BYCOMMAND);
            switch (TrackPopupMenu(hMenu,
                TPM_CENTERALIGN | TPM_BOTTOMALIGN |
                TPM_LEFTBUTTON |
                TPM_NONOTIFY | TPM_RETURNCMD, /* return an item.wID instead of BOOL */
                pos.x, pos.y,
                0, hWnd, (LPCRECT)NULL)) {
            case MNU_RESTORE:
                pthis->restoreApplication();
                break;
            case MNU_ABOUT:
                pthis->showAboutWindow();
                break;
            case MNU_EXIT_AFTER:
                pthis->exitAfterTransfers();
                break;
            case MNU_EXIT:
                pthis->exitApplication();
                break;
            }
            DestroyMenu(hMenu);
            DeleteObject((HGDIOBJ)hbmpRestore);
            DeleteObject((HGDIOBJ)hbmpClose);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    }
    return 0;
}
Exemple #12
0
void ProcessPageShowContextMenu(DWORD dwProcessId)
{
    HMENU        hMenu;
    HMENU        hSubMenu;
    HMENU        hPriorityMenu;
    POINT        pt;
    SYSTEM_INFO  si;
    HANDLE       hProcess;
    DWORD        dwProcessPriorityClass;
    WCHAR        strDebugger[260];
    DWORD        dwDebuggerSize;
    HKEY         hKey;

    memset(&si, 0, sizeof(SYSTEM_INFO));

    GetCursorPos(&pt);
    GetSystemInfo(&si);

    hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_PROCESS_PAGE_CONTEXT));
    hSubMenu = GetSubMenu(hMenu, 0);
    hPriorityMenu = GetSubMenu(hSubMenu, 4);

    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcessId);
    dwProcessPriorityClass = GetPriorityClass(hProcess);
    CloseHandle(hProcess);

    if (si.dwNumberOfProcessors < 2)
        RemoveMenu(hSubMenu, ID_PROCESS_PAGE_SETAFFINITY, MF_BYCOMMAND);

    if (!DebugChannelsAreSupported())
        RemoveMenu(hSubMenu, ID_PROCESS_PAGE_DEBUGCHANNELS, MF_BYCOMMAND);

    switch (dwProcessPriorityClass)    {
    case REALTIME_PRIORITY_CLASS:
        CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, MF_BYCOMMAND);
        break;
    case HIGH_PRIORITY_CLASS:
        CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_HIGH, MF_BYCOMMAND);
        break;
    case ABOVE_NORMAL_PRIORITY_CLASS:
        CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL, MF_BYCOMMAND);
        break;
    case NORMAL_PRIORITY_CLASS:
        CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_NORMAL, MF_BYCOMMAND);
        break;
    case BELOW_NORMAL_PRIORITY_CLASS:
        CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL, MF_BYCOMMAND);
        break;
    case IDLE_PRIORITY_CLASS:
        CheckMenuRadioItem(hPriorityMenu, ID_PROCESS_PAGE_SETPRIORITY_REALTIME, ID_PROCESS_PAGE_SETPRIORITY_LOW, ID_PROCESS_PAGE_SETPRIORITY_LOW, MF_BYCOMMAND);
        break;
    }

    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
    {
        dwDebuggerSize = sizeof(strDebugger);
        if (RegQueryValueExW(hKey, L"Debugger", NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) == ERROR_SUCCESS)
        {
            CharUpper(strDebugger);
            if (wcsstr(strDebugger, L"DRWTSN32"))
                EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
        }
        else
            EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);

        RegCloseKey(hKey);
    } else {
        EnableMenuItem(hSubMenu, ID_PROCESS_PAGE_DEBUG, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
    }
    TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL);
    DestroyMenu(hMenu);
}
Exemple #13
0
static VOID ShowStatusMenu(
    _In_ HWND hwndDlg
    )
{
    PPH_STRING cacheEntryName;
        
    cacheEntryName = PhGetSelectedListViewItemText(ListViewWndHandle);

    if (cacheEntryName)
    {
        POINT cursorPos;
        PPH_EMENU menu;
        PPH_EMENU_ITEM selectedItem;

        GetCursorPos(&cursorPos);

        menu = PhCreateEMenu();
        PhInsertEMenuItem(menu, PhCreateEMenuItem(0, 1, L"Remove", NULL, NULL), -1);

        selectedItem = PhShowEMenu(
            menu,
            ListViewWndHandle,
            PH_EMENU_SHOW_LEFTRIGHT,
            PH_ALIGN_LEFT | PH_ALIGN_TOP,
            cursorPos.x,
            cursorPos.y
            );

        if (selectedItem && selectedItem->Id != -1)
        {
            switch (selectedItem->Id)
            {
            case 1:
                {
                    INT lvItemIndex = PhFindListViewItemByFlags(
                        ListViewWndHandle,
                        -1,
                        LVNI_SELECTED
                        );

                    if (lvItemIndex != -1)
                    {
                        if (!PhGetIntegerSetting(L"EnableWarnings") || PhShowConfirmMessage(
                            hwndDlg,
                            L"remove",
                            cacheEntryName->Buffer,
                            NULL,
                            FALSE
                            ))
                        {
                            PATOM_TABLE_INFORMATION atomTable = NULL;

                            if (!NT_SUCCESS(PhEnumAtomTable(&atomTable)))
                                return;

                            for (ULONG i = 0; i < atomTable->NumberOfAtoms; i++)
                            {
                                PATOM_BASIC_INFORMATION atomInfo = NULL;

                                if (!NT_SUCCESS(PhQueryAtomTableEntry(atomTable->Atoms[i], &atomInfo)))
                                    continue;

                                if (!PhEqualStringZ(atomInfo->Name, cacheEntryName->Buffer, TRUE))
                                    continue;

                                do
                                {
                                    if (!NT_SUCCESS(NtDeleteAtom(atomTable->Atoms[i])))
                                    {
                                        break;
                                    }

                                    PhFree(atomInfo);
                                    atomInfo = NULL;

                                    if (!NT_SUCCESS(PhQueryAtomTableEntry(atomTable->Atoms[i], &atomInfo)))
                                        break;

                                } while (atomInfo->UsageCount >= 1);

                                ListView_DeleteItem(ListViewWndHandle, lvItemIndex);

                                if (atomInfo)
                                {
                                    PhFree(atomInfo);
                                }
                            }

                            PhFree(atomTable);
                        }
                    }
                }
                break;
            }
        }

        PhDestroyEMenu(menu);
        PhDereferenceObject(cacheEntryName);
    }
}
Exemple #14
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_COMMAND:

		switch (LOWORD(wParam))
		{
		case ID_PM_REALTIME:
			SetProcessPriority(REALTIME_PRIORITY_CLASS);
			break;
		case ID_PM_HIGH:
			SetProcessPriority(HIGH_PRIORITY_CLASS);
			break;
		case ID_PM_ABOVE_NORMAL:
			SetProcessPriority(ABOVE_NORMAL_PRIORITY_CLASS);
			break;
		case ID_PM_NORMAL:
			SetProcessPriority(NORMAL_PRIORITY_CLASS);
			break;
		case ID_PM_BELOW_NORMAL:
			SetProcessPriority(BELOW_NORMAL_PRIORITY_CLASS);
			break;
		case ID_PM_IDLE:
			SetProcessPriority(IDLE_PRIORITY_CLASS);
			break;
		}

		switch (HIWORD(wParam))
		{
		case 1:
			{
				if (lParam == (LPARAM)ListBoxProcess)
					ShowModule();
			}
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
			break;
		}

		break;

	case WM_CONTEXTMENU:
		if (SendMessage(ListBoxProcess, LB_GETCURSEL, 0, 0) != LB_ERR)
		{
			POINT cursorPosition;
			GetCursorPos(&cursorPosition);
			TrackPopupMenu(PopupMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, cursorPosition.x, cursorPosition.y, 0, hWnd, NULL);
		}
		break;

	case WM_DESTROY:
		PostQuitMessage(0);
		break;

	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
		break;
	}

	return 0;
}
Exemple #15
0
void EMU::update_input()
{
#ifdef USE_SHIFT_NUMPAD_KEY
	// update numpad key status
	if(key_shift_pressed && !key_shift_released) {
		if(key_status[VK_SHIFT] == 0) {
			// shift key is newly pressed
			key_status[VK_SHIFT] = 0x80;
#ifdef NOTIFY_KEY_DOWN
			vm->key_down(VK_SHIFT, false);
#endif
		}
	}
	else if(!key_shift_pressed && key_shift_released) {
		if(key_status[VK_SHIFT] != 0) {
			// shift key is newly released
			key_status[VK_SHIFT] = 0;
#ifdef NOTIFY_KEY_DOWN
			vm->key_up(VK_SHIFT);
#endif
			// check l/r shift
			if(!(GetAsyncKeyState(VK_LSHIFT) & 0x8000)) key_status[VK_LSHIFT] &= 0x7f;
			if(!(GetAsyncKeyState(VK_RSHIFT) & 0x8000)) key_status[VK_RSHIFT] &= 0x7f;
		}
	}
	key_shift_pressed = key_shift_released = false;
#endif
	
	// release keys
#ifdef USE_AUTO_KEY
	if(lost_focus && autokey_phase == 0) {
#else
	if(lost_focus) {
#endif
		// we lost key focus so release all pressed keys
		for(int i = 0; i < 256; i++) {
			if(key_status[i] & 0x80) {
				key_status[i] &= 0x7f;
#ifdef NOTIFY_KEY_DOWN
				if(!key_status[i]) {
					vm->key_up(i);
				}
#endif
			}
		}
	}
	else {
		for(int i = 0; i < 256; i++) {
			if(key_status[i] & 0x7f) {
				key_status[i] = (key_status[i] & 0x80) | ((key_status[i] & 0x7f) - 1);
#ifdef NOTIFY_KEY_DOWN
				if(!key_status[i]) {
					vm->key_up(i);
				}
#endif
			}
		}
	}
	lost_focus = false;
	
	// update joystick status
	memset(joy_status, 0, sizeof(joy_status));
	for(int i = 0; i < joy_num && i < 2; i++) {
		JOYINFOEX joyinfo;
		joyinfo.dwSize = sizeof(JOYINFOEX);
		joyinfo.dwFlags = JOY_RETURNALL;
		if(joyGetPosEx(i, &joyinfo) == JOYERR_NOERROR) {
			if(joyinfo.dwYpos < 0x3fff) joy_status[i] |= 0x01;	// up
			if(joyinfo.dwYpos > 0xbfff) joy_status[i] |= 0x02;	// down
			if(joyinfo.dwXpos < 0x3fff) joy_status[i] |= 0x04;	// left
			if(joyinfo.dwXpos > 0xbfff) joy_status[i] |= 0x08;	// right
			joy_status[i] |= ((joyinfo.dwButtons & joy_mask[i]) << 4);
		}
	}
#ifdef USE_KEY_TO_JOY
	// emulate joystick #1 with keyboard
	if(key_status[0x26]) joy_status[0] |= 0x01;	// up
	if(key_status[0x28]) joy_status[0] |= 0x02;	// down
	if(key_status[0x25]) joy_status[0] |= 0x04;	// left
	if(key_status[0x27]) joy_status[0] |= 0x08;	// right
#endif
	
	// update mouse status
	memset(mouse_status, 0, sizeof(mouse_status));
	if(mouse_enabled) {
		// get current status
		POINT pt;
		GetCursorPos(&pt);
		ScreenToClient(main_window_handle, &pt);
		mouse_status[0]  = pt.x - display_width / 2;
		mouse_status[1]  = pt.y - display_height / 2;
		mouse_status[2]  = (GetAsyncKeyState(VK_LBUTTON) & 0x8000) ? 1 : 0;
		mouse_status[2] |= (GetAsyncKeyState(VK_RBUTTON) & 0x8000) ? 2 : 0;
		mouse_status[2] |= (GetAsyncKeyState(VK_MBUTTON) & 0x8000) ? 4 : 0;
		// move mouse cursor to the center of window
		if(!(mouse_status[0] == 0 && mouse_status[1] == 0)) {
			pt.x = display_width / 2;
			pt.y = display_height / 2;
			ClientToScreen(main_window_handle, &pt);
			SetCursorPos(pt.x, pt.y);
		}
	}
	
#ifdef USE_AUTO_KEY
	// auto key
	switch(autokey_phase) {
	case 1:
		if(autokey_buffer && !autokey_buffer->empty()) {
			// update shift key status
			int shift = autokey_buffer->read_not_remove(0) & 0x100;
			if(shift && !autokey_shift) {
				key_down(VK_SHIFT, false);
			}
			else if(!shift && autokey_shift) {
				key_up(VK_SHIFT);
			}
			autokey_shift = shift;
			autokey_phase++;
			break;
		}
	case 3:
		if(autokey_buffer && !autokey_buffer->empty()) {
			key_down(autokey_buffer->read_not_remove(0) & 0xff, false);
		}
		autokey_phase++;
		break;
	case USE_AUTO_KEY:
		if(autokey_buffer && !autokey_buffer->empty()) {
			key_up(autokey_buffer->read_not_remove(0) & 0xff);
		}
		autokey_phase++;
		break;
	case USE_AUTO_KEY_RELEASE:
		if(autokey_buffer && !autokey_buffer->empty()) {
			// wait enough while vm analyzes one line
			if(autokey_buffer->read() == 0xd) {
				autokey_phase++;
				break;
			}
		}
	case 30:
		if(autokey_buffer && !autokey_buffer->empty()) {
			autokey_phase = 1;
		}
		else {
			stop_auto_key();
		}
		break;
	default:
		if(autokey_phase) {
			autokey_phase++;
		}
	}
#endif
}

#ifdef USE_SHIFT_NUMPAD_KEY
static const int numpad_table[256] = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//	0x00, 0x69, 0x63, 0x61, 0x67, 0x64, 0x68, 0x66, 0x62, 0x00, 0x00, 0x00, 0x00, 0x60, 0x6e, 0x00,
	0x00, 0x69, 0x63, 0x61, 0x67, 0x64, 0x68, 0x66, 0x62, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00,	// remove shift + period
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
#endif

void EMU::key_down(int code, bool repeat)
{
	bool keep_frames = false;
	
	if(code == VK_SHIFT) {
		if(GetAsyncKeyState(VK_LSHIFT) & 0x8000) key_status[VK_LSHIFT] = 0x80;
		if(GetAsyncKeyState(VK_RSHIFT) & 0x8000) key_status[VK_RSHIFT] = 0x80;
		if(!(key_status[VK_LSHIFT] || key_status[VK_RSHIFT])) key_status[VK_LSHIFT] = 0x80;
	}
	else if(code == VK_CONTROL) {
		if(GetAsyncKeyState(VK_LCONTROL) & 0x8000) key_status[VK_LCONTROL] = 0x80;
		if(GetAsyncKeyState(VK_RCONTROL) & 0x8000) key_status[VK_RCONTROL] = 0x80;
		if(!(key_status[VK_LCONTROL] || key_status[VK_RCONTROL])) key_status[VK_LCONTROL] = 0x80;
	}
	else if(code == VK_MENU) {
		if(GetAsyncKeyState(VK_LMENU) & 0x8000) key_status[VK_LMENU] = 0x80;
		if(GetAsyncKeyState(VK_RMENU) & 0x8000) key_status[VK_RMENU] = 0x80;
		if(!(key_status[VK_LMENU] || key_status[VK_RMENU])) key_status[VK_LMENU] = 0x80;
	}
	else if(code == 0xf0) {
		code = VK_CAPITAL;
		keep_frames = true;
	}
	else if(code == 0xf2) {
		code = VK_KANA;
		keep_frames = true;
	}
	else if(code == 0xf3 || code == 0xf4) {
		code = VK_KANJI;
		keep_frames = true;
	}
#ifdef USE_SHIFT_NUMPAD_KEY
	if(code == VK_SHIFT) {
		key_shift_pressed = true;
		return;
	}
	else if(numpad_table[code] != 0) {
		if(key_shift_pressed || key_shift_released) {
			key_converted[code] = 1;
			key_shift_pressed = true;
			code = numpad_table[code];
		}
	}
#endif
	if(!(code == VK_SHIFT || code == VK_CONTROL || code == VK_MENU)) {
		code = keycode_conv[code];
	}
	
#ifdef DONT_KEEEP_KEY_PRESSED
	if(!(code == VK_SHIFT || code == VK_CONTROL || code == VK_MENU)) {
		key_status[code] = KEY_KEEP_FRAMES;
	}
	else
#endif
	key_status[code] = keep_frames ? KEY_KEEP_FRAMES : 0x80;
#ifdef NOTIFY_KEY_DOWN
	if(keep_frames) {
		repeat = false;
	}
	vm->key_down(code, repeat);
#endif
}
WebMouseWheelEvent WebInputEventFactory::mouseWheelEvent(HWND hwnd, UINT message,
                                                         WPARAM wparam, LPARAM lparam)
{
    WebMouseWheelEvent result; //(WebInputEvent::Uninitialized());

    result.type = WebInputEvent::MouseWheel;

    // TODO(pkasting): http://b/1117926 Are we guaranteed that the message that
    // GetMessageTime() refers to is the same one that we're passed in? Perhaps
    // one of the construction parameters should be the time passed by the
    // caller, who would know for sure.
    result.timeStampSeconds = GetMessageTime() / 1000.0;

    result.button = WebMouseEvent::ButtonNone;

    // Get key state, coordinates, and wheel delta from event.
    typedef SHORT (WINAPI *GetKeyStateFunction)(int key);
    GetKeyStateFunction getKeyState;
    UINT keyState;
    float wheelDelta;
    bool horizontalScroll = false;
    if ((message == WM_VSCROLL) || (message == WM_HSCROLL)) {
        // Synthesize mousewheel event from a scroll event.  This is needed to
        // simulate middle mouse scrolling in some laptops.  Use GetAsyncKeyState
        // for key state since we are synthesizing the input event.
        getKeyState = GetAsyncKeyState;
        keyState = 0;
        if (getKeyState(VK_SHIFT))
            keyState |= MK_SHIFT;
        if (getKeyState(VK_CONTROL))
            keyState |= MK_CONTROL;
        // NOTE: There doesn't seem to be a way to query the mouse button state
        // in this case.

        POINT cursorPosition = {0};
        GetCursorPos(&cursorPosition);
        result.globalX = cursorPosition.x;
        result.globalY = cursorPosition.y;

        switch (LOWORD(wparam)) {
        case SB_LINEUP:    // == SB_LINELEFT
            wheelDelta = WHEEL_DELTA;
            break;
        case SB_LINEDOWN:  // == SB_LINERIGHT
            wheelDelta = -WHEEL_DELTA;
            break;
        case SB_PAGEUP:
            wheelDelta = 1;
            result.scrollByPage = true;
            break;
        case SB_PAGEDOWN:
            wheelDelta = -1;
            result.scrollByPage = true;
            break;
        default:  // We don't supoprt SB_THUMBPOSITION or SB_THUMBTRACK here.
            wheelDelta = 0;
            break;
        }

        if (message == WM_HSCROLL)
            horizontalScroll = true;
    } else {
        // Non-synthesized event; we can just read data off the event.
        getKeyState = GetKeyState;
        keyState = GET_KEYSTATE_WPARAM(wparam);

        result.globalX = static_cast<short>(LOWORD(lparam));
        result.globalY = static_cast<short>(HIWORD(lparam));

        wheelDelta = static_cast<float>(GET_WHEEL_DELTA_WPARAM(wparam));
        if (message == WM_MOUSEHWHEEL) {
            horizontalScroll = true;
            wheelDelta = -wheelDelta;  // Windows is <- -/+ ->, WebKit <- +/- ->.
        }
    }
    if (keyState & MK_SHIFT)
        horizontalScroll = true;

    // Set modifiers based on key state.
    if (keyState & MK_SHIFT)
        result.modifiers |= WebInputEvent::ShiftKey;
    if (keyState & MK_CONTROL)
        result.modifiers |= WebInputEvent::ControlKey;
    if (getKeyState(VK_MENU) & 0x8000)
        result.modifiers |= WebInputEvent::AltKey;
    if (keyState & MK_LBUTTON)
        result.modifiers |= WebInputEvent::LeftButtonDown;
    if (keyState & MK_MBUTTON)
        result.modifiers |= WebInputEvent::MiddleButtonDown;
    if (keyState & MK_RBUTTON)
        result.modifiers |= WebInputEvent::RightButtonDown;

    // Set coordinates by translating event coordinates from screen to client.
    POINT clientPoint = { result.globalX, result.globalY };
    MapWindowPoints(0, hwnd, &clientPoint, 1);
    result.x = clientPoint.x;
    result.y = clientPoint.y;
    result.windowX = result.x;
    result.windowY = result.y;

    // Convert wheel delta amount to a number of pixels to scroll.
    //
    // How many pixels should we scroll per line?  Gecko uses the height of the
    // current line, which means scroll distance changes as you go through the
    // page or go to different pages.  IE 7 is ~50 px/line, although the value
    // seems to vary slightly by page and zoom level.  Since IE 7 has a smoothing
    // algorithm on scrolling, it can get away with slightly larger scroll values
    // without feeling jerky.  Here we use 100 px per three lines (the default
    // scroll amount is three lines per wheel tick).
    static const float scrollbarPixelsPerLine = 100.0f / 3.0f;
    wheelDelta /= WHEEL_DELTA;
    float scrollDelta = wheelDelta;
    if (horizontalScroll) {
        unsigned long scrollChars = defaultScrollCharsPerWheelDelta;
        SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0, &scrollChars, 0);
        // TODO(pkasting): Should probably have a different multiplier
        // scrollbarPixelsPerChar here.
        scrollDelta *= static_cast<float>(scrollChars) * scrollbarPixelsPerLine;
    } else {
        unsigned long scrollLines = defaultScrollLinesPerWheelDelta;
        SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &scrollLines, 0);
        if (scrollLines == WHEEL_PAGESCROLL)
            result.scrollByPage = true;
        if (!result.scrollByPage)
            scrollDelta *= static_cast<float>(scrollLines) * scrollbarPixelsPerLine;
    }

    // Set scroll amount based on above calculations.  WebKit expects positive
    // deltaY to mean "scroll up" and positive deltaX to mean "scroll left".
    if (horizontalScroll) {
        result.deltaX = scrollDelta;
        result.wheelTicksX = wheelDelta;
    } else {
        result.deltaY = scrollDelta;
        result.wheelTicksY = wheelDelta;
    }

    return result;
}
bool CGUIDialogKeyboardGeneric::OnAction(const CAction &action)
{
  bool handled(true);
  if (action.GetID() == ACTION_BACKSPACE)
  {
    Backspace();
  }
  else if (action.GetID() == ACTION_ENTER)
  {
    OnOK();
  }
  else if (action.GetID() == ACTION_CURSOR_LEFT)
  {
    MoveCursor( -1);
  }
  else if (action.GetID() == ACTION_CURSOR_RIGHT)
  {
    if (m_strEditing.IsEmpty() && (unsigned int) GetCursorPos() == m_strEdit.size() && (m_strEdit.size() == 0 || m_strEdit[m_strEdit.size() - 1] != ' '))
    { // add a space
      Character(L' ');
    }
    else
      MoveCursor(1);
  }
  else if (action.GetID() == ACTION_SHIFT)
  {
    OnShift();
  }
  else if (action.GetID() == ACTION_SYMBOLS)
  {
    OnSymbols();
  }
  else if (action.GetID() >= REMOTE_0 && action.GetID() <= REMOTE_9)
  {
    OnRemoteNumberClick(action.GetID());
  }
  else if (action.GetID() == ACTION_PASTE)
  {
    OnPasteClipboard();
  }
  else if (action.GetID() >= KEY_VKEY && action.GetID() < KEY_ASCII)
  { // input from the keyboard (vkey, not ascii)
    if (!m_strEditing.IsEmpty())
      return handled;
    uint8_t b = action.GetID() & 0xFF;
    if (b == XBMCVK_HOME)
    {
      SetCursorPos(0);
    }
    else if (b == XBMCVK_END)
    {
      SetCursorPos(m_strEdit.GetLength());
    }
    else if (b == XBMCVK_LEFT)
    {
      MoveCursor( -1);
    }
    else if (b == XBMCVK_RIGHT)
    {
      MoveCursor(1);
    }
    else if (b == XBMCVK_RETURN || b == XBMCVK_NUMPADENTER)
    {
      OnOK();
    }
    else if (b == XBMCVK_DELETE)
    {
      if (GetCursorPos() < m_strEdit.GetLength())
      {
        MoveCursor(1);
        Backspace();
      }
    }
    else if (b == XBMCVK_BACK) Backspace();
    else if (b == XBMCVK_ESCAPE) Close();
  }
  else if (action.GetID() >= KEY_ASCII)
  { // input from the keyboard
    //char ch = action.GetID() & 0xFF;
    int ch = action.GetUnicode();
    
    // Ignore non-printing characters
    if ( !((0 <= ch && ch < 0x8) || (0xE <= ch && ch < 0x1B) || (0x1C <= ch && ch < 0x20)) )
    {
      switch (ch)
      {
      case 0x8: // backspace
        Backspace();
        break;
      case 0x9: // Tab (do nothing)
      case 0xB: // Non-printing character, ignore
      case 0xC: // Non-printing character, ignore
        break;
      case 0xA: // enter
      case 0xD: // enter
        OnOK();
        break;
      case 0x1B: // escape
        Close();
        break;
      case 0x7F: // Delete
        if (GetCursorPos() < m_strEdit.GetLength())
        {
          MoveCursor(1);
          Backspace();
        }
        break;
      default:  //use character input
        // When we support text input method, we only accept text by gui text message.
        if (!g_Windowing.IsTextInputEnabled())
          Character(action.GetUnicode());
        break;
      }
    }
  }
  else // unhandled by us - let's see if the baseclass wants it
    handled = CGUIDialog::OnAction(action);

  if (handled && m_pCharCallback)
  { // we did _something_, so make sure our search message filter is reset
    m_pCharCallback(this, GetText());
  }
  return handled;
}
//--------------------------------------------------------------------------------------//
void CBCGPDragFrameImpl::MoveDragFrame (BOOL bForceMove)
{
	ASSERT_VALID (m_pDraggedWnd);

	m_pFinalTargetBar = NULL;

	if (m_pDraggedWnd == NULL || m_pDockManager == NULL)
	{
		return;
	}

	if (m_pWndDummy == NULL)
	{
		m_pWndDummy = new CBCGPDummyDockingControlBar;
		m_pWndDummy->CreateEx (0, _T (""), BCGCBProGetTopLevelFrame (m_pDraggedWnd), CRect (0, 0, 0, 0), 
							FALSE, BCGP_DUMMY_WND_ID, WS_CHILD);
	}

	CSize szSencitivity = CBCGPDockingControlBar::GetDragSencitivity ();

	CPoint ptMouse;
	GetCursorPos (&ptMouse);

	CPoint ptOffset = ptMouse - m_ptHot;

	if (abs (ptOffset.x) < szSencitivity.cx && 
		abs (ptOffset.y) < szSencitivity.cy && 
		m_rectDrag.IsRectEmpty () && !bForceMove)
	{
		return;
	}

	m_bDragStarted = TRUE;
	
	m_pDockManager->LockUpdate (TRUE);
		
	CRect rectOld = m_rectExpectedDocked.IsRectEmpty () ? m_rectDrag : m_rectExpectedDocked;
	BOOL bFirstTime = FALSE;

	if (m_rectDrag.IsRectEmpty ())
	{
		if (m_pDraggedWnd->IsKindOf (RUNTIME_CLASS (CBCGPMiniFrameWnd)))
		{
			m_pDraggedWnd->GetWindowRect (m_rectDrag);
		}
		else if (m_pDraggedWnd->IsKindOf (RUNTIME_CLASS (CBCGPControlBar)))
		{
			CBCGPControlBar* pBar = 
				DYNAMIC_DOWNCAST (CBCGPControlBar, m_pDraggedWnd);
			ASSERT_VALID (pBar);
			m_pDraggedWnd->GetWindowRect (m_rectDrag);

			// if the bar is docked then the floating rect has to be set to recent floating rect
			if (pBar->GetParentMiniFrame () == NULL)
			{
				m_rectDrag.right = 
					m_rectDrag.left + pBar->m_recentDockInfo.m_rectRecentFloatingRect.Width ();
				m_rectDrag.bottom = 
					m_rectDrag.top + pBar->m_recentDockInfo.m_rectRecentFloatingRect.Height ();
			}

			if (!m_rectDrag.PtInRect (m_ptHot))
			{
				int nOffset = m_rectDrag.left - m_ptHot.x;
				m_rectDrag.OffsetRect (-nOffset - 5, 0); // offset of mouse pointer 
														 // from the drag rect bound
			}
		}
		bFirstTime = TRUE;
	}


	BOOL bDrawTab = FALSE;
	CBCGPDockingControlBar* pOldTargetBar = m_pTargetBar;
	CRect rectExpected; rectExpected.SetRectEmpty ();

    CBCGPSmartDockingManager* pSDManager = NULL;
    BOOL bSDockingIsOn = FALSE;

    if (m_pDockManager != NULL
        && (pSDManager = m_pDockManager->GetSDManagerPermanent()) != NULL
        && pSDManager->IsStarted())
    {
        bSDockingIsOn = TRUE;
    }

	
	m_pDockManager->CalcExpectedDockedRect (m_pDraggedWnd, ptMouse, 
							rectExpected, bDrawTab, &m_pTargetBar);

	if (pOldTargetBar != NULL && m_nInsertedTabID != -1 && 
		(pOldTargetBar != m_pTargetBar || !bDrawTab))
	{
        RemoveTabPreDocking (pOldTargetBar);
		bFirstTime = TRUE;
	}

	BOOL bCanBeAttached = TRUE;
	if (m_pDraggedWnd->IsKindOf (RUNTIME_CLASS (CBCGPMiniFrameWnd)))
	{
	}
	else if (m_pDraggedWnd->IsKindOf (RUNTIME_CLASS (CBCGPControlBar)))
	{
		CBCGPControlBar* pBar = 
			DYNAMIC_DOWNCAST (CBCGPControlBar, m_pDraggedWnd);
		bCanBeAttached = pBar->CanBeAttached ();
	}

	if (m_pTargetBar != NULL && bCanBeAttached)
	{
		CBCGPBaseTabbedBar* pTabbedBar = 
				DYNAMIC_DOWNCAST (CBCGPBaseTabbedBar, m_pTargetBar);
		if (pTabbedBar != NULL && bDrawTab && 
			 (pTabbedBar->GetVisibleTabsNum () > 1 && pTabbedBar->IsHideSingleTab () ||
			  pTabbedBar->GetVisibleTabsNum () > 0 && !pTabbedBar->IsHideSingleTab ()))
		{
			PlaceTabPreDocking (pTabbedBar, bFirstTime);
			return;
		}
		else if (bDrawTab)
		{
			if (m_nInsertedTabID != -1)
			{
				return;
			}
			if (!bFirstTime)
			{
				EndDrawDragFrame (FALSE);
			}
			DrawFrameTab (m_pTargetBar, FALSE);
			m_nInsertedTabID = 1;
			return;
		}
	}	
	
	m_rectDrag.OffsetRect (ptOffset);
	m_ptHot = ptMouse;

	m_rectExpectedDocked = rectExpected;

	int nNewThickness = m_rectExpectedDocked.IsRectEmpty ()? 
							globalData.m_nDragFrameThiknessFloat : 
							globalData.m_nDragFrameThiknessDock;

	CRect rectDocked;
	if (m_rectExpectedDocked.IsRectEmpty ())
	{
		if (!m_rectDrag.PtInRect (ptMouse))
		{
			CPoint ptMiddleRect (m_rectDrag.TopLeft ().x + m_rectDrag.Width () / 2, 
								 m_rectDrag.top + 5);

			CPoint ptOffset = ptMouse - ptMiddleRect;
			m_rectDrag.OffsetRect (ptOffset);
		}
		rectDocked = m_rectDrag;
	}
	else
	{
		rectDocked = m_rectExpectedDocked;
	}
	if (!bSDockingIsOn || !m_rectExpectedDocked.IsRectEmpty ())
	{
		DrawDragFrame (rectOld, rectDocked, bFirstTime, nNewThickness, m_nOldThikness);
		m_nOldThikness = nNewThickness;
	}
	
}
bool CGUIDialogKeyboard::OnAction(const CAction &action)
{
  // check if we're doing a search, and if so, interrupt the search timer.
  DWORD now = timeGetTime();
  if (m_lastSearchUpdate || m_lastSearchUpdate + SEARCH_DELAY >= now)
    m_lastSearchUpdate = now;

  if (action.wID == ACTION_BACKSPACE
#ifdef __APPLE__
     || action.wID == ACTION_PARENT_DIR
#endif
     )
  {
    Backspace();
    return true;
  }
  else if (action.wID == ACTION_ENTER)
  {
    OnOK();
    return true;
  }
  else if (action.wID == ACTION_CURSOR_LEFT)
  {
    MoveCursor( -1);
    return true;
  }
  else if (action.wID == ACTION_CURSOR_RIGHT)
  {
    if ((unsigned int) GetCursorPos() == m_strEdit.size() && (m_strEdit.size() == 0 || m_strEdit[m_strEdit.size() - 1] != ' '))
    { // add a space
      Character(L' ');
    }
    else
      MoveCursor(1);
    return true;
  }
  else if (action.wID == ACTION_SHIFT)
  {
    OnShift();
    return true;
  }
  else if (action.wID == ACTION_SYMBOLS)
  {
    OnSymbols();
    return true;
  }
  else if (action.wID >= REMOTE_0 && action.wID <= REMOTE_9)
  {
    OnRemoteNumberClick(action.wID);
    return true;
  }
  else if (action.wID >= (WORD)KEY_VKEY && action.wID < (WORD)KEY_ASCII)
  { // input from the keyboard (vkey, not ascii)
    BYTE b = action.wID & 0xFF;
    if (b == 0x25) MoveCursor( -1);     // left
    else if (b == 0x27) MoveCursor(1);  // right
    else if (b == 0x0D) OnOK();         // enter
    else if (b == 0x08) Backspace();    // backspace
    else if (b == 0x1B) Close();        // escape
    else if (b == 0x20) Character(b);   // space
    return true;
  }
  else if (action.wID >= KEY_ASCII)
  { // input from the keyboard
    //char ch = action.wID & 0xFF;
    switch (action.unicode)
    {
    case 13:  // enter
    case 10:  // enter
      OnOK();
      break;
    case 8:   // backspace
      Backspace();
      break;
    case 27:  // escape
      Close();
      break;
    default:  //use character input
      Character(action.unicode);
      break;
    }
    return true;
  }
  return CGUIDialog::OnAction(action);
}
//
// Process mouse click in the target list.  For a worker, assign the selected
// target.  For a manager, distribute the assigned targets among its net servers.
//
void CPageNetwork::OnClickTTargets(NMHDR* pNMHDR, LRESULT* pResult) 
{
	CPoint point;
	TV_HITTESTINFO test_info;
	TargetSelType state;

	// Get the cursor position.
	GetCursorPos( &point );
	test_info.pt = point;
	m_TTargets.ScreenToClient( &(test_info.pt) );

	// Check to see whether the cursor is on an item.
	m_TTargets.HitTest( &test_info );

	// Check that we have an interface item.
	if ( !test_info.hItem || !m_TTargets.GetParentItem( test_info.hItem ) )
		return;

	// A new target assignment is being made.  Clear the results since they are
	// for a configuration we no longer have.
	theApp.pView->ResetDisplayforNewTest();

	// Toggle the selection if the control key is pressed.
	if ( GetKeyState( VK_CONTROL ) & 0x8000 && 
		GetSelectionCheck( test_info.hItem ) == TargetChecked )
	{
		state = TargetUnChecked;
	}
	else
	{
		state = TargetChecked;
	}

	switch ( theApp.pView->m_pWorkerView->GetSelectedType() )
	{
	case WORKER:
		// All clicks work the same for the worker.
		SelectRange( test_info.hItem, test_info.hItem, TRUE, state );
		break;
	case MANAGER:
		// A shift click extends the selection from the last selected item
		// to the currently focused item.  When the control key is also
		// pressed, any previous selection is not cleared.
		if ( (GetKeyState( VK_SHIFT ) & 0x8000 ) && selected )
		{
			// We have a previous item (not the first click) and the shift
			// key is down.
			SelectRange( selected, test_info.hItem, 
				!(GetKeyState( VK_CONTROL ) & 0x8000) );
		}
		else if ( GetKeyState( VK_CONTROL ) & 0x8000 )
		{
			// The control key is down.
			SelectRange( test_info.hItem, test_info.hItem, FALSE, state );
		}
		else 
		{
			SelectRange( test_info.hItem, test_info.hItem, TRUE, state );
		}
		break;
	default:
		ErrorMessage( "Unexpected selection type in CPageNetwork::"
			"OnClickTTargets()." );
		return;
	}

	// immediately refresh the display (create/delete NetClients as needed)
	StoreTargetSelection();
	ShowSettings();
	EnableWindow();

	*pResult = 0;
}
Exemple #21
0
void CNewRandom::Initialize()
{
	++g_dwNewRandomInstanceCounter;

	DWORD dw;
	dw = timeGetTime();
	AddRandomObject(&dw, 4);

	LARGE_INTEGER li;
	QueryPerformanceCounter(&li);
	AddRandomObject(&li, sizeof(LARGE_INTEGER));

	SYSTEMTIME st;
	ZeroMemory(&st, sizeof(SYSTEMTIME));
	GetLocalTime(&st);
	AddRandomObject(&st, sizeof(SYSTEMTIME));

	POINT pt;
	GetCursorPos(&pt);
	AddRandomObject(&pt, sizeof(POINT));

	WORD ww;
	ww = (WORD)(rand());
	AddRandomObject(&ww, 2);
	ww = (WORD)(rand());
	AddRandomObject(&ww, 2);
	ww = (WORD)(rand());
	AddRandomObject(&ww, 2);

	GetCaretPos(&pt);
	AddRandomObject(&pt, sizeof(POINT));

	MEMORYSTATUS ms;
	GlobalMemoryStatus(&ms);
	AddRandomObject(&ms, sizeof(MEMORYSTATUS));

	dw = (DWORD)(UINT_PTR)GetActiveWindow();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetCapture();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetClipboardOwner();
	AddRandomObject(&dw, 4);

#ifndef _WIN32_WCE
	// No support under Windows CE
	dw = (DWORD)(UINT_PTR)GetClipboardViewer();
	AddRandomObject(&dw, 4);
#endif

	dw = GetCurrentProcessId();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetCurrentProcess();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetActiveWindow();
	AddRandomObject(&dw, 4);

	dw = GetCurrentThreadId();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetCurrentThread();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetDesktopWindow();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetFocus();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetForegroundWindow();
	AddRandomObject(&dw, 4);

#ifndef _WIN32_WCE
	dw = (DWORD)GetInputState();
	AddRandomObject(&dw, 4); 
#endif

	dw = GetMessagePos();
	AddRandomObject(&dw, 4);

#ifndef _WIN32_WCE
	dw = (DWORD)GetMessageTime();
	AddRandomObject(&dw, 4);
#endif

	dw = (DWORD)(UINT_PTR)GetOpenClipboardWindow();
	AddRandomObject(&dw, 4);

	dw = (DWORD)(UINT_PTR)GetProcessHeap();
	AddRandomObject(&dw, 4);

	SYSTEM_INFO si;
	GetSystemInfo(&si);
	AddRandomObject(&si, sizeof(SYSTEM_INFO));

	dw = (DWORD)randXorShift();
	AddRandomObject(&dw, 4);

#ifndef _WIN32_WCE
	STARTUPINFO sui;
	GetStartupInfo(&sui);
	AddRandomObject(&sui, sizeof(STARTUPINFO));
#endif

	GUID guid;
	VERIFY(CoCreateGuid(&guid) == S_OK);
	AddRandomObject(&guid, sizeof(GUID));

	BYTE pbCrypt[64];
	CNewRandom::SysCryptGetRandom(&pbCrypt[0], 64);
	AddRandomObject(&pbCrypt[0], 64);

	AddRandomObject(&g_dwNewRandomInstanceCounter, 4);
}
Exemple #22
0
INT_PTR CALLBACK DlgProcIconImport(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static HWND hwndParent, hwndDragOver;
	static int dragging;
	static int dragItem, dropHiLite;
	static HWND hPreview = NULL;

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		hwndParent = (HWND)lParam;
		hPreview = GetDlgItem(hwndDlg, IDC_PREVIEW);
		dragging = dragItem = 0;
		ListView_SetImageList(hPreview, ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32|ILC_MASK, 0, 100), LVSIL_NORMAL);
		ListView_SetIconSpacing(hPreview, 56, 67);
		{
			RECT rcThis, rcParent;
			int cxScreen = GetSystemMetrics(SM_CXSCREEN);

			GetWindowRect(hwndDlg, &rcThis);
			GetWindowRect(hwndParent, &rcParent);
			OffsetRect(&rcThis, rcParent.right-rcThis.left, 0);
			OffsetRect(&rcThis, 0, rcParent.top-rcThis.top);
			GetWindowRect(GetParent(hwndParent), &rcParent);
			if (rcThis.right > cxScreen) {
				OffsetRect(&rcParent, cxScreen-rcThis.right, 0);
				OffsetRect(&rcThis, cxScreen-rcThis.right, 0);
				MoveWindow(GetParent(hwndParent), rcParent.left, rcParent.top, rcParent.right-rcParent.left, rcParent.bottom-rcParent.top, TRUE);
			}
			MoveWindow(hwndDlg, rcThis.left, rcThis.top, rcThis.right-rcThis.left, rcThis.bottom-rcThis.top, FALSE);
			GetClientRect(hwndDlg, &rcThis);
			SendMessage(hwndDlg, WM_SIZE, 0, MAKELPARAM(rcThis.right-rcThis.left, rcThis.bottom-rcThis.top));
		}

		SHAutoComplete( GetDlgItem(hwndDlg, IDC_ICONSET), 1);

		SetDlgItemText(hwndDlg, IDC_ICONSET, _T("icons.dll"));
		return TRUE;

	case DM_REBUILDICONSPREVIEW:
		{
			MySetCursor(IDC_WAIT);
			ListView_DeleteAllItems(hPreview);
			HIMAGELIST hIml = ListView_GetImageList(hPreview, LVSIL_NORMAL);
			ImageList_RemoveAll(hIml);

			TCHAR filename[MAX_PATH], caption[64];
			GetDlgItemText(hwndDlg, IDC_ICONSET, filename, SIZEOF(filename));
			{
				RECT rcPreview, rcGroup;

				GetWindowRect(hPreview, &rcPreview);
				GetWindowRect( GetDlgItem(hwndDlg, IDC_IMPORTMULTI), &rcGroup);
				//SetWindowPos(hPreview, 0, 0, 0, rcPreview.right-rcPreview.left, rcGroup.bottom-rcPreview.top, SWP_NOZORDER|SWP_NOMOVE);
			}

			if ( _taccess(filename, 0) != 0) {
				MySetCursor(IDC_ARROW);
				break;
			}

			LVITEM lvi;
			lvi.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
			lvi.iSubItem = 0;
			lvi.iItem = 0;
			int count = (int)_ExtractIconEx(filename, -1, 16, 16, NULL, LR_DEFAULTCOLOR);
			for (int i=0; i < count; lvi.iItem++, i++) {
				mir_sntprintf(caption, SIZEOF(caption), _T("%d"), i+1);
				lvi.pszText = caption;

				HICON hIcon;
				_ExtractIconEx(filename, i, 16, 16, &hIcon, LR_DEFAULTCOLOR);
				lvi.iImage = ImageList_AddIcon(hIml, hIcon);
				DestroyIcon(hIcon);
				lvi.lParam = i;
				ListView_InsertItem(hPreview, &lvi);
			}
			MySetCursor(IDC_ARROW);
		}
		break;

	case WM_COMMAND:
		switch(LOWORD(wParam)) {
		case IDC_BROWSE:
			{
				TCHAR str[MAX_PATH], *file;
				GetDlgItemText(hwndDlg, IDC_ICONSET, str, SIZEOF(str));
				if (!(file = OpenFileDlg(GetParent(hwndDlg), str, TRUE)))
					break;
				SetDlgItemText(hwndDlg, IDC_ICONSET, file);
				SAFE_FREE((void**)&file);
			}
			break;

		case IDC_GETMORE:
			OpenIconsPage();
			break;

		case IDC_ICONSET:
			if (HIWORD(wParam) == EN_CHANGE)
				SendMessage(hwndDlg, DM_REBUILDICONSPREVIEW, 0, 0);
			break;
		}
		break;

	case WM_MOUSEMOVE:
		if (dragging) {
			LVHITTESTINFO lvhti;
			int onItem = 0;
			HWND hwndOver;
			RECT rc;
			POINT ptDrag;
			HWND hPPreview = GetDlgItem(hwndParent, IDC_PREVIEW);

			lvhti.pt.x = (short)LOWORD(lParam); lvhti.pt.y = (short)HIWORD(lParam);
			ClientToScreen(hwndDlg, &lvhti.pt);
			hwndOver = WindowFromPoint(lvhti.pt);
			GetWindowRect(hwndOver, &rc);
			ptDrag.x = lvhti.pt.x - rc.left; ptDrag.y = lvhti.pt.y - rc.top;
			if (hwndOver != hwndDragOver) {
				ImageList_DragLeave(hwndDragOver);
				hwndDragOver = hwndOver;
				ImageList_DragEnter(hwndDragOver, ptDrag.x, ptDrag.y);
			}

			ImageList_DragMove(ptDrag.x, ptDrag.y);
			if (hwndOver == hPPreview) {
				ScreenToClient(hPPreview, &lvhti.pt);

				if (ListView_HitTest(hPPreview, &lvhti) != -1) {
					if (lvhti.iItem != dropHiLite) {
						ImageList_DragLeave(hwndDragOver);
						if (dropHiLite != -1)
							ListView_SetItemState(hPPreview, dropHiLite, 0, LVIS_DROPHILITED);
						dropHiLite = lvhti.iItem;
						ListView_SetItemState(hPPreview, dropHiLite, LVIS_DROPHILITED, LVIS_DROPHILITED);
						UpdateWindow(hPPreview);
						ImageList_DragEnter(hwndDragOver, ptDrag.x, ptDrag.y);
					}
					onItem = 1;
				}
			}

			if (!onItem && dropHiLite != -1) {
				ImageList_DragLeave(hwndDragOver);
				ListView_SetItemState(hPPreview, dropHiLite, 0, LVIS_DROPHILITED);
				UpdateWindow(hPPreview);
				ImageList_DragEnter(hwndDragOver, ptDrag.x, ptDrag.y);
				dropHiLite = -1;
			}
			MySetCursor(onItem ? IDC_ARROW : IDC_NO);
		}
		break;

	case WM_LBUTTONUP:
		if (dragging) {
			ReleaseCapture();
			ImageList_EndDrag();
			dragging = 0;
			if (dropHiLite != -1) {
				TCHAR path[MAX_PATH], fullPath[MAX_PATH], filename[MAX_PATH];
				LVITEM lvi;

				GetDlgItemText(hwndDlg, IDC_ICONSET, fullPath, SIZEOF(fullPath));
				PathToRelativeT(fullPath, filename);
				lvi.mask = LVIF_PARAM;
				lvi.iItem = dragItem; lvi.iSubItem = 0;
				ListView_GetItem(hPreview, &lvi);
				mir_sntprintf(path, SIZEOF(path), _T("%s,%d"), filename, (int)lvi.lParam);
				SendMessage(hwndParent, DM_CHANGEICON, dropHiLite, (LPARAM)path);
				ListView_SetItemState( GetDlgItem(hwndParent, IDC_PREVIEW), dropHiLite, 0, LVIS_DROPHILITED);
			}
		}
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case IDC_PREVIEW:
			switch (((LPNMHDR)lParam)->code) {
			case LVN_BEGINDRAG:
				SetCapture(hwndDlg);
				dragging = 1;
				dragItem = ((LPNMLISTVIEW)lParam)->iItem;
				dropHiLite = -1;
				ImageList_BeginDrag(ListView_GetImageList(hPreview, LVSIL_NORMAL), dragItem, GetSystemMetrics(SM_CXICON)/2, GetSystemMetrics(SM_CYICON)/2);
				{
					POINT pt;
					RECT rc;

					GetCursorPos(&pt);
					GetWindowRect(hwndDlg, &rc);
					ImageList_DragEnter(hwndDlg, pt.x - rc.left, pt.y - rc.top);
					hwndDragOver = hwndDlg;
				}
				break;
			}
			break;
		}
		break;

	case WM_SIZE: // make the dlg resizeable
		if (!IsIconic(hwndDlg)) {
			UTILRESIZEDIALOG urd = {0};
			urd.cbSize = sizeof(urd);
			urd.hInstance = hInst;
			urd.hwndDlg = hwndDlg;
			urd.lParam = 0; // user-defined
			urd.lpTemplate = MAKEINTRESOURCEA(IDD_ICOLIB_IMPORT);
			urd.pfnResizer = IconDlg_Resize;
			CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
		}
		break;

	case WM_CLOSE:
		DestroyWindow(hwndDlg);
		EnableWindow( GetDlgItem(hwndParent, IDC_IMPORT), TRUE);
		break;

	}

	return FALSE;
}
Exemple #23
0
static int
gather_random_fast( void (*add)(const void*, size_t, int), int requester )
{
    static int addedFixedItems = 0;

    if ( debug_me )
	log_debug ("rndw32#gather_random_fast: req=%d\n", requester );

    /* Get various basic pieces of system information: Handle of active
     * window, handle of window with mouse capture, handle of clipboard owner
     * handle of start of clpboard viewer list, pseudohandle of current
     * process, current process ID, pseudohandle of current thread, current
     * thread ID, handle of desktop window, handle  of window with keyboard
     * focus, whether system queue has any events, cursor position for last
     * message, 1 ms time for last message, handle of window with clipboard
     * open, handle of process heap, handle of procs window station, types of
     * events in input queue, and milliseconds since Windows was started */
    {	byte buffer[20*sizeof(ulong)], *bufptr;
	bufptr = buffer;
      #define ADD(f)  do { ulong along = (ulong)(f);		      \
			   memcpy (bufptr, &along, sizeof (along) );  \
			   bufptr += sizeof (along); } while (0)
	ADD ( GetActiveWindow ());
	ADD ( GetCapture ());
	ADD ( GetClipboardOwner ());
	ADD ( GetClipboardViewer ());
	ADD ( GetCurrentProcess ());
	ADD ( GetCurrentProcessId ());
	ADD ( GetCurrentThread ());
	ADD ( GetCurrentThreadId ());
	ADD ( GetDesktopWindow ());
	ADD ( GetFocus ());
	ADD ( GetInputState ());
	ADD ( GetMessagePos ());
	ADD ( GetMessageTime ());
	ADD ( GetOpenClipboardWindow ());
	ADD ( GetProcessHeap ());
	ADD ( GetProcessWindowStation ());
	ADD ( GetQueueStatus (QS_ALLEVENTS));
	ADD ( GetTickCount ());

	assert ( bufptr-buffer < sizeof (buffer) );
	(*add) ( buffer, bufptr-buffer, requester );
      #undef ADD
    }

    /* Get multiword system information: Current caret position, current
     * mouse cursor position */
    {	POINT point;
	GetCaretPos (&point);
	(*add) ( &point, sizeof (point), requester );
	GetCursorPos (&point);
	(*add) ( &point, sizeof (point), requester );
    }

    /* Get percent of memory in use, bytes of physical memory, bytes of free
     * physical memory, bytes in paging file, free bytes in paging file, user
     * bytes of address space, and free user bytes */
    {	MEMORYSTATUS memoryStatus;
	memoryStatus.dwLength = sizeof (MEMORYSTATUS);
	GlobalMemoryStatus (&memoryStatus);
	(*add) ( &memoryStatus, sizeof (memoryStatus), requester );
    }

    /* Get thread and process creation time, exit time, time in kernel mode,
       and time in user mode in 100ns intervals */
    {	HANDLE handle;
	FILETIME creationTime, exitTime, kernelTime, userTime;
	DWORD minimumWorkingSetSize, maximumWorkingSetSize;

	handle = GetCurrentThread ();
	GetThreadTimes (handle, &creationTime, &exitTime,
					       &kernelTime, &userTime);
	(*add) ( &creationTime, sizeof (creationTime), requester );
	(*add) ( &exitTime, sizeof (exitTime), requester );
	(*add) ( &kernelTime, sizeof (kernelTime), requester );
	(*add) ( &userTime, sizeof (userTime), requester );

	handle = GetCurrentProcess ();
	GetProcessTimes (handle, &creationTime, &exitTime,
						&kernelTime, &userTime);
	(*add) ( &creationTime, sizeof (creationTime), requester );
	(*add) ( &exitTime, sizeof (exitTime), requester );
	(*add) ( &kernelTime, sizeof (kernelTime), requester );
	(*add) ( &userTime, sizeof (userTime), requester );

	/* Get the minimum and maximum working set size for the current process */
	GetProcessWorkingSetSize (handle, &minimumWorkingSetSize,
					  &maximumWorkingSetSize);
	(*add) ( &minimumWorkingSetSize,
				   sizeof (&minimumWorkingSetSize), requester );
	(*add) ( &maximumWorkingSetSize,
				   sizeof (&maximumWorkingSetSize), requester );
    }


    /* The following are fixed for the lifetime of the process so we only
     * add them once */
    if (!addedFixedItems) {
	STARTUPINFO startupInfo;

	/* Get name of desktop, console window title, new window position and
	 * size, window flags, and handles for stdin, stdout, and stderr */
	startupInfo.cb = sizeof (STARTUPINFO);
	GetStartupInfo (&startupInfo);
	(*add) ( &startupInfo, sizeof (STARTUPINFO), requester );
	addedFixedItems = 1;
    }

    /* The performance of QPC varies depending on the architecture it's
     * running on and on the OS.  Under NT it reads the CPU's 64-bit timestamp
     * counter (at least on a Pentium and newer '486's, it hasn't been tested
     * on anything without a TSC), under Win95 it reads the 1.193180 MHz PIC
     * timer.  There are vague mumblings in the docs that it may fail if the
     * appropriate hardware isn't available (possibly '386's or MIPS machines
     * running NT), but who's going to run NT on a '386? */
    {	LARGE_INTEGER performanceCount;
	if (QueryPerformanceCounter (&performanceCount)) {
	    if ( debug_me )
		log_debug ("rndw32#gather_random_fast: perf data\n");
	    (*add) (&performanceCount, sizeof (&performanceCount), requester);
	}
	else { /* Millisecond accuracy at best... */
	    DWORD aword = GetTickCount ();
	    (*add) (&aword, sizeof (aword), requester );
	}
    }

    return 0;
}
Exemple #24
0
void doFlyEffect(LICE_IBitmap *fb, HWND hwnd)
{
    static int initted;
    if (!initted)
    {
        initted=1;
        cam = new pl_Cam;
        cam->Fov=90.0;
        cam->WantZBuffer=true;
        if (cam->WantZBuffer) cam->Sort = -1;
        cam->Y = 800; // move the camera up from the ground
        cam->Pitch = 180.0;

        setup_materials(mat); // intialize materials and palette

        land = setup_landscape(mat[0],mat[1],mat[2]); // create landscape
        sky = land->Children.Get(0); // unhierarchicalize the sky from the land
        land->Children.Delete(0);
        sky2 = land->Children.Get(0);
        land->Children.Delete(0);

        int x;
        for(x=0; x<sizeof(lights)/sizeof(lights[0]); x++)
        {
            lights[x].Set(PL_LIGHT_POINT,(x%4 - 1.5) * LAND_SIZE /4.0,
                          500+(rand()%1000),
                          (x/4-1.5)*LAND_SIZE/4.0,(rand()%1000)/700.0,(rand()%1000)/700.0,(rand()%1000)/700.0,LAND_SIZE*1.0);
        }

    }

    LICE_Clear(fb,0);
    cam->Begin(fb);

    int x;
    for(x=0; x<sizeof(lights)/sizeof(lights[0]); x++)
        cam->RenderLight(&lights[x]);

    // lots of rendering special casing
    if (draw_sky) { // if we're drawing the sky
        if (cam->Y > 2000) { // if above the sky, only render the skies, with
            // no far clip plane

            cam->RenderObject(sky);
            cam->RenderObject(sky2);
        } else {           // otherwise, render the sky (but not the second sky),
            // and the land, with a far clip plane


            cam->RenderObject(sky);
            cam->RenderObject(land);
        }
    } else { // not drawing sky, just render the land

        cam->RenderObject(land);
    }
    cam->End(); // finish rendering

    static POINT lpos;
    POINT p;
    GetCursorPos(&p);
    int mouse_x  = 0;
    int mouse_y  = 0;
    int mouse_b=0;

    if (hwnd)
    {
        mouse_x = p.x-lpos.x;
        mouse_y = p.y-lpos.y;
        if (GetAsyncKeyState(VK_LBUTTON)&0x8000) mouse_b|=2;

        RECT r;
        GetWindowRect(hwnd,&r);
        p.x=(r.right+r.left)/2;
        p.y=(r.bottom+r.top)/2;
        SetCursorPos(p.x,p.y);
    }
    lpos=p;
    // We calculate the amount of time in thousanths of seconds this frame took
    double prevtime = 10; //((uclock() / (float) UCLOCKS_PER_SEC) - prevtime)*1000.0;

    if (mouse_b & 2) { // if right button hit, we go forward quickly
        cam->X -=
            prevtime*4*sin(cam->Pan*PL_PI/180.0)*cos(cam->Pitch*PL_PI/180.0);
        cam->Z +=
            prevtime*4*cos(cam->Pan*PL_PI/180.0)*cos(cam->Pitch*PL_PI/180.0);
        cam->Y +=
            prevtime*4*sin(cam->Pitch*PL_PI/180.0);
    } else if (mouse_b & 1) { // if left button hit, we go forward slowly
        cam->X -=
            prevtime*2*sin(cam->Pan*PL_PI/180.0)*cos(cam->Pitch*PL_PI/180.0);
        cam->Z +=
            prevtime*2*cos(cam->Pan*PL_PI/180.0)*cos(cam->Pitch*PL_PI/180.0);
        cam->Y +=
            prevtime*2*sin(cam->Pitch*PL_PI/180.0);
    }
    cam->Pitch += (mouse_y*mouse_sens); // update pitch and pan of ship
    cam->Pan += (mouse_x*mouse_sens)*(-cos(cam->Pitch*PL_PI/180.0));

    if (cam->X > LAND_SIZE/2) cam->X = LAND_SIZE/2; // make sure we don't go
    if (cam->X < -LAND_SIZE/2) cam->X = -LAND_SIZE/2; // too far away
    if (cam->Z > LAND_SIZE/2) cam->Z = LAND_SIZE/2;
    if (cam->Z < -LAND_SIZE/2) cam->Z = -LAND_SIZE/2;
    if (cam->Y < 0) cam->Y = 0;
    if (cam->Y > 8999) cam->Y = 8999;
#if 0

    while (kbhit()) switch(getch()) { // handle keystrokes
        case 27:
            done++;
            break;    // ESC == quit
        // + is for zooming in.
        case '=':
        case '+':
            cam->Fov -= 1.0;
            if (cam->Fov < 1.0) cam->Fov = 1.0;
            sprintf(lastmessage,"FOV: %2.f",cam->Fov);
            break;
        // - is for zooming out
        case '-':
            cam->Fov += 1.0;
            if (cam->Fov > 179.0) cam->Fov = 179.0;
            sprintf(lastmessage,"FOV: %2.f",cam->Fov);
            break;
        // [ decreases mouse sensitivity
        case '[':
            mouse_sens /= 1.1;
            sprintf(lastmessage,"MouseSens: %.3f",mouse_sens);
            break;
        // ] increases mouse sensitivity
        case ']':
            mouse_sens *= 1.1;
            sprintf(lastmessage,"MouseSens: %.3f",mouse_sens);
            break;
        // v toggles vsync
        case 'v':
            wait_vsync ^= 1;
            sprintf(lastmessage,"VSync %s",wait_vsync ? "on" : "off");
            break;
        // s toggles sky
        case 's':
            draw_sky ^= 1;
            sprintf(lastmessage,"Sky %s",draw_sky ? "on" : "off");
            break;
        }
#endif

    //LICE_ScaledBlit(fb,mat[2]->Texture,0,0,fb->getWidth(),fb->getHeight(),0,0,mat[2]->Texture->getWidth(),mat[2]->Texture->getHeight(),1.0f,0);
}
LRESULT CALLBACK DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_INITDIALOG:
		Init(hDlg);
		return TRUE;

	case WM_COMMAND:
		{
			int id = LOWORD(wParam);
			if (id == IDC_BUTTON_START)
			{
				server.Start();
			}
			if (id == ID_NOTITYICONMENU_EXIT)	// 点击退出菜单,退出应用
			{
				Shell_NotifyIcon(NIM_DELETE,&g_nid);
				EndDialog(hDlg, 0);
			}
			break;
		}
	case WM_SYSCOMMAND:
		if (wParam == SC_CLOSE)		// 暂时隐藏程序,不退出
		{
			ShowWindow(g_hMainWnd, SW_HIDE);  
		}
		break;

	case WM_AIRSOUND_NOTIFY:
		if(wParam == IDC_NOTIFYICON)
		{  
			if(lParam == WM_LBUTTONDOWN)
			{  
				ShowWindow(g_hMainWnd, SW_SHOWNORMAL);  
				SetForegroundWindow(g_hMainWnd);
				return TRUE;  
			}
			if (lParam == WM_RBUTTONDOWN)
			{
				HMENU hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_MENU_NOTIFYICON));
				POINT point;
				GetCursorPos(&point);
				TrackPopupMenu(hMenu, 
					TPM_RIGHTBUTTON, 
					point.x,
					point.y,
					0,
					g_hMainWnd,
					NULL);
				PostMessage(g_hMainWnd, WM_NULL, NULL, NULL);
			}
		}  
	case WM_PAINT:
		{
			BOOL bCompEnabled;
			DwmIsCompositionEnabled(&bCompEnabled);
			if (bCompEnabled)
			{
				PAINTSTRUCT ps;
				HDC hDC = BeginPaint(g_hMainWnd, &ps);
				RECT rcClient;
				GetClientRect(g_hMainWnd, &rcClient);
				HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 0));
				FillRect(hDC, &rcClient, hBrush);
				DrawGlowingText(hDC, IDC_STATIC);
				EndPaint(g_hMainWnd, &ps);
			}
		}
		break;
	}
	return FALSE;
}
Exemple #26
0
void
CMainFrame::updateImageInfo()
{
   const CFlyCapDoc* pDoc = (CFlyCapDoc*)GetActiveDocument();
   CView* pView = (CView*)GetActiveView();   
   
   if( m_wndStatusBar &&
      pDoc != NULL && 
      pView != NULL )
   {
      char pszText[ 64 ];
      
      if( m_ImageInfoMode == TIMESTAMP )
      {
         // Setup the timestamp information
         FlyCaptureTimestamp timeStamp = pDoc->m_imageRaw.timeStamp;  
         
#if defined (WIN64)  
         __time64_t  tmpTime = timeStamp.ulSeconds;
         char* pszTemp = ::_ctime64( &tmpTime );
#elif defined (WIN32)
         time_t lTemp = timeStamp.ulSeconds;      
         char* pszTemp = ::ctime( &lTemp );
#else
#error ** No time conversion **
#endif
         if( pszTemp == NULL )
         {
            return;
         }
         int iMilliSec = timeStamp.ulMicroSeconds / 1000;
         sprintf(
            pszText,
            "%.19s.%.03d %s (%03u,%04u)\n",
            pszTemp,
            iMilliSec,
            &pszTemp[ 20 ],
            timeStamp.ulCycleSeconds,
            timeStamp.ulCycleCount );         
      }
      else if( m_ImageInfoMode == CURSOR )
      {
         // Setup the cursor and image information
         CRect rect;
         CPoint pt;
         COLORREF cr;
         int iWidth = 0;
         int iHeight = 0;
         int iSBOffsetX = 0; // the offset of the horizontal scrollbar
         int iSBOffsetY = 0; // the offset of the vertical scrollbar

         // get the position of the scroll bars.
         // used to calculate the co-ordinates of the image.
         iSBOffsetX = pView->GetScrollPos(SB_HORZ);
         iSBOffsetY = pView->GetScrollPos(SB_VERT);
         
         pDoc->getImageSize( &iWidth, &iHeight );
         CDC* pDC = pView->GetDC();
         pDC->GetClipBox( &rect );         
         GetCursorPos( &pt );                  
         pView->ScreenToClient( &pt );
         cr = GetPixel( pDC->GetSafeHdc(), pt.x, pt.y );
         pView->ReleaseDC( pDC );

         // Check that this window is active and 
         // that the cursor is within bounds of the clipping rect
         if( this == GetActiveWindow() &&
            pt.x >= 0 && pt.x < rect.Width() && pt.y >= 0 && pt.y < rect.Height() )
         {
            sprintf( pszText, "Image(%dx%d) Cursor(%d,%d) RGB(%u,%u,%u)", 
               iWidth, 
               iHeight, 
               pt.x + iSBOffsetX,
               pt.y + iSBOffsetY,
               cr & 0xFF, 
               (cr & 0xFF00) >> 8, 
               (cr & 0xFF0000) >> 16 );
         }
static LRESULT CALLBACK EventArea_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg) {
	case WM_MEASUREITEM:
		{
			MEASUREITEMSTRUCT *lpi = (LPMEASUREITEMSTRUCT) lParam;
			MENUITEMINFOA mii = {0};

			mii.cbSize = sizeof(mii);
			mii.fMask = MIIM_DATA | MIIM_ID;
			if (GetMenuItemInfoA(g_CluiData.hMenuNotify, lpi->itemID, FALSE, &mii) != 0) {
				if (mii.dwItemData == lpi->itemData) {
					lpi->itemWidth = 8 + 16;
					lpi->itemHeight = 0;
					return TRUE;
				}
			}
		}
		break;

	case WM_DRAWITEM:
		{
			LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT) lParam;
			if (dis->hwndItem == (HWND) g_CluiData.hMenuNotify) {
				NotifyMenuItemExData *nmi = 0;

				MENUITEMINFOA mii = {0};
				mii.cbSize = sizeof(mii);
				mii.fMask = MIIM_DATA;
				if (GetMenuItemInfoA(g_CluiData.hMenuNotify, (UINT) dis->itemID, FALSE, &mii) != 0) {
					nmi = (NotifyMenuItemExData *) mii.dwItemData;
					if (nmi) {
						int iIcon = cli_GetContactIcon(nmi->hContact);
						ske_ImageList_DrawEx(g_himlCListClc, nmi->iIcon, dis->hDC, 2, (dis->rcItem.bottom + dis->rcItem.top - GetSystemMetrics(SM_CYSMICON)) / 2, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), CLR_NONE, CLR_NONE, ILD_NORMAL);
						ske_ImageList_DrawEx(g_himlCListClc, iIcon, dis->hDC, 2+GetSystemMetrics(SM_CXSMICON)+2, (dis->rcItem.bottom + dis->rcItem.top - GetSystemMetrics(SM_CYSMICON)) / 2, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), CLR_NONE, CLR_NONE, ILD_NORMAL);
						return TRUE;
					}
				}
			}
			break;
		}
	case WM_LBUTTONUP:
		if (g_CluiData.bEventAreaEnabled)
			SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDC_NOTIFYBUTTON, 0), 0);
		break;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDC_NOTIFYBUTTON) {
			int iSelection;
			MENUITEMINFO mii = {0};
			POINT pt;
			struct NotifyMenuItemExData *nmi = 0;
			int iCount = GetMenuItemCount(g_CluiData.hMenuNotify);
			BOOL result;

			GetCursorPos(&pt);
			mii.cbSize = sizeof(mii);
			mii.fMask = MIIM_DATA;
			if (iCount > 1)
				iSelection = TrackPopupMenu(g_CluiData.hMenuNotify, TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, NULL);
			else
				iSelection = GetMenuItemID(g_CluiData.hMenuNotify, 0);
			result = GetMenuItemInfo(g_CluiData.hMenuNotify, (UINT) iSelection, FALSE, &mii);
			if (result != 0) {
				nmi = (struct NotifyMenuItemExData *) mii.dwItemData;
				if (nmi) {
					CLISTEVENT *cle = MyGetEvent(iSelection);
					if (cle) {
						CLISTEVENT *cle1 = NULL;
						CallService(cle->pszService, (WPARAM) NULL, (LPARAM) cle);
						// re-obtain the pointer, it may already be invalid/point to another event if the
						// event we're interested in was removed by the service (nasty one...)
						cle1 = MyGetEvent(iSelection);
						if (cle1 != NULL)
							CallService(MS_CLIST_REMOVEEVENT, (WPARAM) cle->hContact, (LPARAM) cle->hDbEvent);
					}
				}
			}
			break;
		}
		break;

	case WM_SIZE:
		if (!g_CluiData.fLayered)
			InvalidateRect(hwnd,NULL,FALSE);
		return DefWindowProc(hwnd, msg, wParam, lParam);

	case WM_ERASEBKGND:
		return 1;

	case WM_PAINT:
		if (GetParent(hwnd) == pcli->hwndContactList && g_CluiData.fLayered)
			CallService(MS_SKINENG_INVALIDATEFRAMEIMAGE,(WPARAM)hwnd,0);
		else if (GetParent(hwnd) == pcli->hwndContactList && !g_CluiData.fLayered) {
			HDC hdc, hdc2;
			HBITMAP hbmp,hbmpo;
			RECT rc = {0};
			GetClientRect(hwnd,&rc);
			rc.right++;
			rc.bottom++;
			hdc = GetDC(hwnd);
			hdc2 = CreateCompatibleDC(hdc);
			hbmp = ske_CreateDIB32(rc.right,rc.bottom);
			hbmpo = (HBITMAP)SelectObject(hdc2,hbmp);
			ske_BltBackImage(hwnd,hdc2,&rc);
			EventArea_DrawWorker(hwnd,hdc2);
			BitBlt(hdc,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,
				hdc2,rc.left,rc.top,SRCCOPY);
			SelectObject(hdc2,hbmpo);
			DeleteObject(hbmp);
			DeleteDC(hdc2);
			SelectObject(hdc,GetStockObject(DEFAULT_GUI_FONT));
			ReleaseDC(hwnd,hdc);
			ValidateRect(hwnd,NULL);
		}
		else {
			HDC hdc, hdc2;
			HBITMAP hbmp, hbmpo;
			RECT rc;
			PAINTSTRUCT ps;
			HBRUSH br = GetSysColorBrush(COLOR_3DFACE);
			GetClientRect(hwnd,&rc);
			hdc = BeginPaint(hwnd,&ps);
			hdc2 = CreateCompatibleDC(hdc);
			hbmp = ske_CreateDIB32(rc.right,rc.bottom);
			hbmpo = (HBITMAP)SelectObject(hdc2,hbmp);
			FillRect(hdc2,&ps.rcPaint,br);
			EventArea_DrawWorker(hwnd,hdc2);
			BitBlt(hdc,ps.rcPaint.left,ps.rcPaint.top,ps.rcPaint.right-ps.rcPaint.left,ps.rcPaint.bottom-ps.rcPaint.top,
				hdc2,ps.rcPaint.left,ps.rcPaint.top,SRCCOPY);
			SelectObject(hdc2,hbmpo);
			DeleteObject(hbmp);
			DeleteDC(hdc2);
			ps.fErase = FALSE;
			EndPaint(hwnd,&ps);
		}

	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return TRUE;
}
Exemple #28
0
static void handle_mouse(const int numevents, DIDEVICEOBJECTDATA *ptrbuf)
{
	int i;
	Sint16 xrel, yrel;
	Uint8 state;
	Uint8 button;
	DWORD timestamp = 0;

	/* Sanity check. Mailing list reports this being NULL unexpectedly. */
	if (SDL_PublicSurface == NULL) {
		return;
	}

	/* If the mouse was lost, regain some sense of mouse state */
	if ( mouse_lost && (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
		POINT mouse_pos;
		Uint8 old_state;
		Uint8 new_state;

		/* Set ourselves up with the current cursor position */
		GetCursorPos(&mouse_pos);
		ScreenToClient(SDL_Window, &mouse_pos);
		post_mouse_motion( 0, (Sint16)mouse_pos.x, (Sint16)mouse_pos.y);

		/* Check for mouse button changes */
		old_state = SDL_GetMouseState(NULL, NULL);
		new_state = 0;
		{ /* Get the new DirectInput button state for the mouse */
#if DIRECTINPUT_VERSION >= 0x700
			DIMOUSESTATE2 distate;
#else
			DIMOUSESTATE distate;
#endif
			HRESULT result;

			result=IDirectInputDevice2_GetDeviceState(SDL_DIdev[1],
						sizeof(distate), &distate);
			if ( result != DI_OK ) {
				/* Try again next time */
				SetDIerror(
				"IDirectInputDevice2::GetDeviceState", result);
				return;
			}
			for ( i=3; i>=0; --i ) {
				if ( (distate.rgbButtons[i]&0x80) == 0x80 ) {
					new_state |= 0x01;
				}
				new_state <<= 1;
			}
		}
		for ( i=0; i<8; ++i ) {
			if ( (old_state&0x01) != (new_state&0x01) ) {
				button = (Uint8)(i+1);
				/* Map DI button numbers to SDL */
				switch ( button ) {
					case 2: button = SDL_BUTTON_RIGHT; break;
					case 3: button = SDL_BUTTON_MIDDLE; break;
					case 4: button = SDL_BUTTON_X1; break;
					case 5: button = SDL_BUTTON_X2; break;
					default: break;
				}
				if ( new_state & 0x01 ) {
					/* Grab mouse so we get mouse-up */
					if ( ++mouse_pressed > 0 ) {
						SetCapture(SDL_Window);
					}
					state = SDL_PRESSED;
				} else {
					/* Release mouse after all mouse-ups */
					if ( --mouse_pressed <= 0 ) {
						ReleaseCapture();
						mouse_pressed = 0;
					}
					state = SDL_RELEASED;
				}
				if ( mouse_buttons_swapped ) {
					if ( button == 1 ) button = 3;
					else
					if ( button == 3 ) button = 1;
				}
				posted = SDL_PrivateMouseButton(state, button,
									0, 0);
			}
			old_state >>= 1;
			new_state >>= 1;
		}
		mouse_lost = 0;
		return;
	}
void AppClass::ProcessMouse(void)
{
	m_bArcBall = false;
	m_bFPC = false;
	float fSpeed = 0.01f;
#pragma region ON_MOUSE_PRESS_RELEASE
	static bool	bLastLeft = false, bLastMiddle = false, bLastRight = false;
#define ON_MOUSE_PRESS_RELEASE(key, pressed_action, released_action){  \
			bool pressed = sf::Mouse::isButtonPressed(sf::Mouse::Button::key);			\
			if(pressed){											\
				if(!bLast##key) pressed_action;}/*Just pressed? */\
			else if(bLast##key) released_action;/*Just released?*/\
			bLast##key = pressed; } //remember the state
#pragma endregion
	bool bLeft = false;
	ON_MOUSE_PRESS_RELEASE(Left, NULL, bLeft = true)
	if (bLeft)
	{
		//Turn off the visibility of all BOs for all instances
		m_pMeshMngr->SetVisibleBO(BD_NONE, "ALL", -1);
		//Get the Position and direction of the click on the screen
		std::pair<vector3, vector3> pair =
			m_pCameraMngr->GetClickAndDirectionOnWorldSpace(sf::Mouse::getPosition().x, sf::Mouse::getPosition().y);
		float fDistance = 0;//Stores the distance to the first colliding object
		m_selection = m_pMeshMngr->IsColliding(pair.first, pair.second, fDistance);

		//If there is a collision
		if (m_selection.first >= 0)
		{
			//Turn on the BO of the group
			m_pMeshMngr->SetVisibleBO(BD_OB, m_selection.first, m_selection.second);

			//Turn of the BO of the instance but not the group
			m_pMeshMngr->SetVisibleBO(BD_NONE, m_selection.first, -2);
		}
	}
	
	if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Middle))
		m_bArcBall = true;
	
	if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Right))
		m_bFPC = true;

	if (m_bFPC) {
		//the following code is taken from ReEngAppClass.h CameraRotation ln 351
		UINT	MouseX, MouseY;		// Coordinates for the mouse
		UINT	CenterX, CenterY;	// Coordinates for the center of the screen.

									//Initialize the position of the pointer to the middle of the screen
		CenterX = m_pSystem->GetWindowX() + m_pSystem->GetWindowWidth() / 2;
		CenterY = m_pSystem->GetWindowY() + m_pSystem->GetWindowHeight() / 2;

		//Calculate the position of the mouse and store it
		POINT pt;
		GetCursorPos(&pt);
		MouseX = pt.x;
		MouseY = pt.y;

		//Calculate the difference in view with the angle
		float fAngleX = 0.0f;
		float fAngleY = 0.0f;
		float fDeltaMouse = 0.0f;
		if (MouseX < CenterX)
		{
			fDeltaMouse = static_cast<float>(CenterX - MouseX);
			fAngleY += fDeltaMouse * fSpeed;
		}
		else if (MouseX > CenterX)
		{
			fDeltaMouse = static_cast<float>(MouseX - CenterX);
			fAngleY -= fDeltaMouse * fSpeed;
		}

		if (MouseY < CenterY)
		{
			fDeltaMouse = static_cast<float>(CenterY - MouseY);
			fAngleX -= fDeltaMouse * fSpeed;
		}
		else if (MouseY > CenterY)
		{
			fDeltaMouse = static_cast<float>(MouseY - CenterY);
			fAngleX += fDeltaMouse * fSpeed;
		}
		//Change the Yaw and the Pitch of the camera
		myCam->ChangeYaw(-fAngleY * 3.0f);
		myCam->ChangePitch(fAngleX * 3.0f);
		SetCursorPos(CenterX, CenterY);//Position the mouse in the center
	}
}
Exemple #30
0
void MUS_RenewMouse( HWND hwnd, int active, int Flag_MenuSelected )
{
	int				i;
	int				x,y;
	int				mx,my;
	MOUSE_CHECK		*mc;
	POINT			mp;
	static int		bl=OFF,bm=OFF,br=OFF;
	static int		lcnt=0, mcnt=0, rcnt=0;
	int				rect_err;



	GetCursorPos( &mp );
	ScreenToClient( hwnd, &mp );
	MouseStruct.mx = mx = mp.x;
	MouseStruct.my = my = mp.y;
	x = mx-400;
	y = my-300;
	MouseStruct.interval = x*x + y*y;
	MouseStruct.active = active;

	rect_err = !(0 < mx && 0 < my && MouseStruct.disp_w >= mx && MouseStruct.disp_h >= my);

	MouseStruct.no = -1;
	if( !rect_err ){
		for(i=0; i<MOUSE_REST_MAX ;i++){
			mc = &MouseCheck[MouseStruct.lno][i];
			if( mc->flag ){
				if( mc->sx      <= mx && mc->sy      <= my &&
					mc->sx+mc->w > mx && mc->sy+mc->h > my ){
					MouseStruct.no = i;
					break;
				}
			}
		}
	}
	
	MouseStruct.wheel = MouseStruct.wheel_get;
	if( MouseStruct.wheel_get ){
		MouseStruct.wheel_get = 0;
	}

	
	if( !MouseStruct.click_through && active ){
		if(MouseStruct.same_time){
			if( !(MouseStruct.bl || MouseStruct.br || MouseStruct.bm) ){	
				MouseStruct.bl = (GetAsyncKeyState(VK_LBUTTON)&0x8001)?ON:OFF;
				if( !MouseStruct.bl ){
					MouseStruct.br = (GetAsyncKeyState(VK_RBUTTON)&0x8001)?ON:OFF;
					if( !MouseStruct.br ){
						MouseStruct.bm = (GetAsyncKeyState(VK_MBUTTON)&0x8001)?ON:OFF;
					}
				}
			}else{	
				if(MouseStruct.bl)	MouseStruct.bl = (GetAsyncKeyState(VK_LBUTTON)&0x8001)?ON:OFF;
				else				GetAsyncKeyState(VK_LBUTTON);
				if(MouseStruct.br)	MouseStruct.br = (GetAsyncKeyState(VK_RBUTTON)&0x8001)?ON:OFF;
				else				GetAsyncKeyState(VK_RBUTTON);
				if(MouseStruct.bm)	MouseStruct.bm = (GetAsyncKeyState(VK_MBUTTON)&0x8001)?ON:OFF;
				else				GetAsyncKeyState(VK_MBUTTON);

				if( !(MouseStruct.bl || MouseStruct.br || MouseStruct.bm) ){	
					MouseStruct.bl = (GetAsyncKeyState(VK_LBUTTON)&0x8001)?ON:OFF;
					if( !MouseStruct.bl ){
						MouseStruct.br = (GetAsyncKeyState(VK_RBUTTON)&0x8001)?ON:OFF;
						if( !MouseStruct.br ){
							MouseStruct.bm = (GetAsyncKeyState(VK_MBUTTON)&0x8001)?ON:OFF;
						}
					}
				}
			}
		}else{
			MouseStruct.bl = (GetAsyncKeyState(VK_LBUTTON)&0x8001)?ON:OFF;
			MouseStruct.br = (GetAsyncKeyState(VK_RBUTTON)&0x8001)?ON:OFF;
			MouseStruct.bm = (GetAsyncKeyState(VK_MBUTTON)&0x8001)?ON:OFF;
		}
		if(Flag_MenuSelected>0){
			Flag_MenuSelected--;
			MouseStruct.bl = OFF;
			MouseStruct.br = OFF;
			MouseStruct.bm = OFF;
		}
	}else{
		MouseStruct.click_through = 0;
		GetAsyncKeyState(VK_LBUTTON);
		GetAsyncKeyState(VK_RBUTTON);
		GetAsyncKeyState(VK_MBUTTON);
	}

	if( GetSystemMetrics(SM_SWAPBUTTON) ){
		int	work = MouseStruct.bl;
		MouseStruct.bl = MouseStruct.br;
		MouseStruct.br = work;
	}

	lcnt = (MouseStruct.bl) ? min(8,lcnt+1) : 0;
	rcnt = (MouseStruct.br) ? min(8,rcnt+1) : 0;
	mcnt = (MouseStruct.bm) ? min(8,mcnt+1) : 0;
	MouseStruct.btl = (lcnt==8) || (lcnt==1);
	MouseStruct.btr = (rcnt==8) || (rcnt==1);
	MouseStruct.btm = (mcnt==8) || (mcnt==1);
	
	if(bl==OFF && MouseStruct.bl==ON ){
		MouseStruct.tl = ON;
		MouseStruct.dragl.x = mx;
		MouseStruct.dragl.y = my;
	}else{
		MouseStruct.tl = OFF;
	}
	if(br==OFF && MouseStruct.br==ON ){
		MouseStruct.tr = ON;
		MouseStruct.dragr.x = mx;
		MouseStruct.dragr.y = my;
	}else{
		MouseStruct.tr = OFF;
	}
	if(bm==OFF && MouseStruct.bm==ON ){
		MouseStruct.tm = ON;
		MouseStruct.dragm.x = mx;
		MouseStruct.dragm.y = my;
	}else{
		MouseStruct.tm = OFF;
	}
	
	if( bl==ON && MouseStruct.bl==OFF )	{	MouseStruct.rtl = ON;	}
	else								{	MouseStruct.rtl = OFF;	}
	if( br==ON && MouseStruct.br==OFF )	{	MouseStruct.rtr = ON;	}
	else								{	MouseStruct.rtr = OFF;	}
	if( bm==ON && MouseStruct.bm==OFF )	{	MouseStruct.rtm = ON;	}
	else								{	MouseStruct.rtm = OFF;	}
	
	if( !MouseStruct.bl ) {	MouseStruct.dragl.x = -1;	MouseStruct.dragl.y = -1;	}
	if( !MouseStruct.br ) {	MouseStruct.dragr.x = -1;	MouseStruct.dragr.y = -1;	}
	if( !MouseStruct.bm ) {	MouseStruct.dragm.x = -1;	MouseStruct.dragm.y = -1;	}
	
	bl = MouseStruct.bl;
	br = MouseStruct.br;
	bm = MouseStruct.bm;
}