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.

92 lines
2.7 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1997 Active Voice Corporation. All Rights Reserved.
  4. //
  5. // Active Agent(r) and Unified Communications(tm) are trademarks of Active Voice Corporation.
  6. //
  7. // Other brand and product names used herein are trademarks of their respective owners.
  8. //
  9. // The entire program and user interface including the structure, sequence, selection,
  10. // and arrangement of the dialog, the exclusively "yes" and "no" choices represented
  11. // by "1" and "2," and each dialog message are protected by copyrights registered in
  12. // the United States and by international treaties.
  13. //
  14. // Protected by one or more of the following United States patents: 5,070,526, 5,488,650,
  15. // 5,434,906, 5,581,604, 5,533,102, 5,568,540, 5,625,676, 5,651,054.
  16. //
  17. // Active Voice Corporation
  18. // Seattle, Washington
  19. // USA
  20. //
  21. /////////////////////////////////////////////////////////////////////////////////////////
  22. ////
  23. // wnd.c - window functions
  24. ////
  25. #include "winlocal.h"
  26. // WndCenterWindow - center one window on top of another
  27. // <hwnd1> (i) window to be centered
  28. // <hwnd2> (i) window to be centered upon
  29. // NULL center on parent or owner
  30. // <xOffCenter> (i) offset from horizontal center
  31. // 0 center window exactly
  32. // <yOffCenter> (i) offset from vertical center
  33. // 0 center window exactly
  34. // return 0 if success
  35. //
  36. int DLLEXPORT WINAPI WndCenterWindow(HWND hwnd1, HWND hwnd2, int xOffCenter, int yOffCenter)
  37. {
  38. POINT pt;
  39. RECT rc1;
  40. RECT rc2;
  41. int nWidth;
  42. int nHeight;
  43. if ( hwnd1 )
  44. {
  45. // use parent or owner window if no other specified
  46. //
  47. if (hwnd2 == NULL)
  48. hwnd2 = GetParent(hwnd1);
  49. // use desktop window if no parent or owner
  50. // or if parent or owner is iconic or invisible
  51. //
  52. if (hwnd2 == NULL || IsIconic(hwnd2) || !IsWindowVisible(hwnd2))
  53. hwnd2 = GetDesktopWindow();
  54. // get the rectangles for both windows
  55. //
  56. GetWindowRect(hwnd1, &rc1);
  57. GetClientRect(hwnd2, &rc2);
  58. // calculate the height and width for MoveWindow
  59. //
  60. nWidth = rc1.right - rc1.left;
  61. nHeight = rc1.bottom - rc1.top;
  62. // find the center point and convert to screen coordinates
  63. //
  64. pt.x = (rc2.right - rc2.left) / 2;
  65. pt.y = (rc2.bottom - rc2.top) / 2;
  66. ClientToScreen(hwnd2, &pt);
  67. // calculate the new x, y starting point
  68. //
  69. pt.x -= (nWidth / 2);
  70. pt.y -= (nHeight / 2);
  71. // adjust the window position off center, if necessary
  72. //
  73. pt.x = max(0, pt.x + xOffCenter);
  74. pt.y = max(0, pt.y + yOffCenter);
  75. // center the window
  76. //
  77. MoveWindow( hwnd1, pt.x, pt.y, nWidth, nHeight, FALSE );
  78. }
  79. return 0;
  80. }