center.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /****************************************************************************
  2. *
  3. * Display Doctor Windows Interface Code
  4. *
  5. * ======================================================================
  6. * |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
  7. * | |
  8. * |This copyrighted computer code is a proprietary trade secret of |
  9. * |SciTech Software, Inc., located at 505 Wall Street, Chico, CA 95928 |
  10. * |USA (www.scitechsoft.com). ANY UNAUTHORIZED POSSESSION, USE, |
  11. * |VIEWING, COPYING, MODIFICATION OR DISSEMINATION OF THIS CODE IS |
  12. * |STRICTLY PROHIBITED BY LAW. Unless you have current, express |
  13. * |written authorization from SciTech to possess or use this code, you |
  14. * |may be subject to civil and/or criminal penalties. |
  15. * | |
  16. * |If you received this code in error or you would like to report |
  17. * |improper use, please immediately contact SciTech Software, Inc. at |
  18. * |530-894-8400. |
  19. * | |
  20. * |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
  21. * ======================================================================
  22. *
  23. * Language: C++ 3.0
  24. * Environment: Win16
  25. *
  26. * Description: Dialog driven configuration program for UniVBE and
  27. * WinDirect Professional products.
  28. *
  29. ****************************************************************************/
  30. #include "center.h"
  31. /*------------------------------ Implementation ---------------------------*/
  32. void _EXPORT CenterWindow(HWND hWndCenter, HWND parent, BOOL repaint)
  33. /****************************************************************************
  34. *
  35. * Function: CenterWindow
  36. * Parameters: hWndCenter - Window to center
  37. * parent - Handle for parent window
  38. * repaint - true if window should be re-painted
  39. *
  40. * Description: Centers the specified window within the bounds of the
  41. * specified parent window. If the parent window is NULL, then
  42. * we center it using the Desktop window.
  43. *
  44. ****************************************************************************/
  45. {
  46. HWND hWndParent = (parent ? parent : GetDesktopWindow());
  47. RECT RectParent;
  48. RECT RectCenter;
  49. int CenterX,CenterY,Height,Width;
  50. GetWindowRect(hWndParent, &RectParent);
  51. GetWindowRect(hWndCenter, &RectCenter);
  52. Width = (RectCenter.right - RectCenter.left);
  53. Height = (RectCenter.bottom - RectCenter.top);
  54. CenterX = ((RectParent.right - RectParent.left) - Width) / 2;
  55. CenterY = ((RectParent.bottom - RectParent.top) - Height) / 2;
  56. if ((CenterX < 0) || (CenterY < 0)) {
  57. /* The Center Window is smaller than the parent window. */
  58. if (hWndParent != GetDesktopWindow()) {
  59. /* If the parent window is not the desktop use the desktop size. */
  60. CenterX = (GetSystemMetrics(SM_CXSCREEN) - Width) / 2;
  61. CenterY = (GetSystemMetrics(SM_CYSCREEN) - Height) / 2;
  62. }
  63. CenterX = (CenterX < 0) ? 0: CenterX;
  64. CenterY = (CenterY < 0) ? 0: CenterY;
  65. }
  66. else {
  67. CenterX += RectParent.left;
  68. CenterY += RectParent.top;
  69. }
  70. /* Copy the values into RectCenter */
  71. RectCenter.left = CenterX;
  72. RectCenter.right = CenterX + Width;
  73. RectCenter.top = CenterY;
  74. RectCenter.bottom = CenterY + Height;
  75. /* Move the window to the new location */
  76. MoveWindow(hWndCenter, RectCenter.left, RectCenter.top,
  77. (RectCenter.right - RectCenter.left),
  78. (RectCenter.bottom - RectCenter.top), repaint);
  79. }
  80. void _EXPORT CenterLogo(HWND hWndLogo, HWND hWndParent, int CenterY)
  81. /****************************************************************************
  82. *
  83. * Function: CenterLogo
  84. * Parameters: hWndLogo - Window to center
  85. * hWndParent - Handle for parent window
  86. * CenterY - Top coordinate for logo
  87. *
  88. * Description: Centers the specified window within the bounds of the
  89. * specified parent window in the horizontal direction only.
  90. *
  91. ****************************************************************************/
  92. {
  93. RECT RectParent;
  94. RECT RectCenter;
  95. int CenterX,Height,Width;
  96. GetWindowRect(hWndParent, &RectParent);
  97. GetWindowRect(hWndLogo, &RectCenter);
  98. Width = (RectCenter.right - RectCenter.left);
  99. Height = (RectCenter.bottom - RectCenter.top);
  100. CenterX = ((RectParent.right - RectParent.left) - Width) / 2;
  101. /* Copy the values into RectCenter */
  102. RectCenter.left = CenterX;
  103. RectCenter.right = CenterX + Width;
  104. RectCenter.top = CenterY;
  105. RectCenter.bottom = CenterY + Height;
  106. /* Move the window to the new location */
  107. MoveWindow(hWndLogo, RectCenter.left, RectCenter.top,
  108. (RectCenter.right - RectCenter.left),
  109. (RectCenter.bottom - RectCenter.top), false);
  110. }