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