コード例 #1
0
void AnimateToTray(HWND hWnd)
{
	HWND hCaptionWindow;
	RECT rcFrom, rcTo;
	TCHAR windowText[512];
	WNDCLASSEX wcex;
	HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
	int xInc, yInc, captionWidth;

	if(GetDoAnimateMinimize())
	{
		// Get the rect of the tray and the window. Note that the window rect
		// is still valid even though the window is hidden
    
		GetTrayWndRect(&rcTo);
		
		GetWindowRect(hWnd,&rcFrom);
		GetWindowText(hWnd, windowText, sizeof(windowText));

		wcex.cbSize			= sizeof(WNDCLASSEX);
		wcex.style			= CS_HREDRAW | CS_VREDRAW;
		wcex.lpfnWndProc	= CaptionWndProc;
		wcex.cbClsExtra		= 0;
		wcex.cbWndExtra		= 0;
		wcex.hInstance		= hInstance;
		wcex.hIcon			= (HICON)SendMessage(hWnd, WM_GETICON, ICON_BIG, 0);
		wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
		wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW);
		wcex.lpszMenuName	= NULL;
		wcex.lpszClassName	= L"Caption Window";
		wcex.hIconSm		= (HICON)SendMessage(hWnd, WM_GETICON, ICON_SMALL, 0);
		
		if(!RegisterClassEx(&wcex))
			return;

		hCaptionWindow = CreateWindow(L"Caption Window", windowText, WS_VISIBLE | WS_POPUPWINDOW | WS_CAPTION, rcFrom.left,
			rcFrom.top, 0, 0, NULL, NULL, hInstance, NULL);
		
		captionWidth = GetSystemMetrics(SM_CYCAPTION) + 3;

		SetWindowPos(hCaptionWindow, NULL, 0, 0, 220, captionWidth, SWP_NOMOVE | SWP_NOZORDER);
		
		xInc = (rcTo.left - rcFrom.left) / ANIMATE_TRAY_NUMFRAMES;
		yInc = (rcTo.top + captionWidth - rcFrom.top) / ANIMATE_TRAY_NUMFRAMES; 

		for(int i = 0; i < ANIMATE_TRAY_NUMFRAMES; i++)
		{
			Sleep(ANIMATE_TRAY_FRAMERATE);
			SetWindowPos(hCaptionWindow, NULL, rcFrom.left+=xInc, rcFrom.top+=yInc, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
		}

		DestroyWindow(hCaptionWindow);
		UnregisterClass(L"Caption Window", hInstance);
	}
}
コード例 #2
0
void MinimizeWndToTray(HWND hWnd)
{
  if(!IsWindowVisible(hWnd)) 
    return;
  if(GetDoAnimateMinimize())
  {
    RECT rcFrom,rcTo;

    GetWindowRect(hWnd,&rcFrom);
    GetTrayWndRect(&rcTo);

    DrawAnimatedRects(hWnd,IDANI_CAPTION,&rcFrom,&rcTo);
  }

  ShowWindow(hWnd,SW_HIDE);
}
コード例 #3
0
void RestoreWndFromTray(HWND hWnd)
{
  if(IsWindowVisible(hWnd)) 
    return;
  if(GetDoAnimateMinimize())
  {
    RECT rcFrom,rcTo;
    GetTrayWndRect(&rcFrom);
    GetWindowRect(hWnd,&rcTo);

    DrawAnimatedRects(hWnd,IDANI_CAPTION,&rcFrom,&rcTo);
  }

  ShowWindow(hWnd,SW_SHOW);
  SetActiveWindow(hWnd);
  SetForegroundWindow(hWnd);
}