[PR]

水無瀬の部屋 > Programming > sample > exe2ico > instdlg.cpp
最終更新日: 2007/03/29

   1: //*********************************************************
   2: // プロジェクト: exe2ico
   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( EXE ),
  63: 		MAKE_DDX( DLL ),
  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_DLL == (FLAG_DLL & 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_EXE,           false, false, false, false  },
 343: 			{ IDC_MORE_EXE,      true,  false, false, false  },
 344: 			{ IDC_REGPATH_EXE,   false, false, true,  false  },
 345: 			{ IDC_MENUTITLE_EXE, false, false, true,  false  },
 346: 			{ IDC_CMDLINE_EXE,   false, false, true,  false  },
 347: 			{ IDC_GROUP_EXE,     false, false, true,  false  },
 348: //			{ IDC_DLL,           false, false, false, false  },
 349: 			{ IDC_MORE_DLL,      true,  false, false, false  },
 350: 			{ IDC_REGPATH_DLL,   false, false, true,  false  },
 351: 			{ IDC_MENUTITLE_DLL, false, false, true,  false  },
 352: 			{ IDC_CMDLINE_DLL,   false, false, true,  false  },
 353: 			{ IDC_GROUP_DLL,     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_DLL == (FLAG_DLL & g_dlg.info.flags)); 
 633: 
 634: 	// OnInstallSystemCommandUsePif(), InitInstallDlgControls() と重複している!
 635: 	// 関数名を考えよう!
 636: 	if ( g_dlg.ico )
 637: 	{
 638: 		VisibleDlgItem( hWnd, IDC_DLL,      true );
 639: 		VisibleDlgItem( hWnd, IDC_MORE_DLL, true );
 640: 	}
 641: 	else
 642: 	{
 643: 		VisibleDlgItem( hWnd, IDC_DLL,      false );
 644: 		VisibleDlgItem( hWnd, IDC_MORE_DLL, false );
 645: 
 646: 		if ( FLAG_DLL == (g_dlg.more & FLAG_DLL) )
 647: 		{
 648: 			g_dlg.more ^= FLAG_DLL;
 649: 			VERIFY( ShowDlgItemGroup( hWnd, ID_DLL, FLAG_DLL == (FLAG_DLL & g_dlg.more) ) );
 650: 		}
 651: 	}
 652: */
 653: 
 654: 	return true;
 655: }//OnInstallSystemCommandSetDefault
 656: 
 657: 
 658: //******************************************************************************************************************
 659: // private - init
 660: //******************************************************************************************************************
 661: //*********************************************************
 662: // InitInstallDlgSystemMenu
 663: //*********************************************************
 664: static
 665: bool
 666: InitInstallDlgSystemMenu
 667: 	(
 668: 		HWND hWnd
 669: 	)
 670: {
 671: 	// パラメタの仮定
 672: 	ASSERT( IsValidWindow( hWnd ) );
 673: 
 674: 	HMENU hmenuSystem = GetSystemMenu( hWnd, false );
 675: 	const int pos = GetMenuItemPos( hmenuSystem, SC_ZOOM );
 676: 	if ( 0 <= pos )
 677: 	{
 678: 		const struct 
 679: 			{
 680: 					  UINT  type;
 681: 					  UINT  id;
 682: 				const char *title;
 683: 			}
 684: 		item[] =
 685: 			{
 686: #define MAKE_MENUITEM( type, id, title ) { type, id, title }
 687: 				MAKE_MENUITEM( MF_SEPARATOR, 0,              null ),
 688: 				MAKE_MENUITEM( MF_STRING,    IDM_SETDEFAULT, "設定を初期値に戻す(&D)" ),
 689: 				MAKE_MENUITEM( MF_STRING,    IDM_ABOUT,      "About(&A)" ),
 690: #undef MAKE_MENUITEM
 691: 			};
 692: 		{for( int i = numof( item ); 0 < i; --i )
 693: 		{
 694: 			VERIFY( InsertMenu( hmenuSystem, pos+1, MF_BYPOSITION | item[ i-1 ].type, item[ i-1 ].id, item[ i-1 ].title ) );
 695: 	//		Menu_InsertSeparator( hmenuSystem, pos+1, MF_BYPOSITION );
 696: 		}}
 697: 	}
 698: 
 699: 	return true;
 700: }//InitInstallDlgSystemMenu
 701: 
 702: 
 703: //******************************************************************************************************************
 704: // private
 705: //******************************************************************************************************************
 706: static bool SetInstallDlgDataVerbList( HWND hwndListView, const char *verb );
 707: 
 708: 
 709: //*********************************************************
 710: // ShowDlgItemGroup
 711: //*********************************************************
 712: static
 713: bool
 714: ShowDlgItemGroup
 715: 	(
 716: 		HWND hWnd,
 717: 		id_t id,
 718: 		bool bShow
 719: 	)
 720: {
 721: 	// パラメタの仮定
 722: 	ASSERT( IsValidWindow( hWnd ) );
 723: 	ASSERT( IS_VALID_ID( id ) );
 724: 
 725: 	{for( int index = 0; index < numof( g_ddx ); ++index )
 726: 	{
 727: 		if ( id == g_ddx[ index ].id )
 728: 		{
 729: 			//
 730: 			SetDlgItemText( hWnd, g_ddx[ index ].more, bShow ? "<< 詳細" : "詳細 >>" );
 731: 
 732: 			//
 733: 			{for( int i = 0; i < numof( g_offset ); ++i )
 734: 			{
 735: 				const int ctrl = atoffset( int, &g_ddx[ index ], g_offset[ i ] );
 736: 				if ( (ctrl != g_ddx[ index ].check )
 737: 				  && (ctrl != g_ddx[ index ].more) )
 738: 				{
 739: 					if ( IsValidDlgItem( hWnd, ctrl ) )
 740: 					{
 741: 						VisibleDlgItem( hWnd, ctrl, bShow );
 742: 					}
 743: 				}
 744: 			}}
 745: 
 746: 			//
 747: 			const int sign = bShow ? 1 : -1;
 748: 			const int group_bottom = GetDlgItemBottom( hWnd, g_ddx[ index ].group );
 749: 			const int more_bottom  = GetDlgItemBottom( hWnd, g_ddx[ index ].more );
 750: 			const int height = sign * (group_bottom - more_bottom);
 751: 
 752: 			//
 753: 			{for( int i = 0; i < numof( g_ddx ); ++i )
 754: 			{
 755: 				if ( i != index )
 756: 				{
 757: 					if ( more_bottom < GetDlgItemTop( hWnd, g_ddx[ i ].group ) )
 758: 					{
 759: 						{for( int j = 0; j < numof( g_offset ); ++j )
 760: 						{
 761: 							const int ctrl = atoffset( int, &g_ddx[ i ], g_offset[ j ] );
 762: 							if ( IsValidDlgItem( hWnd, ctrl ) )
 763: 							{
 764: 								ShiftDlgItemPos( hWnd, ctrl, 0, height );
 765: 							}
 766: 						}}
 767: 					}
 768: 				}
 769: 			}}
 770: 
 771: 			//
 772: 			ShiftDlgItemPos( hWnd, IDOK,     0, height );
 773: 			ShiftDlgItemPos( hWnd, IDCANCEL, 0, height );
 774: 
 775: 			//
 776: 			g_dlg.szMinSize.cy += height;
 777: 			ShiftWindowSize( hWnd, 0, height );
 778: 		}
 779: 	}}
 780: 
 781: 	return true;
 782: }//ShowDlgItemGroup
 783: 
 784: //*********************************************************
 785: // EnableDlgItemGroup
 786: //*********************************************************
 787: static
 788: bool
 789: EnableDlgItemGroup
 790: 	(
 791: 		HWND hWnd,
 792: 		id_t id,
 793: 		bool bEnable
 794: 	)
 795: {
 796: 	// パラメタの仮定
 797: 	ASSERT( IsValidWindow( hWnd ) );
 798: 	ASSERT( IS_VALID_ID( id ) );
 799: 
 800: 	//
 801: 	{for( int index = 0; index < numof( g_ddx ); ++index )
 802: 	{
 803: 		if ( id == g_ddx[ index ].id )
 804: 		{
 805: 			{for( int i = 0; i < numof( g_offset ); ++i )
 806: 			{
 807: 				const int ctrl = atoffset( int, &g_ddx[ index ], g_offset[ i ] );
 808: 				if ( (ctrl != g_ddx[ index ].check )
 809: 				  && (ctrl != g_ddx[ index ].more) )
 810: 				{
 811: 					if ( IsValidDlgItem( hWnd, ctrl ) )
 812: 					{
 813: 						EnableDlgItem( hWnd, ctrl, bEnable );
 814: 					}
 815: 				}
 816: 			}}
 817: 		}
 818: 	}}
 819: 
 820: 	return true;
 821: }//EnableDlgItemGroup
 822: 
 823: //*********************************************************
 824: // GetInstallDlgData
 825: //*********************************************************
 826: static
 827: bool
 828: GetInstallDlgData
 829: 	(
 830: 		HWND       hWnd,
 831: 		install_t *info
 832: 	)
 833: {
 834: 	// パラメタの仮定
 835: 	ASSERT( IsValidWindow( hWnd ) );
 836: 	ASSERT( IsValidPtr( info, sizeof( *info ) ) );
 837: 	DESTROY_BUFFER( info, sizeof( *info ) ); // [破壊]
 838: 
 839: 	// 関連づけ
 840: 	info->flags = 0;
 841: 	{for( int i = 0; i < numof( g_ddx ); ++i )
 842: 	{
 843: 		// check
 844: 		if ( IsValidDlgItem( hWnd, g_ddx[ i ].check ) )
 845: 		{
 846: 			if ( BST_CHECKED == IsDlgButtonChecked( hWnd, g_ddx[ i ].check ) )
 847: 			{
 848: 				info->flags |= g_ddx[ i ].flag;
 849: 			}
 850: 		}
 851: 		
 852: 		//
 853: 		{
 854: 			ASSERT( IS_VALID_ID( g_ddx[ i ].id ) );
 855: 			const size_t index = ID_INDEX( g_ddx[ i ].id );
 856: 			ASSERT( IS_VALID_INDEX( index ) );
 857: 			relation_t *reg = &info->reg[ index ];
 858: 
 859: 			// default
 860: 			strcopy( reg->menu, numof(reg->menu), g_dlg.info.reg[ index ].menu );
 861: 			strcopy( reg->cmdline, numof(reg->cmdline), g_dlg.info.reg[ index ].cmdline );
 862: 			strcopy( reg->regpath, numof(reg->regpath), g_dlg.info.reg[ index ].regpath );
 863: 
 864: 			// regpath
 865: 			if ( IsValidDlgItem( hWnd, g_ddx[ i ].reg ) )
 866: 			{
 867: 				VERIFY( 0 <= GetDlgItemText( hWnd, g_ddx[ i ].reg, reg->regpath, numof( reg->regpath ) ) );
 868: 			}
 869: //			ASSERT( IsValidRegistryPathString( reg->regpath ) );
 870: 
 871: 			// menu
 872: 			if ( IsValidDlgItem( hWnd, g_ddx[ i ].menu ) )
 873: 			{
 874: 				VERIFY( 0 <= GetDlgItemText( hWnd, g_ddx[ i ].menu, reg->menu, numof( reg->menu ) ) );
 875: 			}
 876: 			ASSERT( IsValidStringPtr( reg->menu ) );
 877: 
 878: 			// cmdline
 879: 			if ( IsValidDlgItem( hWnd, g_ddx[ i ].cmdline ) )
 880: 			{
 881: 				VERIFY( 0 <= GetDlgItemText( hWnd, g_ddx[ i ].cmdline, reg->cmdline, numof( reg->cmdline ) ) );
 882: 			}
 883: 			ASSERT( IsValidCommandLineString( reg->cmdline ) );
 884: 		}
 885: 	}}
 886: 
 887: 	
 888: 	ASSERT( IsValidInstallInfo( info ) );
 889: 	return true;
 890: }//GetInstallDlgData
 891: 
 892: //*********************************************************
 893: // SetInstallDlgData
 894: //*********************************************************
 895: static
 896: bool
 897: SetInstallDlgData
 898: 	(
 899: 		      HWND       hWnd,
 900: 		const install_t *info
 901: 	)
 902: {
 903: 	// パラメタの仮定
 904: 	ASSERT( IsValidWindow( hWnd ) );
 905: 	ASSERT( IsValidInstallInfo( info ) );
 906: 
 907: 	// 
 908: 	{for( int i = 0; i < numof( g_ddx ); ++i )
 909: 	{
 910: 		// check
 911: 		const UINT uCheck = (g_ddx[ i ].flag == (info->flags & g_ddx[ i ].flag)) ? BST_CHECKED : BST_UNCHECKED;
 912: 		if ( ! IsValidDlgItem( hWnd, g_ddx[ i ].check ) )
 913: 		{
 914: 			EnableDlgItemGroup( hWnd, g_ddx[ i ].id, false );
 915: 		}
 916: 		else
 917: 		{
 918: 			EnableDlgItemGroup( hWnd, g_ddx[ i ].id, BST_CHECKED == uCheck );
 919: 			CheckDlgButton( hWnd, g_ddx[ i ].check, uCheck );
 920: 		}
 921: 
 922: 		//
 923: 		{
 924: 			ASSERT( IS_VALID_ID( g_ddx[ i ].id ) );
 925: 			const size_t index = ID_INDEX( g_ddx[ i ].id );
 926: 			ASSERT( IS_VALID_INDEX( index ) );
 927: 			const relation_t *reg = &info->reg[ index ];
 928: //			ASSERT( IsValidRegistryPathString( reg->regpath ) );
 929: 			ASSERT( IsValidCommandLineString( reg->cmdline ) );
 930: 			ASSERT( IsValidStringPtr( reg->menu ) );
 931: 
 932: 			// regpath
 933: 			if ( IsValidDlgItem( hWnd, g_ddx[ i ].reg ) )
 934: 			{
 935: 				VERIFY( SetDlgItemText( hWnd, g_ddx[ i ].reg, reg->regpath ) );
 936: 			}
 937: 
 938: 			// menu
 939: 			if ( IsValidDlgItem( hWnd, g_ddx[ i ].menu ) )
 940: 			{
 941: 				VERIFY( SetDlgItemText( hWnd, g_ddx[ i ].menu, reg->menu ) );
 942: 			}
 943: 
 944: 			// cmdline
 945: 			if ( IsValidDlgItem( hWnd, g_ddx[ i ].cmdline ) )
 946: 			{
 947: 				VERIFY( SetDlgItemText( hWnd, g_ddx[ i ].cmdline, reg->cmdline ) );
 948: 			}
 949: 		}
 950: 	}}
 951: 
 952: 	return true;
 953: }//SetInstallDlgData
 954: 
 955: 
 956: //******************************************************************************************************************
 957: // private - init controls
 958: //******************************************************************************************************************
 959: //*********************************************************
 960: // InitInstallDlgControls
 961: //*********************************************************
 962: static
 963: bool
 964: InitInstallDlgControls
 965: 	(
 966: 		HWND  hWnd,
 967: 		DWORD more
 968: 	)
 969: {
 970: 	// パラメタの仮定
 971: 	ASSERT( IsValidWindow( hWnd ) );
 972: 
 973: 	//
 974: 	{for( int i = 0; i < numof( g_ddx ); ++i )
 975: 	{
 976: 		VERIFY( ShowDlgItemGroup( hWnd, g_ddx[ i ].id, 0 != (more & g_ddx[ i ].flag) ) );
 977: 	}}
 978: /*
 979: 	// OnInstallSystemCommandUsePif(), OnInstallSystemCommandSetDefault() と重複している!
 980: 	// 関数名を考えよう!
 981: 	if ( g_dlg.ico )
 982: 	{
 983: 		VisibleDlgItem( hWnd, IDC_DLL,      true );
 984: 		VisibleDlgItem( hWnd, IDC_MORE_DLL, true );
 985: 	}
 986: 	else
 987: 	{
 988: 		VisibleDlgItem( hWnd, IDC_DLL,      false );
 989: 		VisibleDlgItem( hWnd, IDC_MORE_DLL, false );
 990: 
 991: 		if ( FLAG_DLL == (g_dlg.more & FLAG_DLL) )
 992: 		{
 993: 			g_dlg.more ^= FLAG_DLL;
 994: 			VERIFY( ShowDlgItemGroup( hWnd, ID_DLL, FLAG_DLL == (FLAG_DLL & g_dlg.more) ) );
 995: 		}
 996: 	}
 997: */
 998: 
 999: 	return true;
1000: }//InitInstallDlgControls
1001: 
1002: 
1003: 
1004: //******************************************************************************************************************
1005: // TEST
1006: //******************************************************************************************************************
1007: 
1008: 
1009: #ifdef _DEBUG // デバッグ時のみ
1010: 
1011: 
1012: //*********************************************************
1013: // test_InstallDlg
1014: //*********************************************************
1015: DEFINE_TESTPROC( test_InstallDlg )
1016: {
1017: 	//---------------------------------------------------------
1018: 	// 定数 の テスト
1019: 	//---------------------------------------------------------
1020: 
1021: 	// g_offset の 重複
1022: 	{for( int i = 0; i < numof( g_offset ) - 1; ++i )
1023: 	{
1024: 		{for( int j = i+1; j < numof( g_offset ); ++j )
1025: 		{
1026: 			ASSERT( i != j );
1027: 			ASSERT( g_offset[ i ] != g_offset[ j ] );
1028: 		}}
1029: 	}}
1030: 
1031: 	// g_ddx の 範囲
1032: 	{for( int i = 0; i < numof( g_ddx ); ++i )
1033: 	{
1034: 		ASSERT( IS_VALID_ID( g_ddx[ i ].id ) );
1035: //		ASSERT( (0 <= g_ddx[i].id) && (g_ddx[i].id < numof( ((install_t *)null)->reg )) );
1036: 	}}
1037: 
1038: 	// g_ddx の 重複
1039: 	{for( int i = 0; i < numof( g_ddx ) - 1; ++i )
1040: 	{
1041: 		{for( int j = i+1; j < numof( g_ddx ); ++j )
1042: 		{
1043: 			ASSERT( i != j );
1044: 			ASSERT( g_ddx[ i ].id != g_ddx[ j ].id );
1045: 			ASSERT( 0 == (g_ddx[ i ].flag & g_ddx[ j ].flag) );
1046: 
1047: 			{for( int k = 0; k < numof( g_offset ); ++k )
1048: 			{
1049: 				const int ctrl_i = atoffset( int, &g_ddx[ i ], g_offset[ k ] );
1050: 				const int ctrl_j = atoffset( int, &g_ddx[ j ], g_offset[ k ] );
1051: 				ASSERT( ctrl_i != ctrl_j );
1052: 			}}
1053: 		}}
1054: 	}}
1055: 
1056: 
1057: 	//---------------------------------------------------------
1058: 	// ファイルスコープ関数 の テスト
1059: 	//---------------------------------------------------------
1060: 
1061: 	//---------------------------------------------------------
1062: 	// 公開関数 の テスト
1063: 	//---------------------------------------------------------
1064: 
1065: }//test_InstallDlg
1066: 
1067: 
1068: #endif // #ifdef _DEBUG
1069: 
1070: 
1071: //** end **

参照:


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

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

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

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