Subversion Repositories filter_foundry

Rev

Rev 193 | 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;
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);
22
 
23
    if  (hParent == NULL)
24
        hParent = GetDesktopWindow();
25
 
26
    GetClientRect(hParent, &rcParent);
27
    ClientToScreen(hParent, (LPPOINT)&rcParent.left);  // point(left,  top)
28
    ClientToScreen(hParent, (LPPOINT)&rcParent.right); // point(right, bottom)
29
 
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);
33
 
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;
37
 
38
    GetWindowRect(hDlg, &rcDialog);
39
    nWidth  = rcDialog.right  - rcDialog.left;
40
    nHeight = rcDialog.bottom - rcDialog.top;
41
 
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);
47
 
48
        yOrigin = max(rcParent.bottom - rcParent.top - nHeight, 0) / 3
49
            + rcParent.top;
50
    yScreen = GetSystemMetrics(SM_CYSCREEN);
51
    if  (yOrigin + nHeight > yScreen)
52
        yOrigin = max(0 , yScreen - nHeight);
53
 
54
    SetWindowPos(hDlg, NULL, xOrigin, yOrigin, nWidth, nHeight, SWP_NOZORDER);
55
}