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
32 #include <winsock2.h>
\r
33 #include <windows.h>
\r
37 #include <commctrl.h>
\r
38 #include <windowsx.h>
\r
41 #include "resource.h"
\r
44 /*---------------------------------------------------------------------------*/
\r
45 /* サイズ変更可能とするダイアログボックスは WS_CLIPCHILDREN スタイルを追加す */
\r
47 /*---------------------------------------------------------------------------*/
\r
50 /*----- ダイアログボックスの初期サイズを設定 ----------------------------------
\r
53 * HWND hDlg : ウインドウハンドル
\r
54 * DIALOGSIZE *Dt : ダイアログサイズ設定パラメータ
\r
55 * SIZE *Size : ダイアログのサイズ
\r
59 *----------------------------------------------------------------------------*/
\r
61 void DlgSizeInit(HWND hDlg, DIALOGSIZE *Dt, SIZE *Size)
\r
65 GetWindowRect(hDlg, &Rect);
\r
66 Dt->MinSize.cx = Rect.right - Rect.left;
\r
67 Dt->MinSize.cy = Rect.bottom - Rect.top;
\r
68 Dt->CurSize.cx = Dt->MinSize.cx;
\r
69 Dt->CurSize.cy = Dt->MinSize.cy;
\r
73 Rect.right = Rect.left + Size->cx;
\r
74 Rect.bottom = Rect.top + Size->cy;
\r
76 DlgSizeChange(hDlg, Dt, &Rect, WMSZ_BOTTOMRIGHT);
\r
78 GetWindowRect(hDlg, &Rect);
\r
79 MoveWindow(hDlg, Rect.left, Rect.top, Dt->CurSize.cx, Dt->CurSize.cy, TRUE);
\r
85 /*----- ダイアログボックスのサイズを返す --------------------------------------
\r
88 * HWND hDlg : ウインドウハンドル
\r
89 * DIALOGSIZE *Dt : ダイアログサイズ設定パラメータ
\r
90 * SIZE *Size : ダイアログのサイズを返すワーク
\r
94 *----------------------------------------------------------------------------*/
\r
96 void AskDlgSize(HWND hDlg, DIALOGSIZE *Dt, SIZE *Size)
\r
98 Size->cx = Dt->CurSize.cx;
\r
99 Size->cy = Dt->CurSize.cy;
\r
105 /*----- ダイアログボックスのサイズ変更処理 ------------------------------------
\r
108 * HWND hDlg : ウインドウハンドル
\r
109 * DIALOGSIZE *Dt : ダイアログサイズ設定パラメータ
\r
110 * RECT *New : 新しいダイアログのサイズ
\r
111 * int Flg : サイズ変更方向 (WMSZ_xxx)
\r
117 * ダイアログボックスに WM_SIZING メッセージが来た時に呼ぶ事
\r
118 *----------------------------------------------------------------------------*/
\r
120 void DlgSizeChange(HWND hDlg, DIALOGSIZE *Dt, RECT *New, int Flg)
\r
126 /* 最少サイズより小さくならないようにする処理 */
\r
127 if((New->right - New->left) < Dt->MinSize.cx)
\r
129 if((Flg == WMSZ_LEFT) || (Flg == WMSZ_TOPLEFT) || (Flg == WMSZ_BOTTOMLEFT))
\r
130 New->left = New->right - Dt->MinSize.cx;
\r
132 New->right = New->left + Dt->MinSize.cx;
\r
134 if((New->bottom - New->top) < Dt->MinSize.cy)
\r
136 if((Flg == WMSZ_TOP) || (Flg == WMSZ_TOPLEFT) || (Flg == WMSZ_TOPRIGHT))
\r
137 New->top = New->bottom - Dt->MinSize.cy;
\r
139 New->bottom = New->top + Dt->MinSize.cy;
\r
142 /* 水平方向に移動する部品の処理 */
\r
143 if(Dt->CurSize.cx != New->right - New->left)
\r
145 Win = Dt->HorMoveList;
\r
148 GetWindowRect(GetDlgItem(hDlg, *Win), &Rect);
\r
149 Point.x = Rect.left + (New->right - New->left) - Dt->CurSize.cx;
\r
150 Point.y = Rect.top;
\r
151 ScreenToClient(hDlg, &Point);
\r
153 GetClientRect(GetDlgItem(hDlg, *Win), &Rect);
\r
154 Rect.left = Point.x;
\r
155 Rect.top = Point.y;
\r
156 MoveWindow(GetDlgItem(hDlg, *Win), Rect.left, Rect.top, Rect.right, Rect.bottom, FALSE);
\r
162 /* 垂直方向に移動する部品の処理 */
\r
163 if(Dt->CurSize.cy != New->bottom - New->top)
\r
165 Win = Dt->VarMoveList;
\r
168 GetWindowRect(GetDlgItem(hDlg, *Win), &Rect);
\r
169 Point.x = Rect.left;
\r
170 Point.y = Rect.top + (New->bottom - New->top) - Dt->CurSize.cy;
\r
171 ScreenToClient(hDlg, &Point);
\r
173 GetClientRect(GetDlgItem(hDlg, *Win), &Rect);
\r
174 Rect.left = Point.x;
\r
175 Rect.top = Point.y;
\r
176 MoveWindow(GetDlgItem(hDlg, *Win), Rect.left, Rect.top, Rect.right, Rect.bottom, FALSE);
\r
182 /* 大きさを変更する部品の処理 */
\r
183 if((Dt->CurSize.cx != New->right - New->left) ||
\r
184 (Dt->CurSize.cy != New->bottom - New->top))
\r
186 Win = Dt->ResizeList;
\r
189 GetWindowRect(GetDlgItem(hDlg, *Win), &Rect);
\r
190 Rect.right = (Rect.right - Rect.left) + (New->right - New->left) - Dt->CurSize.cx;
\r
191 Rect.bottom = (Rect.bottom - Rect.top) + (New->bottom - New->top) - Dt->CurSize.cy;
\r
193 Point.x = Rect.left;
\r
194 Point.y = Rect.top;
\r
195 ScreenToClient(hDlg, &Point);
\r
196 Rect.left = Point.x;
\r
197 Rect.top = Point.y;
\r
199 MoveWindow(GetDlgItem(hDlg, *Win), Rect.left, Rect.top, Rect.right, Rect.bottom, FALSE);
\r
206 Dt->CurSize.cx = New->right - New->left;
\r
207 Dt->CurSize.cy = New->bottom - New->top;
\r
208 InvalidateRect(hDlg, NULL, FALSE);
\r