Source

owl-components / SCDlg.cpp

Full commit
/* Self Centering dialog */

#include <OWL\Dialog.H>
#pragma hdrstop

#include "OwlStuff\SCDlg.H"
/*-------------------------------------------------------------------------*/
TSelfCenteringDialog::TSelfCenteringDialog(TWindow* parent, TResId resource, TModule* module)
:
	TDialog(parent, resource, module)
{
	/* merly a placeholder */
}
/*-------------------------------------------------------------------------*/
void TSelfCenteringDialog::SetupWindow()
{
	TDialog::SetupWindow(); // Pass to top of chain to initialze the visual element
}
/*-------------------------------------------------------------------------*/
void TSelfCenteringDialog::MoveToWindowCentre(const HWND ClientWindow)
{
	/* locals */
	RECT clientRect; // Rectangle of client window
   TRect ourRect; // Rectangle of our window
   int clientRectWidth, clientRectHeight, ourRectHeight, ourRectWidth;

   GetHWndState(); // Ensure members are up-to-date
   GetWindowRect(ourRect);
   ::GetWindowRect(ClientWindow, &clientRect);

   clientRectWidth = clientRect.right - clientRect.left;
   clientRectHeight = clientRect.bottom - clientRect.top;
   ourRectWidth = ourRect.right - ourRect.left;
   ourRectHeight = ourRect.bottom - ourRect.top;

   ourRect.left = clientRect.left + ((clientRectWidth /2) - (ourRectWidth /2));
   ourRect.top = clientRect.top + ((clientRectHeight /2) - (ourRectHeight /2));
   ourRect.bottom = ourRect.top + ourRectHeight;
   ourRect.right = ourRect.left + ourRectWidth;

   /* send MoveWindow() our modified rectangle */
   MoveWindow(ourRect, true);
}
/*-------------------------------------------------------------------------*/
void TSelfCenteringDialog::MoveToScreenCentre()
{
	HWND screen = GetDesktopWindow(); // Get handle for entrie screen
   int oldwidth, oldheight, newx, newy;
   TRect rectangle; // Borland class library compatible rectangle
   RECT screenrect; // Win API type rectangle

   GetHWndState(); // Ensure members are up-to-date
   GetWindowRect(rectangle); // Get window coordinates
   ::GetWindowRect(screen, &screenrect); // Get screen coords.  Must use scope override to access Windows version not function of class defined by Borland

   // Do conversions
   oldwidth = rectangle.right - rectangle.left;
   oldheight = rectangle.bottom - rectangle.top;

   // Do calculations for centre
   newx = (screenrect.right /2) - (oldwidth /2);
   newy = (screenrect.bottom /2) - (oldheight /2);

   MoveWindow(newx, newy, oldwidth, oldheight, true); // Move to these coordinates (see, I just changed the x,y not the height and width) */
}
/*-------------------------------------------------------------------------*/