[PR]

『新妻LOVELY×CATION』を応援しています!
水無瀬の部屋 > Programming > sample > cur2cpp > instdlg.cpp
最終更新日: 2007/03/29

   1: //*********************************************************
   2: // プロジェクト: cur2cpp
   3: //   ファイル名: instdlg.cpp
   4: //*********************************************************
   5: #include "instdlg.h"  //
   6: #include "install.h" //
   7: #include "res.h"     //
   8: #include <misc/atoffset.h>
   9: #include <header/myweburl.h>       //
  10: #include <dlg/aboutbox/aboutbox.h> //
  11: 
  12: 
  13: //---------------------------------------------------------
  14: // テスト関数 の 宣言
  15: //---------------------------------------------------------
  16: DECLARE_TESTPROC( test_InstallDlg );
  17: 
  18: 
  19: //---------------------------------------------------------
  20: // ファイルスコープ関数 の 宣言
  21: //---------------------------------------------------------
  22: static bool InitInstallDlgControls( HWND hWnd, DWORD more );
  23: static bool SetInstallDlgData( HWND hWnd, const install_t *info );
  24: static bool GetInstallDlgData( HWND hWnd, install_t *info );
  25: static bool EnableDlgItemGroup( HWND hWnd, id_t id, bool bEnable );
  26: static bool ShowDlgItemGroup( HWND hWnd, id_t id, bool bShow );
  27: static bool InitInstallDlgSystemMenu( HWND hWnd );
  28: static INT_PTR CALLBACK InstallDlgProc( HWND, UINT, WPARAM, LPARAM );
  29: 
  30: 
  31: //---------------------------------------------------------
  32: // ファイルスコープ変数 の 定義
  33: //---------------------------------------------------------
  34: //
  35: static struct g_dlg_tag
  36: 	{
  37: 		bool      ico;
  38: 		DWORD     more;
  39: 		RECT      rcClient;
  40: 		SIZE      szMinSize;
  41: 		install_t info;
  42: 	} g_dlg;
  43: 
  44: //
  45: static const struct g_ddx_tag
  46: 	{
  47: 		id_t  id;
  48: 		DWORD flag;
  49: 		int   check;
  50: 		int   more;
  51: 		int   reg;
  52: 		int   reg_title;
  53: 		int   menu;
  54: 		int   menu_title;
  55: 		int   cmdline;
  56: 		int   cmdline_title;
  57: 		int   group;
  58: 	}
  59: g_ddx[] = 
  60: 	{
  61: #define MAKE_DDX( name ) { ID_ ## name, FLAG_ ## name, IDC_ ## name, IDC_MORE_ ## name, IDC_REGPATH_ ## name, IDC_STATIC_REGPATH_ ## name, IDC_MENUTITLE_ ## name, IDC_STATIC_MENUTITLE_ ## name, IDC_CMDLINE_ ## name, IDC_STATIC_CMDLINE_ ## name, IDC_GROUP_ ## name }
  62: 		MAKE_DDX( ICO ),
  63: 		MAKE_DDX( CUR ),
  64: #undef MAKE_DDX
  65: 	};
  66: COMPILE_ASSERT( numof(g_ddx) == numof( ((install_t *)null)->reg ) );
  67: 
  68: // 各コントロールIDへのアクセス
  69: static const size_t g_offset[] =
  70: 	{
  71: #define DDX_MEMBER_OFFSET( member ) offsetof( struct g_ddx_tag, member )
  72: 		DDX_MEMBER_OFFSET( check ), 
  73: 		DDX_MEMBER_OFFSET( more ),
  74: 		DDX_MEMBER_OFFSET( reg ),
  75: 		DDX_MEMBER_OFFSET( reg_title ),
  76: 		DDX_MEMBER_OFFSET( menu ),
  77: 		DDX_MEMBER_OFFSET( menu_title ),
  78: 		DDX_MEMBER_OFFSET( cmdline ),
  79: 		DDX_MEMBER_OFFSET( cmdline_title ),
  80: 		DDX_MEMBER_OFFSET( group ),
  81: #undef DDX_MEMBER_OFFSET
  82: 	};
  83: 
  84: 
  85: //*********************************************************
  86: // InstallDlg
  87: // アプリケーションを拡張子に関連づける
  88: //*********************************************************
  89: bool
  90: InstallDlg
  91: 	(
  92: 		HWND hwndOwner
  93: 	)
  94: {
  95: 	CALLONCE_TESTPROC( test_InstallDlg ); // [テスト]
  96: 
  97: 	// パラメタの仮定
  98: 	ASSERT( !hwndOwner || IsValidWindow( hwndOwner ) );
  99: 
 100: 	HINSTANCE hInstance = GetModuleHandle( null );
 101: 	const INT_PTR result = DialogBoxParam
 102: 		(
 103: 			hInstance,
 104: 			MAKEINTRESOURCE( INSTALL_BOX ),
 105: 			hwndOwner, 
 106: 			InstallDlgProc,
 107: 			null
 108: 		);
 109: 	return IDOK == result;
 110: }//InstallDlg
 111: 
 112: 
 113: //******************************************************************************************************************
 114: //
 115: //******************************************************************************************************************
 116: static INT_PTR OnInstallInitDialog( HWND hWnd, WPARAM wParam, LPARAM lParam );
 117: static INT_PTR OnInstallDestroy( HWND hWnd );
 118: static INT_PTR OnInstallCommand( HWND hWnd, WPARAM wParam, LPARAM lParam );
 119: static INT_PTR OnInstallSystemCommand( HWND hWnd, WPARAM wParam, LPARAM lParam );
 120: static INT_PTR OnInstallHitTest( HWND hWnd, WPARAM wParam, LPARAM lParam );
 121: static INT_PTR OnInstallGetMinMaxInfo( HWND hWnd, LPARAM lParam );
 122: static INT_PTR OnInstallSize( HWND hWnd, WPARAM wParam, LPARAM lParam );
 123: 
 124: 
 125: //*********************************************************
 126: // InstallDlgProc
 127: //*********************************************************
 128: static
 129: INT_PTR
 130: CALLBACK
 131: InstallDlgProc
 132: 	(
 133: 		HWND   hWnd,
 134: 		UINT   uMsg,
 135: 		WPARAM wParam,
 136: 		LPARAM lParam
 137: 	)
 138: {
 139: 	// パラメタの仮定
 140: 	ASSERT( IsValidWindow( hWnd ) );
 141: 
 142: 	switch( uMsg )
 143: 	{
 144: 		case WM_DESTROY:       return OnInstallDestroy( hWnd );
 145: 		case WM_NCHITTEST:     return OnInstallHitTest( hWnd, wParam, lParam );
 146: 		case WM_INITDIALOG:    return OnInstallInitDialog( hWnd, wParam, lParam );
 147: 		case WM_COMMAND:       return OnInstallCommand( hWnd, wParam, lParam );
 148: 		case WM_SYSCOMMAND:    return OnInstallSystemCommand( hWnd, wParam, lParam );
 149: 		case WM_GETMINMAXINFO: return OnInstallGetMinMaxInfo( hWnd, lParam );
 150: 		case WM_SIZE:          return OnInstallSize( hWnd, wParam, lParam );
 151: 		default:               return false;
 152: 	}
 153: }//InstallDlgProc
 154: 
 155: //*********************************************************
 156: // OnInstallInitDialog - WM_INITDIALOG
 157: // ダイアログが作成された。
 158: // この関数が抜けるまでダイアログは表示されない。
 159: // 明示的にフォーカスを移動した場合は 真 を返せ。
 160: // さもなくば 偽 を返せ。
 161: //   HWND   wParam …… フォーカスを受け取る予定のコントロール
 162: //   LPARAM lParam …… ダイアログの初期化パラメタ
 163: //*********************************************************
 164: static
 165: INT_PTR
 166: OnInstallInitDialog
 167: 	(
 168: 		HWND   hWnd,
 169: 		WPARAM _unuse( wParam ),
 170: 		LPARAM _unuse( lParam )
 171: 	)
 172: {
 173: 	// パラメタの仮定
 174: 	ASSERT( IsValidWindow( hWnd ) );
 175: 	ASSERT( IsValidInitDialogMessageParam( wParam, lParam ) );
 176: 
 177: 	// ダイアログ の 初期化
 178: 	{
 179: 		HINSTANCE hInstance = GetModuleHandle( null );
 180: 		HICON hIcon   = SHGetInstanceIcon( hInstance, SHGFI_LARGEICON );
 181: 		HICON hIconSm = SHGetInstanceIcon( hInstance, SHGFI_SMALLICON );
 182: 		SetWindowIcon( hWnd, ICON_BIG,   hIcon   ); // 大きいアイコン
 183: 		SetWindowIcon( hWnd, ICON_SMALL, hIconSm ); // 小さいアイコン
 184: 		VERIFY( WindowMoveToCursorPos( hWnd ) );
 185: 
 186: 		// ダイアログ情報 g_dlg の 初期化
 187: 		{
 188: 			//
 189: 			VERIFY( GetClientRect( hWnd, &g_dlg.rcClient ) );
 190: 			VERIFY( GetWindowSize( hWnd, &g_dlg.szMinSize ) );
 191: 			
 192: 			//
 193: 			VERIFY( LoadInstallInfo( &g_dlg.info ) );
 194: 
 195: 			// 全ての詳細を隠す
 196: 			g_dlg.more = 0;
 197: 
 198: 			// 
 199: 			g_dlg.ico = (FLAG_ICO == (FLAG_ICO & g_dlg.info.flags)); 
 200: 		}
 201: 	}
 202: 
 203: 	// システムメニュー の 初期化
 204: 	VERIFY( InitInstallDlgSystemMenu( hWnd ) );
 205: 
 206: 	// コントロール の 初期化
 207: 	VERIFY( InitInstallDlgControls( hWnd, g_dlg.more ) );
 208: 
 209: 	// コントロール値 の 設定
 210: 	VERIFY( SetInstallDlgData( hWnd, &g_dlg.info ) );
 211: 
 212: 	return false;
 213: }//OnInstallInitDialog
 214: 
 215: //*********************************************************
 216: // OnInstallDestroy - WM_DESTROY
 217: // まもなくウィンドウが破棄される。
 218: // ウィンドウに関連付けた独自リソースを破棄する。
 219: // 常に 真 を返す。
 220: //*********************************************************
 221: static
 222: INT_PTR
 223: OnInstallDestroy
 224: 	(
 225: 		HWND _unuse( hWnd )
 226: 	)
 227: {
 228: 	// パラメタの仮定
 229: 	ASSERT( IsValidWindow( hWnd ) );
 230: 
 231: 	return true;
 232: }//OnInstallDestroy
 233: 
 234: //*********************************************************
 235: // OnInstallHitTest - WM_NCHITTEST
 236: // カーソル・イベントがあるたびに呼び出される。
 237: // カーソルが存在する位置を示す値を返す。
 238: //   GET_X_LPARAM( lParam ) …… カーソルのスクリーン x 座標
 239: //   GET_Y_LPARAM( lParam ) …… カーソルのスクリーン y 座標
 240: //*********************************************************
 241: static
 242: INT_PTR
 243: OnInstallHitTest
 244: 	(
 245: 		HWND   hWnd,
 246: 		WPARAM wParam, 
 247: 		LPARAM lParam
 248: 	)
 249: {
 250: 	// パラメタの仮定
 251: 	ASSERT( IsValidWindow( hWnd ) );
 252: 
 253: 	// サイズ変更矢印の変換ルール一覧
 254: 	const struct { LRESULT from; LRESULT to; } trans[] = 
 255: 		{
 256: 			{ HTCLIENT,      HTCAPTION }, // クライアント領域を掴んで移動可能に
 257: 			{ HTTOP,         HTBORDER  }, // 上端の縦矢印 → 矢印なし
 258: 			{ HTBOTTOM,      HTBORDER  }, // 下端の縦矢印 → 矢印なし
 259: 			{ HTTOPLEFT,     HTLEFT    }, // 左上隅の斜め矢印 → 左右矢印
 260: 			{ HTTOPRIGHT,    HTRIGHT   }, // 右上隅の斜め矢印 → 左右矢印
 261: 			{ HTBOTTOMLEFT,  HTLEFT    }, // 左下隅の斜め矢印 → 左右矢印
 262: 			{ HTBOTTOMRIGHT, HTRIGHT   }, // 右下隅の斜め矢印 → 左右矢印
 263: 		};
 264: 	// 変換一覧にあれば変換した値を返す
 265: 	const LRESULT lResult = DefWindowProc( hWnd, WM_NCHITTEST, wParam, lParam );
 266: 	{for( int i = 0; i < numof( trans ); ++i )
 267: 	{
 268: 		if ( lResult == trans[ i ].from )
 269: 		{
 270: 			SetWindowLongPtr64( hWnd, DWL_MSGRESULT, trans[ i ].to );
 271: 			return true;
 272: 		}
 273: 	}}
 274: 
 275: 	return false;
 276: }//OnInstallHitTest
 277: 
 278: //*********************************************************
 279: // OnInstallGetMinMaxInfo
 280: //*********************************************************
 281: static
 282: INT_PTR
 283: OnInstallGetMinMaxInfo
 284: 	(
 285: 		HWND   hWnd,
 286: 		LPARAM lParam
 287: 	)
 288: {
 289: 	// パラメタの仮定
 290: 	ASSERT( IsValidWindow( hWnd ) );
 291: 	ASSERT( IsValidPtr( (MINMAXINFO *)lParam, sizeof(MINMAXINFO) ) );
 292: 
 293: 	//
 294: 	MINMAXINFO *pmmi = (MINMAXINFO *)lParam;
 295: 
 296: 	//
 297: 	pmmi->ptMinTrackSize.y = g_dlg.szMinSize.cy;
 298: 	pmmi->ptMaxTrackSize.y = g_dlg.szMinSize.cy;
 299: 
 300: 	//
 301: 	pmmi->ptMinTrackSize.x = ((0 != g_dlg.more) ? 2 : 1) * g_dlg.szMinSize.cx;
 302: 
 303: 	//
 304: 	if ( 0 == g_dlg.more )
 305: 	{
 306: 		pmmi->ptMaxTrackSize.x = g_dlg.szMinSize.cx;
 307: 	}
 308: 
 309: 	return true;
 310: }//OnInstallGetMinMaxInfo
 311: 
 312: //*********************************************************
 313: // OnInstallSize
 314: //*********************************************************
 315: static
 316: INT_PTR
 317: OnInstallSize
 318: 	(
 319: 		HWND   hWnd,
 320: 		WPARAM wParam,
 321: 		LPARAM lParam
 322: 	)
 323: {
 324: 	// パラメタの仮定
 325: 	ASSERT( IsValidWindow( hWnd ) );
 326: 
 327: 	// 最小化時は無視
 328: 	if ( SIZE_MINIMIZED == wParam )
 329: 		return true;
 330: 
 331: 	// 移動とサイズ変更のリスト
 332: 	const struct
 333: 		{
 334: 			int  nID;
 335: 			bool pos_x;
 336: 			bool pos_y;
 337: 			bool size_x;
 338: 			bool size_y;
 339: 		}
 340: 	ctrl[] =
 341: 		{
 342: //			{ IDC_CUR,           false, false, false, false  },
 343: 			{ IDC_MORE_CUR,      true,  false, false, false  },
 344: 			{ IDC_REGPATH_CUR,   false, false, true,  false  },
 345: 			{ IDC_MENUTITLE_CUR, false, false, true,  false  },
 346: 			{ IDC_CMDLINE_CUR,   false, false, true,  false  },
 347: 			{ IDC_GROUP_CUR,     false, false, true,  false  },
 348: //			{ IDC_ICO,           false, false, false, false  },
 349: 			{ IDC_MORE_ICO,      true,  false, false, false  },
 350: 			{ IDC_REGPATH_ICO,   false, false, true,  false  },
 351: 			{ IDC_MENUTITLE_ICO, false, false, true,  false  },
 352: 			{ IDC_CMDLINE_ICO,   false, false, true,  false  },
 353: 			{ IDC_GROUP_ICO,     false, false, true,  false  },
 354: 			{ IDOK,              true,  false, false, false  },
 355: 			{ IDCANCEL,          true,  false, false, false  }
 356: 		};
 357: 	HDWP hdwp = BeginDeferWindowPos( numof(ctrl) );
 358: 	if ( hdwp )
 359: 	{
 360: 		const int width   = LOWORD(lParam);
 361: 		const int height  = HIWORD(lParam);
 362: 		const int shift_x = width  - g_dlg.rcClient.right;
 363: 		const int shift_y = height - g_dlg.rcClient.bottom;
 364: 		{for( int i = 0; i < numof(ctrl); ++i )
 365: 		{
 366: 			ASSERT( IsValidDlgItem( hWnd, ctrl[ i ].nID ) );
 367: 			VERIFY( ShiftDeferDlgItem
 368: 				(
 369: 					&hdwp,
 370: 					hWnd,
 371: 					ctrl[i].nID,
 372: 					ctrl[i].pos_x  ? shift_x : 0,
 373: 					ctrl[i].pos_y  ? shift_y : 0,
 374: 					ctrl[i].size_x ? shift_x : 0,
 375: 					ctrl[i].size_y ? shift_y : 0
 376: 				) );
 377: 		}}
 378: 		VERIFY( EndDeferWindowPos( hdwp ) );
 379: 
 380: 		g_dlg.rcClient.right  = width;
 381: 		g_dlg.rcClient.bottom = height;
 382: 	}
 383: 	return true;
 384: }//OnInstallSize
 385: 
 386: 
 387: //******************************************************************************************************************
 388: // OnInstallCommand - WM_COMMAND
 389: //******************************************************************************************************************
 390: static INT_PTR OnInstallCommandOK( HWND hWnd );
 391: static INT_PTR OnInstallCommandCancel( HWND hWnd );
 392: static INT_PTR OnInstallCommandDefault( HWND hWnd, WPARAM wParam );
 393: static INT_PTR OnInstallCommandCheck( HWND hWnd, WPARAM wParam );
 394: static INT_PTR OnInstallCommandMore( HWND hWnd, WPARAM wParam );
 395: 
 396: 
 397: //*********************************************************
 398: // OnInstallCommand - WM_COMMAND
 399: // コマンド項目が選択された。
 400: // 返値の意味は要求されたコマンド項目による。
 401: //   LOWORD(wParam) …… 選択されたコマンド項目の識別子。
 402: //                     メニューの区切り線が選択された場合は 0 が設定される。
 403: //   HIWORD(wParam) …… 通知コード。
 404: //                     メッセージが  メニュー  から送信された場合は 0 が設定される。
 405: //                     メッセージがアクセラレータから送信された場合は 1 が設定される。
 406: //   HWND lParam    …… メッセージがコントロールから送信された場合はメッセージを送信したコントロールのハンドル。
 407: //
 408: //*********************************************************
 409: static
 410: INT_PTR
 411: OnInstallCommand
 412: 	(
 413: 		HWND   hWnd,
 414: 		WPARAM wParam,
 415: 		LPARAM _unuse( lParam )
 416: 	)
 417: {
 418: 	// パラメタの仮定
 419: 	ASSERT( IsValidWindow( hWnd ) );
 420: 	ASSERT( IsValidCommandMessageParam( wParam, lParam ) );
 421: 
 422: 	switch( LOWORD( wParam ) )
 423: 	{
 424: 		case IDOK:     return OnInstallCommandOK( hWnd );
 425: 		case IDCANCEL: return OnInstallCommandCancel( hWnd );
 426: 		default:       return OnInstallCommandDefault( hWnd, wParam );
 427: 	}
 428: }//OnInstallCommand
 429: 
 430: //*********************************************************
 431: // OnInstallCommandOK
 432: //*********************************************************
 433: static
 434: INT_PTR
 435: OnInstallCommandOK
 436: 	(
 437: 		HWND hWnd
 438: 	)
 439: {
 440: 	// パラメタの仮定
 441: 	ASSERT( IsValidWindow( hWnd ) );
 442: 
 443: 	//
 444: 	install_t info; // 設定値
 445: 	if ( ! GetInstallDlgData( hWnd, &info ) )
 446: 	{
 447: 		return false;
 448: 	}
 449: 	ASSERT( IsValidInstallInfo( &info ) );
 450: 
 451: 	// 関連づけ
 452: 	const DWORD modified = GetModifiedFlags( &info, &g_dlg.info );
 453: 	VERIFY( SaveInstallInfo( &info, modified ) );
 454: 
 455: 	//
 456: 	VERIFY( EndDialog( hWnd, IDOK ) );
 457: 
 458: 	return true;
 459: }//OnInstallCommandOK
 460: 
 461: //*********************************************************
 462: // OnInstallCommandCancel
 463: //*********************************************************
 464: static
 465: INT_PTR
 466: OnInstallCommandCancel
 467: 	(
 468: 		HWND hWnd
 469: 	)
 470: {
 471: 	// パラメタの仮定
 472: 	ASSERT( IsValidWindow( hWnd ) );	
 473: 	
 474: 	VERIFY( EndDialog( hWnd, IDCANCEL ) );
 475: 
 476: 	return true;
 477: }//OnInstallCommandCancel
 478: 
 479: //*********************************************************
 480: // OnInstallCommandDefault
 481: //*********************************************************
 482: static
 483: INT_PTR
 484: OnInstallCommandDefault
 485: 	(
 486: 		HWND   hWnd,
 487: 		WPARAM wParam
 488: 	)
 489: {
 490: 	// パラメタの仮定
 491: 	ASSERT( IsValidWindow( hWnd ) );
 492: 
 493: 	{for( int i = 0; i < numof( g_ddx ); ++i )
 494: 	{
 495: 		const int id = LOWORD( wParam );
 496: 
 497: 		if ( id == g_ddx[ i ].check )
 498: 			return OnInstallCommandCheck( hWnd, wParam );
 499: 		if ( id == g_ddx[ i ].more )
 500: 			return OnInstallCommandMore( hWnd, wParam );
 501: 	}}
 502: 
 503: 	return false;
 504: }//OnInstallCommandDefault
 505: 
 506: //*********************************************************
 507: // OnInstallCommandCheck
 508: //*********************************************************
 509: static
 510: INT_PTR
 511: OnInstallCommandCheck
 512: 	(
 513: 		HWND   hWnd,
 514: 		WPARAM wParam
 515: 	)
 516: {
 517: 	// パラメタの仮定
 518: 	ASSERT( IsValidWindow( hWnd ) );
 519: 
 520: 	//
 521: 	{for( int i = 0; i < numof( g_ddx ); ++i )
 522: 	{
 523: 		if ( g_ddx[ i ].check == LOWORD( wParam ) )
 524: 		{
 525: 			const bool bEnable = (BST_CHECKED == IsDlgButtonChecked( hWnd, g_ddx[ i ].check ));
 526: 			EnableDlgItemGroup( hWnd, g_ddx[ i ].id, bEnable );
 527: 			return true;
 528: 		}
 529: 	}}
 530: 
 531: 	UNREACHCODE( "g_ddx の抜け?" );
 532: 	return true;
 533: }//OnInstallCommandCheck
 534: 
 535: //*********************************************************
 536: // OnInstallCommandMore
 537: //*********************************************************
 538: static
 539: INT_PTR
 540: OnInstallCommandMore
 541: 	(
 542: 		HWND   hWnd,
 543: 		WPARAM wParam
 544: 	)
 545: {
 546: 	// パラメタの仮定
 547: 	ASSERT( IsValidWindow( hWnd ) );
 548: 
 549: 	//
 550: 	{for( int i = 0; i < numof( g_ddx ); ++i )
 551: 	{
 552: 		if ( g_ddx[ i ].more == LOWORD( wParam ) )
 553: 		{
 554: 			g_dlg.more ^= g_ddx[ i ].flag;
 555: 			VERIFY( ShowDlgItemGroup( hWnd, g_ddx[ i ].id, 0 != (g_dlg.more & g_ddx[ i ].flag) ) );
 556: 			return true;
 557: 		}
 558: 	}}
 559: 
 560: 	UNREACHCODE( "g_ddx の抜け?" );
 561: 	return true;
 562: }//OnInstallCommandMore
 563: 
 564: 
 565: //******************************************************************************************************************
 566: // WM_SYSCOMMAND
 567: //******************************************************************************************************************
 568: static INT_PTR OnInstallSystemCommandSetDefault( HWND hWnd );
 569: static INT_PTR OnInstallSystemCommandAbout( HWND hWnd );
 570: 
 571: 
 572: //*********************************************************
 573: // OnInstallSystemCommand - WM_SYSCOMMAND
 574: //*********************************************************
 575: static
 576: INT_PTR
 577: OnInstallSystemCommand
 578: 	(
 579: 		HWND   hWnd,
 580: 		WPARAM wParam,
 581: 		LPARAM _unuse( lParam )
 582: 	)
 583: {
 584: 	// パラメタの仮定
 585: 	ASSERT( IsValidWindow( hWnd ) );
 586: 	ASSERT( IsValidSystemCommandMessageParam( wParam, lParam ) );
 587: 
 588: 	switch( LOWORD(wParam) )
 589: 	{
 590: 		case IDM_ABOUT:      return OnInstallSystemCommandAbout( hWnd );
 591: 		case IDM_SETDEFAULT: return OnInstallSystemCommandSetDefault( hWnd );
 592: 		default:             return false;
 593: 	}
 594: }//OnInstallSystemCommand
 595: 
 596: //*********************************************************
 597: // OnInstallSystemCommandAbout
 598: //*********************************************************
 599: static
 600: INT_PTR
 601: OnInstallSystemCommandAbout
 602: 	(
 603: 		HWND hWnd
 604: 	)
 605: {
 606: 	// パラメタの仮定
 607: 	ASSERT( IsValidWindow( hWnd ) );
 608: 
 609: 	ABOUTBOX_t tmp; // AboutBox のパラメータ
 610: 	tmp.url = URL_WEBPAGE;
 611: 	AboutBox( hWnd, &tmp ); // 「……について」ダイアログを表示する。
 612: 
 613: 	return true;
 614: }//OnInstallSystemCommandAbout
 615: 
 616: //*********************************************************
 617: // OnInstallSystemCommandSetDefault
 618: //*********************************************************
 619: static
 620: INT_PTR
 621: OnInstallSystemCommandSetDefault
 622: 	(
 623: 		HWND hWnd
 624: 	)
 625: {
 626: 	// パラメタの仮定
 627: 	ASSERT( IsValidWindow( hWnd ) );
 628: 
 629: 	VERIFY( SetInstallDlgData( hWnd, &g_dlg.info ) );
 630: 
 631: 	//
 632: 	g_dlg.ico = (FLAG_ICO == (FLAG_ICO & g_dlg.info.flags)); 
 633: 
 634: 	// OnInstallSystemCommandUsePif(), InitInstallDlgControls() と重複している!
 635: 	// 関数名を考えよう!
 636: 	if ( g_dlg.ico )
 637: 	{
 638: 		VisibleDlgItem( hWnd, IDC_ICO,      true );
 639: 		VisibleDlgItem( hWnd, IDC_MORE_ICO, true );
 640: 	}
 641: 	else
 642: 	{
 643: 		VisibleDlgItem( hWnd, IDC_ICO,      false );
 644: 		VisibleDlgItem( hWnd, IDC_MORE_ICO, false );
 645: 
 646: 		if ( FLAG_ICO == (g_dlg.more & FLAG_ICO) )
 647: 		{
 648: 			g_dlg.more ^= FLAG_ICO;
 649: 			VERIFY( ShowDlgItemGroup( hWnd, ID_ICO, FLAG_ICO == (FLAG_ICO & g_dlg.more) ) );
 650: 		}
 651: 	}
 652: 
 653: 	return true;
 654: }//OnInstallSystemCommandSetDefault
 655: 
 656: 
 657: //******************************************************************************************************************
 658: // private - init
 659: //******************************************************************************************************************
 660: //*********************************************************
 661: // InitInstallDlgSystemMenu
 662: //*********************************************************
 663: static
 664: bool
 665: InitInstallDlgSystemMenu
 666: 	(
 667: 		HWND hWnd
 668: 	)
 669: {
 670: 	// パラメタの仮定
 671: 	ASSERT( IsValidWindow( hWnd ) );
 672: 
 673: 	HMENU hmenuSystem = GetSystemMenu( hWnd, false );
 674: 	const int pos = GetMenuItemPos( hmenuSystem, SC_ZOOM );
 675: 	if ( 0 <= pos )
 676: 	{
 677: 		const struct 
 678: 			{
 679: 					  UINT  type;
 680: 					  UINT  id;
 681: 				const char *title;
 682: 			}
 683: 		item[] =
 684: 			{
 685: #define MAKE_MENUITEM( type, id, title ) { type, id, title }
 686: 				MAKE_MENUITEM( MF_SEPARATOR, 0,              null ),
 687: 				MAKE_MENUITEM( MF_STRING,    IDM_SETDEFAULT, "設定を初期値に戻す(&D)" ),
 688: 				MAKE_MENUITEM( MF_STRING,    IDM_ABOUT,      "About(&A)" ),
 689: #undef MAKE_MENUITEM
 690: 			};
 691: 		{for( int i = numof( item ); 0 < i; --i )
 692: 		{
 693: 			VERIFY( InsertMenu( hmenuSystem, pos+1, MF_BYPOSITION | item[ i-1 ].type, item[ i-1 ].id, item[ i-1 ].title ) );
 694: 	//		Menu_InsertSeparator( hmenuSystem, pos+1, MF_BYPOSITION );
 695: 		}}
 696: 	}
 697: 
 698: 	return true;
 699: }//InitInstallDlgSystemMenu
 700: 
 701: 
 702: //******************************************************************************************************************
 703: // private
 704: //******************************************************************************************************************
 705: static bool SetInstallDlgDataVerbList( HWND hwndListView, const char *verb );
 706: 
 707: 
 708: //*********************************************************
 709: // ShowDlgItemGroup
 710: //*********************************************************
 711: static
 712: bool
 713: ShowDlgItemGroup
 714: 	(
 715: 		HWND hWnd,
 716: 		id_t id,
 717: 		bool bShow
 718: 	)
 719: {
 720: 	// パラメタの仮定
 721: 	ASSERT( IsValidWindow( hWnd ) );
 722: 	ASSERT( IS_VALID_ID( id ) );
 723: 
 724: 	{for( int index = 0; index < numof( g_ddx ); ++index )
 725: 	{
 726: 		if ( id == g_ddx[ index ].id )
 727: 		{
 728: 			//
 729: 			SetDlgItemText( hWnd, g_ddx[ index ].more, bShow ? "<< 詳細" : "詳細 >>" );
 730: 
 731: 			//
 732: 			{for( int i = 0; i < numof( g_offset ); ++i )
 733: 			{
 734: 				const int ctrl = atoffset( int, &g_ddx[ index ], g_offset[ i ] );
 735: 				if ( (ctrl != g_ddx[ index ].check )
 736: 				  && (ctrl != g_ddx[ index ].more) )
 737: 				{
 738: 					if ( IsValidDlgItem( hWnd, ctrl ) )
 739: 					{
 740: 						VisibleDlgItem( hWnd, ctrl, bShow );
 741: 					}
 742: 				}
 743: 			}}
 744: 
 745: 			//
 746: 			const int sign = bShow ? 1 : -1;
 747: 			const int group_bottom = GetDlgItemBottom( hWnd, g_ddx[ index ].group );
 748: 			const int more_bottom  = GetDlgItemBottom( hWnd, g_ddx[ index ].more );
 749: 			const int height = sign * (group_bottom - more_bottom);
 750: 
 751: 			//
 752: 			{for( int i = 0; i < numof( g_ddx ); ++i )
 753: 			{
 754: 				if ( i != index )
 755: 				{
 756: 					if ( more_bottom < GetDlgItemTop( hWnd, g_ddx[ i ].group ) )
 757: 					{
 758: 						{for( int j = 0; j < numof( g_offset ); ++j )
 759: 						{
 760: 							const int ctrl = atoffset( int, &g_ddx[ i ], g_offset[ j ] );
 761: 							if ( IsValidDlgItem( hWnd, ctrl ) )
 762: 							{
 763: 								ShiftDlgItemPos( hWnd, ctrl, 0, height );
 764: 							}
 765: 						}}
 766: 					}
 767: 				}
 768: 			}}
 769: 
 770: 			//
 771: 			ShiftDlgItemPos( hWnd, IDOK,     0, height );
 772: 			ShiftDlgItemPos( hWnd, IDCANCEL, 0, height );
 773: 
 774: 			//
 775: 			g_dlg.szMinSize.cy += height;
 776: 			ShiftWindowSize( hWnd, 0, height );
 777: 		}
 778: 	}}
 779: 
 780: 	return true;
 781: }//ShowDlgItemGroup
 782: 
 783: //*********************************************************
 784: // EnableDlgItemGroup
 785: //*********************************************************
 786: static
 787: bool
 788: EnableDlgItemGroup
 789: 	(
 790: 		HWND hWnd,
 791: 		id_t id,
 792: 		bool bEnable
 793: 	)
 794: {
 795: 	// パラメタの仮定
 796: 	ASSERT( IsValidWindow( hWnd ) );
 797: 	ASSERT( IS_VALID_ID( id ) );
 798: 
 799: 	//
 800: 	{for( int index = 0; index < numof( g_ddx ); ++index )
 801: 	{
 802: 		if ( id == g_ddx[ index ].id )
 803: 		{
 804: 			{for( int i = 0; i < numof( g_offset ); ++i )
 805: 			{
 806: 				const int ctrl = atoffset( int, &g_ddx[ index ], g_offset[ i ] );
 807: 				if ( (ctrl != g_ddx[ index ].check )
 808: 				  && (ctrl != g_ddx[ index ].more) )
 809: 				{
 810: 					if ( IsValidDlgItem( hWnd, ctrl ) )
 811: 					{
 812: 						EnableDlgItem( hWnd, ctrl, bEnable );
 813: 					}
 814: 				}
 815: 			}}
 816: 		}
 817: 	}}
 818: 
 819: 	return true;
 820: }//EnableDlgItemGroup
 821: 
 822: //*********************************************************
 823: // GetInstallDlgData
 824: //*********************************************************
 825: static
 826: bool
 827: GetInstallDlgData
 828: 	(
 829: 		HWND       hWnd,
 830: 		install_t *info
 831: 	)
 832: {
 833: 	// パラメタの仮定
 834: 	ASSERT( IsValidWindow( hWnd ) );
 835: 	ASSERT( IsValidPtr( info, sizeof( *info ) ) );
 836: 	DESTROY_BUFFER( info, sizeof( *info ) ); // [破壊]
 837: 
 838: 	// 関連づけ
 839: 	info->flags = 0;
 840: 	{for( int i = 0; i < numof( g_ddx ); ++i )
 841: 	{
 842: 		// check
 843: 		if ( IsValidDlgItem( hWnd, g_ddx[ i ].check ) )
 844: 		{
 845: 			if ( BST_CHECKED == IsDlgButtonChecked( hWnd, g_ddx[ i ].check ) )
 846: 			{
 847: 				info->flags |= g_ddx[ i ].flag;
 848: 			}
 849: 		}
 850: 		
 851: 		//
 852: 		{
 853: 			ASSERT( IS_VALID_ID( g_ddx[ i ].id ) );
 854: 			const size_t index = ID_INDEX( g_ddx[ i ].id );
 855: 			ASSERT( IS_VALID_INDEX( index ) );
 856: 			relation_t *reg = &info->reg[ index ];
 857: 
 858: 			// default
 859: 			strcopy( reg->menu, numof(reg->menu), g_dlg.info.reg[ index ].menu );
 860: 			strcopy( reg->cmdline, numof(reg->cmdline), g_dlg.info.reg[ index ].cmdline );
 861: 			strcopy( reg->regpath, numof(reg->regpath), g_dlg.info.reg[ index ].regpath );
 862: 
 863: 			// regpath
 864: 			if ( IsValidDlgItem( hWnd, g_ddx[ i ].reg ) )
 865: 			{
 866: 				VERIFY( 0 <= GetDlgItemText( hWnd, g_ddx[ i ].reg, reg->regpath, numof( reg->regpath ) ) );
 867: 			}
 868: //			ASSERT( IsValidRegistryPathString( reg->regpath ) );
 869: 
 870: 			// menu
 871: 			if ( IsValidDlgItem( hWnd, g_ddx[ i ].menu ) )
 872: 			{
 873: 				VERIFY( 0 <= GetDlgItemText( hWnd, g_ddx[ i ].menu, reg->menu, numof( reg->menu ) ) );
 874: 			}
 875: 			ASSERT( IsValidStringPtr( reg->menu ) );
 876: 
 877: 			// cmdline
 878: 			if ( IsValidDlgItem( hWnd, g_ddx[ i ].cmdline ) )
 879: 			{
 880: 				VERIFY( 0 <= GetDlgItemText( hWnd, g_ddx[ i ].cmdline, reg->cmdline, numof( reg->cmdline ) ) );
 881: 			}
 882: 			ASSERT( IsValidCommandLineString( reg->cmdline ) );
 883: 		}
 884: 	}}
 885: 
 886: 	
 887: 	ASSERT( IsValidInstallInfo( info ) );
 888: 	return true;
 889: }//GetInstallDlgData
 890: 
 891: //*********************************************************
 892: // SetInstallDlgData
 893: //*********************************************************
 894: static
 895: bool
 896: SetInstallDlgData
 897: 	(
 898: 		      HWND       hWnd,
 899: 		const install_t *info
 900: 	)
 901: {
 902: 	// パラメタの仮定
 903: 	ASSERT( IsValidWindow( hWnd ) );
 904: 	ASSERT( IsValidInstallInfo( info ) );
 905: 
 906: 	// 
 907: 	{for( int i = 0; i < numof( g_ddx ); ++i )
 908: 	{
 909: 		// check
 910: 		const UINT uCheck = (g_ddx[ i ].flag == (info->flags & g_ddx[ i ].flag)) ? BST_CHECKED : BST_UNCHECKED;
 911: 		if ( ! IsValidDlgItem( hWnd, g_ddx[ i ].check ) )
 912: 		{
 913: 			EnableDlgItemGroup( hWnd, g_ddx[ i ].id, false );
 914: 		}
 915: 		else
 916: 		{
 917: 			EnableDlgItemGroup( hWnd, g_ddx[ i ].id, BST_CHECKED == uCheck );
 918: 			CheckDlgButton( hWnd, g_ddx[ i ].check, uCheck );
 919: 		}
 920: 
 921: 		//
 922: 		{
 923: 			ASSERT( IS_VALID_ID( g_ddx[ i ].id ) );
 924: 			const size_t index = ID_INDEX( g_ddx[ i ].id );
 925: 			ASSERT( IS_VALID_INDEX( index ) );
 926: 			const relation_t *reg = &info->reg[ index ];
 927: //			ASSERT( IsValidRegistryPathString( reg->regpath ) );
 928: 			ASSERT( IsValidCommandLineString( reg->cmdline ) );
 929: 			ASSERT( IsValidStringPtr( reg->menu ) );
 930: 
 931: 			// regpath
 932: 			if ( IsValidDlgItem( hWnd, g_ddx[ i ].reg ) )
 933: 			{
 934: 				VERIFY( SetDlgItemText( hWnd, g_ddx[ i ].reg, reg->regpath ) );
 935: 			}
 936: 
 937: 			// menu
 938: 			if ( IsValidDlgItem( hWnd, g_ddx[ i ].menu ) )
 939: 			{
 940: 				VERIFY( SetDlgItemText( hWnd, g_ddx[ i ].menu, reg->menu ) );
 941: 			}
 942: 
 943: 			// cmdline
 944: 			if ( IsValidDlgItem( hWnd, g_ddx[ i ].cmdline ) )
 945: 			{
 946: 				VERIFY( SetDlgItemText( hWnd, g_ddx[ i ].cmdline, reg->cmdline ) );
 947: 			}
 948: 		}
 949: 	}}
 950: 
 951: 	return true;
 952: }//SetInstallDlgData
 953: 
 954: 
 955: //******************************************************************************************************************
 956: // private - init controls
 957: //******************************************************************************************************************
 958: //*********************************************************
 959: // InitInstallDlgControls
 960: //*********************************************************
 961: static
 962: bool
 963: InitInstallDlgControls
 964: 	(
 965: 		HWND  hWnd,
 966: 		DWORD more
 967: 	)
 968: {
 969: 	// パラメタの仮定
 970: 	ASSERT( IsValidWindow( hWnd ) );
 971: 
 972: 	//
 973: 	{for( int i = 0; i < numof( g_ddx ); ++i )
 974: 	{
 975: 		VERIFY( ShowDlgItemGroup( hWnd, g_ddx[ i ].id, 0 != (more & g_ddx[ i ].flag) ) );
 976: 	}}
 977: 
 978: 	// OnInstallSystemCommandUsePif(), OnInstallSystemCommandSetDefault() と重複している!
 979: 	// 関数名を考えよう!
 980: 	if ( g_dlg.ico )
 981: 	{
 982: 		VisibleDlgItem( hWnd, IDC_ICO,      true );
 983: 		VisibleDlgItem( hWnd, IDC_MORE_ICO, true );
 984: 	}
 985: 	else
 986: 	{
 987: 		VisibleDlgItem( hWnd, IDC_ICO,      false );
 988: 		VisibleDlgItem( hWnd, IDC_MORE_ICO, false );
 989: 
 990: 		if ( FLAG_ICO == (g_dlg.more & FLAG_ICO) )
 991: 		{
 992: 			g_dlg.more ^= FLAG_ICO;
 993: 			VERIFY( ShowDlgItemGroup( hWnd, ID_ICO, FLAG_ICO == (FLAG_ICO & g_dlg.more) ) );
 994: 		}
 995: 	}
 996: 
 997: 	return true;
 998: }//InitInstallDlgControls
 999: 
1000: 
1001: 
1002: //******************************************************************************************************************
1003: // TEST
1004: //******************************************************************************************************************
1005: 
1006: 
1007: #ifdef _DEBUG // デバッグ時のみ
1008: 
1009: 
1010: //*********************************************************
1011: // test_InstallDlg
1012: //*********************************************************
1013: DEFINE_TESTPROC( test_InstallDlg )
1014: {
1015: 	//---------------------------------------------------------
1016: 	// 定数 の テスト
1017: 	//---------------------------------------------------------
1018: 
1019: 	// g_offset の 重複
1020: 	{for( int i = 0; i < numof( g_offset ) - 1; ++i )
1021: 	{
1022: 		{for( int j = i+1; j < numof( g_offset ); ++j )
1023: 		{
1024: 			ASSERT( i != j );
1025: 			ASSERT( g_offset[ i ] != g_offset[ j ] );
1026: 		}}
1027: 	}}
1028: 
1029: 	// g_ddx の 範囲
1030: 	{for( int i = 0; i < numof( g_ddx ); ++i )
1031: 	{
1032: 		ASSERT( IS_VALID_ID( g_ddx[ i ].id ) );
1033: //		ASSERT( (0 <= g_ddx[i].id) && (g_ddx[i].id < numof( ((install_t *)null)->reg )) );
1034: 	}}
1035: 
1036: 	// g_ddx の 重複
1037: 	{for( int i = 0; i < numof( g_ddx ) - 1; ++i )
1038: 	{
1039: 		{for( int j = i+1; j < numof( g_ddx ); ++j )
1040: 		{
1041: 			ASSERT( i != j );
1042: 			ASSERT( g_ddx[ i ].id != g_ddx[ j ].id );
1043: 			ASSERT( 0 == (g_ddx[ i ].flag & g_ddx[ j ].flag) );
1044: 
1045: 			{for( int k = 0; k < numof( g_offset ); ++k )
1046: 			{
1047: 				const int ctrl_i = atoffset( int, &g_ddx[ i ], g_offset[ k ] );
1048: 				const int ctrl_j = atoffset( int, &g_ddx[ j ], g_offset[ k ] );
1049: 				ASSERT( ctrl_i != ctrl_j );
1050: 			}}
1051: 		}}
1052: 	}}
1053: 
1054: 
1055: 	//---------------------------------------------------------
1056: 	// ファイルスコープ関数 の テスト
1057: 	//---------------------------------------------------------
1058: 
1059: 	//---------------------------------------------------------
1060: 	// 公開関数 の テスト
1061: 	//---------------------------------------------------------
1062: 
1063: }//test_InstallDlg
1064: 
1065: 
1066: #endif // #ifdef _DEBUG
1067: 
1068: 
1069: //** end **

参照:


Google
ご意見・ご感想をお聞かせ下さい。匿名で送信できます。

 * 返信が必要な場合には postmaster@katsura-kotonoha.sakura.ne.jp へ直接メールしてください。

水無瀬の部屋 > sample > cur2cpp > instdlg.cpp

このページは cpp2web が出力しました。
水無瀬 優 postmaster@katsura-kotonoha.sakura.ne.jp
http://katsura-kotonoha.sakura.ne.jp/prog/code/cur2cpp/instdlg_cpp.shtml
『新妻LOVELY×CATION』を応援しています!