Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.7 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: winutil.cpp
  6. * Content: Windows GUI utility functions
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 09/21/99 pnewson Created
  12. ***************************************************************************/
  13. #include "dxvutilspch.h"
  14. #undef DPF_SUBCOMP
  15. #define DPF_SUBCOMP DN_SUBCOMP_VOICE
  16. #undef DPF_MODNAME
  17. #define DPF_MODNAME "CenterWindowOnWorkspace"
  18. HRESULT CenterWindowOnWorkspace(HWND hWnd)
  19. {
  20. DPF_ENTER();
  21. // Center the dialog on the desktop
  22. RECT rtWnd;
  23. RECT rtWorkArea;
  24. // First get the current dimensions of the dialog
  25. if (!GetWindowRect(hWnd, &rtWnd))
  26. {
  27. // Get window rect failed. Log it to the debugger, don't move
  28. // the window.
  29. DPFX(DPFPREP, DVF_ERRORLEVEL, "GetWindowRect() failed, code: %i", GetLastError());
  30. DPF_EXIT();
  31. return E_FAIL;
  32. }
  33. // Now get the dimensions of the work area
  34. if (!SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rtWorkArea, 0))
  35. {
  36. // Weird.
  37. DPFX(DPFPREP, DVF_ERRORLEVEL, "SystemParametersInfo() failed, code: %i", GetLastError());
  38. DPF_EXIT();
  39. return E_FAIL;
  40. }
  41. if (!MoveWindow(
  42. hWnd,
  43. rtWorkArea.left + (rtWorkArea.right - rtWorkArea.left)/2 - (rtWnd.right - rtWnd.left)/2,
  44. rtWorkArea.top + (rtWorkArea.bottom - rtWorkArea.top)/2 - (rtWnd.bottom - rtWnd.top)/2,
  45. rtWnd.right - rtWnd.left,
  46. rtWnd.bottom - rtWnd.top,
  47. FALSE))
  48. {
  49. // Move window failed. Log it to the debugger.
  50. DPFX(DPFPREP, DVF_ERRORLEVEL, "MoveWindow() failed, code: %i", GetLastError());
  51. DPF_EXIT();
  52. return E_FAIL;
  53. }
  54. DPF_EXIT();
  55. return S_OK;
  56. }