Subversion Repositories filter_foundry

Rev

Rev 259 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
259 daniel-mar 1
/* Copyright 1996 - 2000 Adobe Systems Incorporated                */
2
/* All Rights Reserved.                                            */
3
 
4
#include <windows.h>
5
 
6
// from PS 6 SDK - WinUtilities.cpp
7
 
8
/* Centers a dialog template 1/3 of the way down on the main screen */
9
 
10
void CenterDialog(HWND hDlg)
11
{
12
        int  nHeight;
268 daniel-mar 13
        int  nWidth;
14
        int  nTitleBits;
15
        RECT rcDialog;
16
        RECT rcParent;
17
        int  xOrigin;
18
        int  yOrigin;
19
        int  xScreen;
20
        int  yScreen;
21
        HWND hParent = GetParent(hDlg);
259 daniel-mar 22
 
268 daniel-mar 23
        if  (hParent == NULL)
24
                hParent = GetDesktopWindow();
259 daniel-mar 25
 
268 daniel-mar 26
        GetClientRect(hParent, &rcParent);
27
        ClientToScreen(hParent, (LPPOINT)&rcParent.left);  // point(left,  top)
28
        ClientToScreen(hParent, (LPPOINT)&rcParent.right); // point(right, bottom)
259 daniel-mar 29
 
268 daniel-mar 30
        // Center on Title: title bar has system menu, minimize,  maximize bitmaps
31
        // Width of title bar bitmaps - assumes 3 of them and dialog has a sysmenu
32
        nTitleBits = GetSystemMetrics(SM_CXSIZE);
259 daniel-mar 33
 
268 daniel-mar 34
        // If dialog has no sys menu compensate for odd# bitmaps by sub 1 bitwidth
35
        if  ( ! (GetWindowLong(hDlg, GWL_STYLE) & WS_SYSMENU))
36
                nTitleBits -= nTitleBits / 3;
259 daniel-mar 37
 
268 daniel-mar 38
        GetWindowRect(hDlg, &rcDialog);
39
        nWidth  = rcDialog.right  - rcDialog.left;
40
        nHeight = rcDialog.bottom - rcDialog.top;
259 daniel-mar 41
 
268 daniel-mar 42
        xOrigin = max(rcParent.right - rcParent.left - nWidth, 0) / 2
43
                  + rcParent.left - nTitleBits;
44
        xScreen = GetSystemMetrics(SM_CXSCREEN);
45
        if  (xOrigin + nWidth > xScreen)
46
                xOrigin = max (0, xScreen - nWidth);
259 daniel-mar 47
 
48
        yOrigin = max(rcParent.bottom - rcParent.top - nHeight, 0) / 3
268 daniel-mar 49
                  + rcParent.top;
50
        yScreen = GetSystemMetrics(SM_CYSCREEN);
51
        if  (yOrigin + nHeight > yScreen)
52
                yOrigin = max(0 , yScreen - nHeight);
259 daniel-mar 53
 
268 daniel-mar 54
        SetWindowPos(hDlg, NULL, xOrigin, yOrigin, nWidth, nHeight, SWP_NOZORDER);
259 daniel-mar 55
}