Commits

Anonymous committed 0a5ec94

The Borland OWL library: Additional Daybo Logic components.

Comments (0)

Files changed (2)

+#ifndef __INC_OWLSTUFF_SCDLG_H
+#define __INC_OWLSTUFF_SCDLG_H
+/*-------------------------------------------------------------------------*/
+#ifndef __cplusplus
+#	error Self Centering Dialog requires C++
+#endif
+
+class TSelfCenteringDialog : public TDialog
+{
+public:
+	TSelfCenteringDialog(TWindow* parent=0, TResId resource=0, TModule* module=0); // Constructor
+   void MoveToWindowCentre(const HWND ClientWindow); // Moves to centre of the client window
+   void MoveToScreenCentre(); // Moves to the screen centre
+protected:
+	virtual void SetupWindow();
+private:
+};
+/*-------------------------------------------------------------------------*/
+#endif /*__INC_OWLSTUFF_SCDLG_H*/
+/* 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) */
+}
+/*-------------------------------------------------------------------------*/