1 /*=============================================================================
\r
5 ===============================================================================
\r
6 / Copyright (C) 1997-2007 Sota. All rights reserved.
\r
8 / Redistribution and use in source and binary forms, with or without
\r
9 / modification, are permitted provided that the following conditions
\r
12 / 1. Redistributions of source code must retain the above copyright
\r
13 / notice, this list of conditions and the following disclaimer.
\r
14 / 2. Redistributions in binary form must reproduce the above copyright
\r
15 / notice, this list of conditions and the following disclaimer in the
\r
16 / documentation and/or other materials provided with the distribution.
\r
18 / THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
\r
19 / IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
\r
20 / OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
\r
21 / IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
22 / INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
\r
23 / BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
\r
24 / USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
\r
25 / ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
26 / (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
\r
27 / THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
28 /============================================================================*/
\r
31 #include <windows.h>
\r
35 #include <commctrl.h>
\r
36 #include <windowsx.h>
\r
39 #include "resource.h"
\r
42 /*---------------------------------------------------------------------------*/
\r
43 /* サイズ変更可能とするダイアログボックスは WS_CLIPCHILDREN スタイルを追加す */
\r
45 /*---------------------------------------------------------------------------*/
\r
48 /*----- ダイアログボックスの初期サイズを設定 ----------------------------------
\r
51 * HWND hDlg : ウインドウハンドル
\r
52 * DIALOGSIZE *Dt : ダイアログサイズ設定パラメータ
\r
53 * SIZE *Size : ダイアログのサイズ
\r
57 *----------------------------------------------------------------------------*/
\r
59 void DlgSizeInit(HWND hDlg, DIALOGSIZE *Dt, SIZE *Size)
\r
63 GetWindowRect(hDlg, &Rect);
\r
64 Dt->MinSize.cx = Rect.right - Rect.left;
\r
65 Dt->MinSize.cy = Rect.bottom - Rect.top;
\r
66 Dt->CurSize.cx = Dt->MinSize.cx;
\r
67 Dt->CurSize.cy = Dt->MinSize.cy;
\r
71 Rect.right = Rect.left + Size->cx;
\r
72 Rect.bottom = Rect.top + Size->cy;
\r
74 DlgSizeChange(hDlg, Dt, &Rect, WMSZ_BOTTOMRIGHT);
\r
76 GetWindowRect(hDlg, &Rect);
\r
77 MoveWindow(hDlg, Rect.left, Rect.top, Dt->CurSize.cx, Dt->CurSize.cy, TRUE);
\r
83 /*----- ダイアログボックスのサイズを返す --------------------------------------
\r
86 * HWND hDlg : ウインドウハンドル
\r
87 * DIALOGSIZE *Dt : ダイアログサイズ設定パラメータ
\r
88 * SIZE *Size : ダイアログのサイズを返すワーク
\r
92 *----------------------------------------------------------------------------*/
\r
94 void AskDlgSize(HWND hDlg, DIALOGSIZE *Dt, SIZE *Size)
\r
96 Size->cx = Dt->CurSize.cx;
\r
97 Size->cy = Dt->CurSize.cy;
\r
103 /*----- ダイアログボックスのサイズ変更処理 ------------------------------------
\r
106 * HWND hDlg : ウインドウハンドル
\r
107 * DIALOGSIZE *Dt : ダイアログサイズ設定パラメータ
\r
108 * RECT *New : 新しいダイアログのサイズ
\r
109 * int Flg : サイズ変更方向 (WMSZ_xxx)
\r
115 * ダイアログボックスに WM_SIZING メッセージが来た時に呼ぶ事
\r
116 *----------------------------------------------------------------------------*/
\r
118 void DlgSizeChange(HWND hDlg, DIALOGSIZE *Dt, RECT *New, int Flg)
\r
124 /* 最少サイズより小さくならないようにする処理 */
\r
125 if((New->right - New->left) < Dt->MinSize.cx)
\r
127 if((Flg == WMSZ_LEFT) || (Flg == WMSZ_TOPLEFT) || (Flg == WMSZ_BOTTOMLEFT))
\r
128 New->left = New->right - Dt->MinSize.cx;
\r
130 New->right = New->left + Dt->MinSize.cx;
\r
132 if((New->bottom - New->top) < Dt->MinSize.cy)
\r
134 if((Flg == WMSZ_TOP) || (Flg == WMSZ_TOPLEFT) || (Flg == WMSZ_TOPRIGHT))
\r
135 New->top = New->bottom - Dt->MinSize.cy;
\r
137 New->bottom = New->top + Dt->MinSize.cy;
\r
140 /* 水平方向に移動する部品の処理 */
\r
141 if(Dt->CurSize.cx != New->right - New->left)
\r
143 Win = Dt->HorMoveList;
\r
146 GetWindowRect(GetDlgItem(hDlg, *Win), &Rect);
\r
147 Point.x = Rect.left + (New->right - New->left) - Dt->CurSize.cx;
\r
148 Point.y = Rect.top;
\r
149 ScreenToClient(hDlg, &Point);
\r
151 GetClientRect(GetDlgItem(hDlg, *Win), &Rect);
\r
152 Rect.left = Point.x;
\r
153 Rect.top = Point.y;
\r
154 MoveWindow(GetDlgItem(hDlg, *Win), Rect.left, Rect.top, Rect.right, Rect.bottom, FALSE);
\r
160 /* 垂直方向に移動する部品の処理 */
\r
161 if(Dt->CurSize.cy != New->bottom - New->top)
\r
163 Win = Dt->VarMoveList;
\r
166 GetWindowRect(GetDlgItem(hDlg, *Win), &Rect);
\r
167 Point.x = Rect.left;
\r
168 Point.y = Rect.top + (New->bottom - New->top) - Dt->CurSize.cy;
\r
169 ScreenToClient(hDlg, &Point);
\r
171 GetClientRect(GetDlgItem(hDlg, *Win), &Rect);
\r
172 Rect.left = Point.x;
\r
173 Rect.top = Point.y;
\r
174 MoveWindow(GetDlgItem(hDlg, *Win), Rect.left, Rect.top, Rect.right, Rect.bottom, FALSE);
\r
180 /* 大きさを変更する部品の処理 */
\r
181 if((Dt->CurSize.cx != New->right - New->left) ||
\r
182 (Dt->CurSize.cy != New->bottom - New->top))
\r
184 Win = Dt->ResizeList;
\r
187 GetWindowRect(GetDlgItem(hDlg, *Win), &Rect);
\r
188 Rect.right = (Rect.right - Rect.left) + (New->right - New->left) - Dt->CurSize.cx;
\r
189 Rect.bottom = (Rect.bottom - Rect.top) + (New->bottom - New->top) - Dt->CurSize.cy;
\r
191 Point.x = Rect.left;
\r
192 Point.y = Rect.top;
\r
193 ScreenToClient(hDlg, &Point);
\r
194 Rect.left = Point.x;
\r
195 Rect.top = Point.y;
\r
197 MoveWindow(GetDlgItem(hDlg, *Win), Rect.left, Rect.top, Rect.right, Rect.bottom, FALSE);
\r
204 Dt->CurSize.cx = New->right - New->left;
\r
205 Dt->CurSize.cy = New->bottom - New->top;
\r
206 InvalidateRect(hDlg, NULL, FALSE);
\r