[PR]

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

   1: //*********************************************************
   2: // プロジェクト: TOOLS
   3: //  ファイル名: toolctrl.cpp
   4: //*********************************************************
   5: #include <header/toolctrl.h>
   6: #include <header/tooldbg.h>
   7: #include <header/snprintf.h>  //
   8: #include <header/toolbase.h>        // 
   9: #include <header/toolwind.h>
  10: #include <header/toolsys.h>  //
  11: #include <limits.h>
  12: 
  13: 
  14: //------------------------------------------------------------------------------------------------------------------
  15: // Accelerator
  16: //------------------------------------------------------------------------------------------------------------------
  17: 
  18: 
  19: //*********************************************************
  20: // GetAcceleratorCount
  21: // ハンドル hAccel が含む ACCEL の数を返す
  22: //*********************************************************
  23: int
  24: GetAcceleratorCount
  25: 	(
  26: 		HACCEL hAccel
  27: 	)
  28: {
  29: 	// パラメタの仮定
  30: 	ASSERT( hAccel );
  31: 
  32: 	return CopyAcceleratorTable( hAccel, null, 0 );
  33: }//GetAcceleratorCount
  34: 
  35: //*********************************************************
  36: // LoadAcceleratorTable
  37: // リソースからアクセラレータ配列 ACCEL[] をロードする
  38: // ロードした配列は使用後に関数 free() で解放する
  39: //*********************************************************
  40: ACCEL *
  41: LoadAcceleratorTable
  42: 	(
  43: 		HINSTANCE   hInstance,
  44: 		const char *name,
  45: 		int        *num
  46: 	)
  47: {
  48: 	// パラメタの仮定
  49: 	ASSERT( IsValidInstanceHandle( hInstance ) );
  50: 	ASSERT( IsValidResourceName( name ) );
  51: 	ASSERT( IsValidPtr( num, sizeof( *num ) ) );
  52: 
  53: 	// 
  54: 	*num = 0;
  55: 
  56: 	// リソースからアクセラレータをロードする
  57: 	// ロードされたアクセラレータは自動的に解放される
  58: 	HACCEL hAccel = LoadAccelerators( hInstance, name );
  59: 	if ( !hAccel )
  60: 		return null; // アクセラレータのロードに失敗
  61: 
  62: 	// 項目数を取得
  63: 	const int count = GetAcceleratorCount( hAccel );
  64: 	if ( count <= 0 )
  65: 		return null; // 終了
  66: 
  67: 	// 領域の確保
  68: 	ACCEL *acc = (ACCEL *)malloc( count * sizeof( *acc ) );
  69: 	if ( !acc )
  70: 		return null; // 領域の確保に失敗
  71: 
  72: 	// 確保した領域に ACCEL を複写
  73: 	*num = CopyAcceleratorTable( hAccel, acc, count );
  74: 	ASSERT( count == *num );
  75: 	return acc;
  76: }//LoadAcceleratorTable
  77: 
  78: 
  79: //------------------------------------------------------------------------------------------------------------------
  80: // Button
  81: //------------------------------------------------------------------------------------------------------------------
  82: 
  83: 
  84: //*********************************************************
  85: // IsDlgItemButtonControl
  86: //*********************************************************
  87: bool
  88: IsDlgItemButtonControl
  89: 	(
  90: 		HWND hwndDlg,
  91: 		int  nID
  92: 	)
  93: {
  94: 	VALID_TEST( IsValidWindow( hwndDlg ) );
  95: 
  96: 	HWND hwndButton = GetDlgItem( hwndDlg, nID );
  97: 	VALID_TEST( IsWindowButtonControl( hwndButton ) );
  98: 
  99: 	return true;
 100: }//IsDlgItemButtonControl
 101: 
 102: //*********************************************************
 103: // IsWindowButtonControl
 104: //*********************************************************
 105: bool
 106: IsWindowButtonControl
 107: 	(
 108: 		HWND hwndButton
 109: 	)
 110: {
 111: 	VALID_TEST( IsValidWindow( hwndButton ) );
 112: 	VALID_TEST( IsClassNameWindow( hwndButton, "Button" ) );
 113: 
 114: 	return true;
 115: }//IsWindowButtonControl
 116: 
 117: 
 118: //------------------------------------------------------------------------------------------------------------------
 119: // ComboBox
 120: //------------------------------------------------------------------------------------------------------------------
 121: 
 122: 
 123: //*********************************************************
 124: // ComboBox_GetCurSelItemData()
 125: //   現在選択されている項目に関連づけられた 32 bit 値を取得する。
 126: //   値の取得に失敗すると CB_ERR を返す。
 127: //
 128: // HWND hwndCombo
 129: //   コントロールへのハンドル
 130: //
 131: // [疑問]
 132: //   選択されていない場合は?
 133: //
 134: //*********************************************************
 135: LPARAM // 現在選択されている項目に関連づけられた 32 bit 値
 136: ComboBox_GetCurSelItemData
 137: 	(
 138: 		HWND hwndCombo
 139: 	)
 140: {
 141: 	// パラメタの仮定
 142: 	ASSERT( IsWindowComboBoxControl( hwndCombo ) );
 143: 	
 144: 	const int cursel = ComboBox_GetCurSel( hwndCombo );
 145: 	return ComboBox_GetItemData( hwndCombo, cursel );
 146: }//ComboBox_GetCurSelItemData
 147: 
 148: //*********************************************************
 149: // ComboBox_GetCurSelTextLength()
 150: //  現在選択されている項目の文字列長を取得する。
 151: //   文字列長の取得に失敗すると CB_ERR を返す。
 152: //
 153: // HWND hwndCombo
 154: //   コントロールへのハンドル
 155: //
 156: //*********************************************************
 157: int // 現在選択されている項目の文字列長
 158: ComboBox_GetCurSelTextLength
 159: 	(
 160: 		HWND hwndCombo
 161: 	)
 162: {
 163: 	// パラメタの仮定
 164: 	ASSERT( IsWindowComboBoxControl( hwndCombo ) );
 165: 	
 166: 	const int cursel = ComboBox_GetCurSel( hwndCombo );
 167: 	return ComboBox_GetLBTextLen( hwndCombo, cursel );
 168: }//ComboBox_GetCurSelTextLength
 169: 
 170: //*********************************************************
 171: // IsDlgItemComboBoxControl
 172: //*********************************************************
 173: bool
 174: IsDlgItemComboBoxControl
 175: 	(
 176: 		HWND hwndDlg,
 177: 		int  nID
 178: 	)
 179: {
 180: 	VALID_TEST( IsValidWindow( hwndDlg ) );
 181: 
 182: 	HWND hwndCombo = GetDlgItem( hwndDlg, nID );
 183: 	VALID_TEST( IsWindowComboBoxControl( hwndCombo ) );
 184: 
 185: 	return true;
 186: }//IsDlgItemComboBoxControl
 187: 
 188: //*********************************************************
 189: // IsWindowComboBoxControl()
 190: //  コンボボックスであれば 真 を返す。
 191: //
 192: // HWND hwndCombo
 193: //   コントロールへのハンドル
 194: //
 195: //*********************************************************
 196: bool // コンボボックスであれば 真
 197: IsWindowComboBoxControl
 198: 	(
 199: 		HWND hwndCombo
 200: 	)
 201: {
 202: 	VALID_TEST( IsValidWindow( hwndCombo ) );
 203: 	VALID_TEST( IsClassNameWindow( hwndCombo, "ComboBox" ) );
 204: 
 205: 	return true;
 206: }//IsWindowComboBoxControl
 207: 
 208: 
 209: //------------------------------------------------------------------------------------------------------------------
 210: // Edit
 211: //------------------------------------------------------------------------------------------------------------------
 212: 
 213: 
 214: //*********************************************************
 215: // Edit_AddText
 216: //*********************************************************
 217: void
 218: Edit_AddText
 219: 	(
 220: 		HWND        hwndEdit,
 221: 		const char *string
 222: 	)
 223: {
 224: 	// パラメタの仮定
 225: 	ASSERT( IsWindowEditControl( hwndEdit ) );
 226: 	ASSERT( IsValidStringPtr( string )  );
 227: 
 228: 	// 選択範囲の保存
 229: 	int nSelStart, nSelEnd;
 230: 	SendMessage( hwndEdit, EM_GETSEL,
 231: 		reinterpret_cast<WPARAM>( &nSelStart ), reinterpret_cast<LPARAM>( &nSelEnd ) );
 232: 
 233: 	// 末尾に挿入
 234: 	const int length = GetWindowTextLength( hwndEdit );
 235: 	Edit_SetSel( hwndEdit, length, length );
 236: 	Edit_ReplaceSelText( hwndEdit, string );
 237: 
 238: 	// 選択範囲の復元
 239: 	Edit_SetSel( hwndEdit, nSelStart, nSelEnd );
 240: }//Edit_AddText
 241: 
 242: //*********************************************************
 243: // Edit_AllocText
 244: //*********************************************************
 245: char *
 246: Edit_AllocText
 247: 	(
 248: 		HWND hwndEdit
 249: 	)
 250: {
 251: 	// パラメタの仮定
 252: 	ASSERT( IsWindowEditControl( hwndEdit ) );
 253: 
 254: 	const int length = Edit_GetTextLength( hwndEdit );
 255: 	char *string = (char *)malloc( (1 + length) * sizeof( *string ) );
 256: 	if ( !string )
 257: 		return null; // 領域の確保に失敗
 258: 
 259: 	Edit_GetText( hwndEdit, string, 1 + length );
 260: 
 261: 	ASSERT( IsValidStringPtr( string )  );
 262: 	ASSERT( (size_t)length == strlen(string) );
 263: 	return string;
 264: }//Edit_AllocText
 265: 
 266: //*********************************************************
 267: // Edit_GetSelLength
 268: //*********************************************************
 269: int
 270: Edit_GetSelLength
 271: 	(
 272: 		HWND hwndEdit
 273: 	)
 274: {
 275: 	// パラメタの仮定
 276: 	ASSERT( IsWindowEditControl( hwndEdit ) );
 277: 
 278: 	const DWORD dwSel = Edit_GetSel( hwndEdit );
 279: 	const WORD wStart = LOWORD(dwSel);
 280: 	const WORD wStop  = HIWORD(dwSel);
 281: 
 282: 	ASSERT( wStart <= wStop );
 283: 	return wStop - wStart;
 284: }//Edit_GetSelLength
 285: 
 286: //*********************************************************
 287: // Edit_GetSelStart
 288: //*********************************************************
 289: WORD
 290: Edit_GetSelStart
 291: 	(
 292: 		HWND hwndEdit
 293: 	)
 294: {
 295: 	// パラメタの仮定
 296: 	ASSERT( IsWindowEditControl( hwndEdit ) );
 297: 
 298: 	DWORD dwSel = Edit_GetSel( hwndEdit );
 299: 	ASSERT( LOWORD(dwSel) <= HIWORD(dwSel) );
 300: 
 301: 	return LOWORD(dwSel);
 302: }//Edit_GetSelStart
 303: 
 304: //*********************************************************
 305: // Edit_IsAllSelected
 306: //*********************************************************
 307: bool
 308: Edit_IsAllSelected
 309: 	(
 310: 		HWND hwndEdit
 311: 	)
 312: {
 313: 	// パラメタの仮定
 314: 	ASSERT( IsWindowEditControl( hwndEdit ) );
 315: 
 316: 	return Edit_GetSelLength( hwndEdit ) != Edit_GetTextLength( hwndEdit );
 317: }//Edit_IsAllSelected
 318: 
 319: //*********************************************************
 320: // Edit_ReplaceSelText
 321: //*********************************************************
 322: void
 323: Edit_ReplaceSelText
 324: 	(
 325: 		HWND        hwndEdit,
 326: 		const char *string
 327: 	)
 328: {
 329: 	// パラメタの仮定
 330: 	ASSERT( IsWindowEditControl( hwndEdit ) );
 331: 	ASSERT( IsValidStringPtr( string )  );
 332: 
 333: 	const WORD wStart = Edit_GetSelStart( hwndEdit );
 334: 	SendMessage( hwndEdit, EM_REPLACESEL, true, reinterpret_cast<LPARAM>( string ) );
 335: 	Edit_SetSel( hwndEdit, wStart, wStart + strlen(string) );
 336: }//Edit_ReplaceSelText
 337: 
 338: //*********************************************************
 339: // IsDlgItemEditControl
 340: //*********************************************************
 341: bool
 342: IsDlgItemEditControl
 343: 	(
 344: 		HWND hwndDlg,
 345: 		int  nID
 346: 	)
 347: {
 348: 	VALID_TEST( IsValidWindow( hwndDlg ) );
 349: 
 350: 	HWND hwndEdit = GetDlgItem( hwndDlg, nID );
 351: 	VALID_TEST( IsWindowEditControl( hwndEdit ) );
 352: 
 353: 	return true;
 354: }//IsDlgItemEditControl
 355: 
 356: //*********************************************************
 357: // IsWindowEditControl
 358: //*********************************************************
 359: bool
 360: IsWindowEditControl
 361: 	(
 362: 		HWND hwndEdit
 363: 	)
 364: {
 365: 	VALID_TEST( IsValidWindow( hwndEdit ) );
 366: 	VALID_TEST( IsClassNameWindow( hwndEdit, "Edit" ) );
 367: 
 368: 	return true;
 369: }//IsWindowEditControl
 370: 
 371: 
 372: //------------------------------------------------------------------------------------------------------------------
 373: // Header
 374: //------------------------------------------------------------------------------------------------------------------
 375: 
 376: 
 377: //*********************************************************
 378: // Header_HitTest
 379: //   HHT_ONDIVIDER, HHT_ONDIVOPEN, HHT_ONHEADER, etc...  
 380: //*********************************************************
 381: LRESULT
 382: Header_HitTest
 383: 	(
 384: 		HWND  hwndHeader,
 385: 		UINT  flags,
 386: 		POINT pt
 387: 	)
 388: {
 389: 	// パラメタの仮定
 390: 	ASSERT( IsWindowHeaderControl( hwndHeader ) );
 391: 
 392: 	HDHITTESTINFO hht;
 393: 	memzero( &hht, sizeof( hht ) );
 394: 	hht.pt    = pt;
 395: 	hht.flags = flags;
 396: 
 397: 	return SendMessage( hwndHeader, HDM_HITTEST, 0, reinterpret_cast<LPARAM>( &hht ) );
 398: }//Header_HitTest
 399: 
 400: //*********************************************************
 401: // IsDlgItemHeaderControl
 402: //*********************************************************
 403: bool
 404: IsDlgItemHeaderControl
 405: 	(
 406: 		HWND hwndDlg,
 407: 		int  nID
 408: 	)
 409: {
 410: 	VALID_TEST( IsValidWindow( hwndDlg ) );
 411: 
 412: 	HWND hwndHeader = GetDlgItem( hwndDlg, nID );
 413: 	VALID_TEST( IsWindowHeaderControl( hwndHeader ) );
 414: 
 415: 	return true;
 416: }//IsDlgItemHeaderControl
 417: 
 418: //*********************************************************
 419: // IsWindowHeaderControl
 420: //*********************************************************
 421: bool
 422: IsWindowHeaderControl
 423: 	(
 424: 		HWND hwndHeader
 425: 	)
 426: {
 427: 	VALID_TEST( IsValidWindow( hwndHeader ) );
 428: 	VALID_TEST( IsClassNameWindow( hwndHeader, WC_HEADER ) );
 429: 
 430: 	return true;
 431: }//IsWindowHeaderControl
 432: 
 433: 
 434: //------------------------------------------------------------------------------------------------------------------
 435: // Hotkey
 436: //------------------------------------------------------------------------------------------------------------------
 437: 
 438: 
 439: //*********************************************************
 440: // Hotkey_GetHotkey
 441: //*********************************************************
 442: DWORD
 443: Hotkey_GetHotkey
 444: 	(
 445: 		HWND hwndHotkey
 446: 	)
 447: {
 448: 	// パラメタの仮定
 449: 	ASSERT( IsWindowHotkeyControl( hwndHotkey ) );
 450: 
 451: 	return (DWORD)SendMessage( hwndHotkey, HKM_GETHOTKEY, 0, 0 );
 452: }//Hotkey_GetHotkey
 453: 
 454: //*********************************************************
 455: // Hotkey_SetHotkey
 456: //*********************************************************
 457: void
 458: Hotkey_SetHotkey
 459: 	(
 460: 		HWND   hwndHotkey,
 461: 		WPARAM wHotkey
 462: 	)
 463: {
 464: 	// パラメタの仮定
 465: 	ASSERT( IsWindowHotkeyControl( hwndHotkey ) );
 466: 	ASSERT( HIBYTE( wHotkey ) ==
 467: 		( HIBYTE( wHotkey ) & (HOTKEYF_ALT | HOTKEYF_CONTROL | HOTKEYF_SHIFT | HOTKEYF_EXT) ) );
 468: 
 469: 	SendMessage( hwndHotkey, HKM_SETHOTKEY, wHotkey, 0 );
 470: }//Hotkey_SetHotkey
 471: 
 472: //*********************************************************
 473: // Hotkey_SetRules
 474: // ホットキーコントロールに修飾キーの禁止組合せとデフォルトの組合せを指定する。
 475: //
 476: // wRules
 477: //   HKCOMB_A, HKCOMB_C, HKCOMB_CA, HKCOMB_NONE, HKCOMB_S, HKCOMB_SA, HKCOMB_SC, HKCOMB_SCA, etc...
 478: //
 479: // lDefault
 480: //   MAKELPARAM(fwModInv, 0); 
 481: //
 482: //*********************************************************
 483: void
 484: Hotkey_SetRules
 485: 	(
 486: 		HWND   hwndHotkey, //
 487: 		WPARAM wRules,     // 修飾キーの禁止組合せ
 488: 		LPARAM lDefault    // デフォルトの修飾キー
 489: 	)
 490: {
 491: 	// パラメタの仮定
 492: 	ASSERT( IsWindowHotkeyControl( hwndHotkey ) );
 493: 
 494: 	SendMessage( hwndHotkey, HKM_SETRULES, wRules, lDefault );
 495: }//Hotkey_SetRules
 496: 
 497: //*********************************************************
 498: // IsDlgItemHotkeyControl
 499: //*********************************************************
 500: bool
 501: IsDlgItemHotkeyControl
 502: 	(
 503: 		HWND hwndDlg,
 504: 		int  nID
 505: 	)
 506: {
 507: 	VALID_TEST( IsValidWindow( hwndDlg ) );
 508: 
 509: 	HWND hwndHotkey = GetDlgItem( hwndDlg, nID );
 510: 	VALID_TEST( IsWindowHotkeyControl( hwndHotkey ) );
 511: 
 512: 	return true;
 513: }//IsDlgItemHotkeyControl
 514: 
 515: //*********************************************************
 516: // IsWindowHotkeyControl
 517: //*********************************************************
 518: bool
 519: IsWindowHotkeyControl
 520: 	(
 521: 		HWND hwndHotkey
 522: 	)
 523: {
 524: 	VALID_TEST( IsValidWindow( hwndHotkey ) );
 525: 	VALID_TEST( IsClassNameWindow( hwndHotkey, HOTKEY_CLASS ) );
 526: 
 527: 	return true;
 528: }//IsWindowHotkeyControl
 529: 
 530: 
 531: //------------------------------------------------------------------------------------------------------------------
 532: // ListBox
 533: //------------------------------------------------------------------------------------------------------------------
 534: 
 535: 
 536: //*********************************************************
 537: // IsDlgItemListBoxControl
 538: //*********************************************************
 539: bool
 540: IsDlgItemListBoxControl
 541: 	(
 542: 		HWND hwndDlg,
 543: 		int  nID
 544: 	)
 545: {
 546: 	VALID_TEST( IsValidWindow( hwndDlg ) );
 547: 
 548: 	HWND hListBox = GetDlgItem( hwndDlg, nID );
 549: 	VALID_TEST( IsWindowListBoxControl( hListBox ) );
 550: 
 551: 	return true;
 552: }//IsDlgItemListBoxControl
 553: 
 554: //*********************************************************
 555: // IsWindowListBoxControl
 556: //*********************************************************
 557: bool
 558: IsWindowListBoxControl
 559: 	(
 560: 		HWND hListBox
 561: 	)
 562: {
 563: 	VALID_TEST( IsValidWindow( hListBox ) );
 564: 	VALID_TEST( IsClassNameWindow( hListBox, "ListBox" ) );
 565: 
 566: 	return true;
 567: }//IsWindowListBoxControl
 568: 
 569: //*********************************************************
 570: // ListBox_AddItem
 571: //*********************************************************
 572: int
 573: ListBox_AddItem
 574: 	(
 575: 		HWND        hListBox,
 576: 		const char *string,
 577: 		LPARAM      lParam
 578: 	)
 579: {
 580: 	// パラメタの仮定
 581: 	ASSERT( IsWindowListBoxControl( hListBox ) );
 582: 	ASSERT( IsValidStringPtr( string ) );
 583: 
 584: 	const int nIndex = ListBox_AddString( hListBox, string );
 585: 	if ( lParam && (LB_ERR != nIndex) )
 586: 		VERIFY( LB_ERR != ListBox_SetItemData( hListBox, nIndex, lParam ) );
 587: 
 588: 	return nIndex;
 589: }//ListBox_AddItem
 590: 
 591: //*********************************************************
 592: // ListBox_InitStorage
 593: //*********************************************************
 594: LRESULT
 595: ListBox_InitStorage
 596: 	(
 597: 		HWND  hListBox,
 598: 		int   nItems,
 599: 		DWORD dwSize
 600: 	)
 601: {
 602: 	// パラメタの仮定
 603: 	ASSERT( IsWindowListBoxControl( hListBox ) );
 604: 	ASSERT( 0 < nItems );
 605: 	ASSERT( 0 < dwSize );
 606: 
 607: 	return SendMessage( hListBox, LB_INITSTORAGE, nItems, dwSize );
 608: }//ListBox_InitStorage
 609: 
 610: //*********************************************************
 611: // ListBox_InsertItem
 612: //*********************************************************
 613: int
 614: ListBox_InsertItem
 615: 	(
 616: 		HWND        hListBox, 
 617: 		int         index,
 618: 		const char *string,
 619: 		LPARAM      lParam
 620: 	)
 621: {
 622: 	// パラメタの仮定
 623: 	ASSERT( IsWindowListBoxControl( hListBox ) );
 624: 	ASSERT( (0 <= index) && (index <= ListBox_GetCount( hListBox )) );
 625: 	ASSERT( IsValidStringPtr( string ) );
 626: 
 627: 	index = ListBox_InsertString( hListBox, index, string );
 628: 	if ( lParam && (LB_ERR != index) )
 629: 		VERIFY( LB_ERR != ListBox_SetItemData( hListBox, index, lParam ) );
 630: 
 631: 	return index;
 632: }//ListBox_InsertItem
 633: 
 634: //*********************************************************
 635: // ListBox_IsValidIndex
 636: //*********************************************************
 637: bool
 638: ListBox_IsValidIndex
 639: 	(
 640: 		HWND hListBox,
 641: 		int  index
 642: 	)
 643: {
 644: 	// パラメタの仮定
 645: 	ASSERT( IsWindowListBoxControl( hListBox ) );
 646: 
 647: 	const int count = ListBox_GetCount( hListBox );
 648: 	return (0 <= index) && (index < count);
 649: }//ListBox_IsValidIndex
 650: 
 651: //*********************************************************
 652: // ListBox_MoveItem
 653: //*********************************************************
 654: int
 655: ListBox_MoveItem
 656: 	(
 657: 		HWND hListBox,
 658: 		int  to, 
 659: 		int  from
 660: 	)
 661: {
 662: 	// パラメタの仮定
 663: 	ASSERT( IsWindowListBoxControl( hListBox ) );
 664: 	ASSERT( ListBox_IsValidIndex( hListBox, from ) );
 665: 	ASSERT( (0 <= to) && (to <= ListBox_GetCount( hListBox )) );
 666: 	ASSERT( to != from );
 667: 
 668: 	// 移動元項目の情報を取得
 669: 	const int length = ListBox_GetTextLen( hListBox, from );
 670: 	char *buffer = (char *)malloc( (1 + length) * sizeof( buffer ) );
 671: 	if ( !buffer ) 
 672: 		return LB_ERR;
 673: 	VERIFY( LB_ERR != ListBox_GetText( hListBox, from, buffer ) );
 674: 	const LRESULT data = ListBox_GetItemData( hListBox, from );
 675: 
 676: 	// 移動元項目を削除
 677: 	VERIFY( LB_ERR != ListBox_DeleteString( hListBox, from ) );
 678: 	if ( from < to )
 679: 	{
 680: 		--to;
 681: 	}
 682: 
 683: 	// 移動先に複製を作成
 684: 	VERIFY( to == ListBox_InsertItem( hListBox, to, buffer, data ) );
 685: 	free( buffer );
 686: 	return to;
 687: }//ListBox_MoveItem
 688: 
 689: 
 690: //------------------------------------------------------------------------------------------------------------------
 691: // ListView
 692: //------------------------------------------------------------------------------------------------------------------
 693: 
 694: 
 695: //*********************************************************
 696: // IsDlgItemListViewControl
 697: //*********************************************************
 698: bool
 699: IsDlgItemListViewControl
 700: 	(
 701: 		HWND hwndDlg,
 702: 		int  nID
 703: 	)
 704: {
 705: 	VALID_TEST( IsValidWindow( hwndDlg ) );
 706: 
 707: 	HWND hListView = GetDlgItem( hwndDlg, nID );
 708: 	VALID_TEST( IsWindowListViewControl( hListView ) );
 709: 
 710: 	return true;
 711: }//IsDlgItemListViewControl
 712: 
 713: //*********************************************************
 714: // IsWindowListViewControl
 715: //*********************************************************
 716: bool
 717: IsWindowListViewControl
 718: 	(
 719: 		HWND hListView
 720: 	)
 721: {
 722: 	VALID_TEST( IsValidWindow( hListView ) );
 723: 	VALID_TEST( IsClassNameWindow( hListView, WC_LISTVIEW ) );
 724: 
 725: 	return true;
 726: }//IsWindowListViewControl
 727: 
 728: //*********************************************************
 729: // ListView_AddIconImage
 730: //*********************************************************
 731: int
 732: ListView_AddIconImage
 733: 	(
 734: 		HWND  hListView,
 735: 		int   nImageListType,
 736: 		HICON hIcon
 737: 	)
 738: {
 739: 	// パラメタの仮定
 740: 	ASSERT( IsWindowListViewControl( hListView ) );
 741: 	ASSERT(  ( LVSIL_NORMAL == nImageListType )
 742: 	      || ( LVSIL_SMALL  == nImageListType )
 743: 	      || ( LVSIL_STATE  == nImageListType ) );
 744: 	ASSERT( IsValidIconHandle( hIcon ) );
 745: 
 746: 	HIMAGELIST hImageList = ListView_GetImageList( hListView, nImageListType );
 747: 	if ( !hImageList )
 748: 		return -1;
 749: 
 750: 	ASSERT( hImageList );
 751: 	return ImageList_AddIcon( hImageList, hIcon );
 752: }//ListView_AddIconImage
 753: 
 754: //*********************************************************
 755: // ListView_DestroyImageList
 756: //*********************************************************
 757: bool
 758: ListView_DestroyImageList
 759: 	(
 760: 		HWND hListView,
 761: 		int  nImageListType
 762: 	)
 763: {
 764: 	// パラメタの仮定
 765: 	ASSERT( IsWindowListViewControl( hListView ) );
 766: 	ASSERT(  ( LVSIL_NORMAL == nImageListType )
 767: 	      || ( LVSIL_SMALL  == nImageListType )
 768: 	      || ( LVSIL_STATE  == nImageListType ) );
 769: 
 770: 	HIMAGELIST hImageList = ListView_GetImageList( hListView, nImageListType );
 771: 	if ( !hImageList )
 772: 		return false;
 773: 
 774: 	ASSERT( hImageList );
 775: 	return !! ImageList_Destroy( hImageList );
 776: }//ListView_DestroyImageList
 777: 
 778: //*********************************************************
 779: // ListView_GetCursorItem
 780: //*********************************************************
 781: int
 782: ListView_GetCursorItem
 783: 	(
 784: 		HWND hListView
 785: 	)
 786: {
 787: 	// パラメタの仮定
 788: 	ASSERT( IsWindowListViewControl( hListView ) );
 789: 
 790: 	POINT pt; 
 791: 	VERIFY( GetClientCursorPos( hListView, &pt ) );
 792: 	
 793: 	LVHITTESTINFO lvhi;
 794: 	memzero( &lvhi, sizeof( lvhi ) );
 795: 	lvhi.pt    = pt;
 796: 	lvhi.flags = LVHT_ONITEM;
 797: 	return ListView_HitTest( hListView, &lvhi );
 798: }//ListView_GetCursorItem
 799: 
 800: //*********************************************************
 801: // ListView_GetItemParam
 802: //*********************************************************
 803: LPARAM
 804: ListView_GetItemParam
 805: 	(
 806: 		HWND hListView,
 807: 		int  index,
 808: 		int  nSubItem
 809: 	)
 810: {
 811: 	// パラメタの仮定
 812: 	ASSERT( IsWindowListViewControl( hListView ) );
 813: 	ASSERT( ListView_IsValidIndex( hListView, index ) );
 814: 	ASSERT( 0 == nSubItem );
 815: 	
 816: 	LVITEM lvi;
 817: 	memzero( &lvi, sizeof( lvi ) );
 818: 	lvi.mask     = LVIF_PARAM;
 819: 	lvi.iItem    = index;
 820: 	lvi.iSubItem = nSubItem;
 821: 	ListView_GetItem( hListView, &lvi );
 822: 	return lvi.lParam;
 823: }//ListView_GetItemParam
 824: 
 825: //*********************************************************
 826: // ListView_InsertNewColumn
 827: //   hListView の nIndex 列目の直後に、幅 nWidth, タイトル string な列を挿入する。
 828: //   mask …… LVCF_FMT...
 829: //   fmt  …… LVCFMT_LEFT...
 830: //*********************************************************
 831: int
 832: ListView_InsertNewColumn
 833: 	(
 834: 		HWND  hListView,
 835: 		int   nIndex,
 836: 		UINT  mask,
 837: 		int   fmt,
 838: 		int   nWidth,
 839: 		char *string
 840: 	)
 841: {
 842: 	// パラメタの仮定
 843: 	ASSERT( IsWindowListViewControl( hListView ) );
 844: 	ASSERT( 0 <= nIndex );
 845: 	ASSERT( 0 < nWidth );
 846: 	ASSERT( IsValidStringPtr( string ) );
 847: 
 848: 	LVCOLUMN lvc;
 849: 	memzero( &lvc, sizeof( lvc ) );
 850: 	lvc.mask     = mask | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
 851: 	lvc.fmt      = fmt;
 852: 	lvc.iSubItem = nIndex;
 853: 	lvc.cx       = nWidth;
 854: 	lvc.pszText  = string;
 855: 	return ListView_InsertColumn( hListView, nIndex, &lvc );
 856: }//ListView_InsertNewColumn
 857: 
 858: //*********************************************************
 859: // ListView_IsValidIndex
 860: //*********************************************************
 861: bool
 862: ListView_IsValidIndex
 863: 	(
 864: 		HWND hListView,
 865: 		int  index
 866: 	)
 867: {
 868: 	// パラメタの仮定
 869: 	ASSERT( IsWindowListViewControl( hListView ) );
 870: 
 871: 	const int count = ListView_GetItemCount( hListView );
 872: 	return (0 <= index) && (index < count);
 873: }//ListView_IsValidIndex
 874: 
 875: //*********************************************************
 876: // ListView_SetExtendedStyle
 877: //   dwSetStyle …… LVS_EX_HEADERDRAGDROP, LVS_EX_FULLROWSELECT, etc...
 878: //*********************************************************
 879: DWORD
 880: ListView_SetExtendedStyle
 881: 	(
 882: 		HWND  hListView,
 883: 		DWORD dwSetStyle
 884: 	)
 885: {
 886: 	// パラメタの仮定
 887: 	ASSERT( IsWindowListViewControl( hListView ) );
 888: 
 889: 	DWORD dwStyle;
 890: 	dwStyle = ListView_GetExtendedListViewStyle( hListView );
 891: 	dwStyle = dwStyle | dwSetStyle;
 892: 	return ListView_SetExtendedListViewStyle( hListView, dwStyle );
 893: }//ListView_SetExtendedStyle
 894: 
 895: //*********************************************************
 896: // ListView_SetItemParam
 897: //*********************************************************
 898: bool
 899: ListView_SetItemParam
 900: 	(
 901: 		HWND   hListView,
 902: 		int    nIndex,
 903: 		int    nSubItem,
 904: 		LPARAM lParam
 905: 	)
 906: {
 907: 	// パラメタの仮定
 908: 	ASSERT( IsWindowListViewControl( hListView ) );
 909: 	ASSERT( ListView_IsValidIndex( hListView, nIndex ) );
 910: 	ASSERT( 0 == nSubItem );
 911: 
 912: 	LVITEM lvi;
 913: 	memzero( &lvi, sizeof( lvi ) );
 914: 	lvi.mask     = LVIF_PARAM;
 915: 	lvi.iItem    = nIndex;
 916: 	lvi.iSubItem = nSubItem;
 917: 	lvi.lParam   = lParam;
 918: 	return !! ListView_SetItem( hListView, &lvi );
 919: }//ListView_SetItemParam
 920: 
 921: 
 922: //------------------------------------------------------------------------------------------------------------------
 923: // Scrollbar
 924: //------------------------------------------------------------------------------------------------------------------
 925: 
 926: 
 927: //*********************************************************
 928: // MakeScrollInfo
 929: //*********************************************************
 930: bool
 931: MakeScrollInfo
 932: 	(
 933: 		SCROLLINFO *si, 
 934: 		UINT        fMask, 
 935: 		int         nMin,
 936: 		int         nMax, 
 937: 		UINT        nPage, 
 938: 		int         nPos, 
 939: 		int         nTrackPos
 940: 	)
 941: {
 942: 	// パラメタの仮定
 943: 	ASSERT( IsValidPtr( si, sizeof( *si ) ) );
 944: 
 945: 	memzero( si, sizeof( *si ) );
 946: 	si->cbSize    = sizeof( *si );
 947: 	si->fMask     = fMask;
 948: 	si->nMin      = nMin;
 949: 	si->nMax      = nMax;
 950: 	si->nPage     = nPage;
 951: 	si->nPos      = nPos;
 952: 	si->nTrackPos = nTrackPos;
 953: 
 954: 	return true;
 955: }//MakeScrollInfo
 956: 
 957: //*********************************************************
 958: // GetScrollbarPageSize
 959: //*********************************************************
 960: int
 961: GetScrollbarPageSize
 962: 	(
 963: 		HWND hWnd, 
 964: 		int  nType
 965: 	)
 966: {
 967: 	// パラメタの仮定
 968: 	ASSERT( IsValidWindow( hWnd ) );
 969: 	ASSERT( ( SB_HORZ == nType )
 970: 	     || ( SB_VERT == nType )
 971: 	     || ( SB_CTL  == nType ) );
 972: 
 973: 	SCROLLINFO si;
 974: 	memzero( &si, sizeof( si ) );
 975: 	si.cbSize = sizeof( si );
 976: 	si.fMask  = SIF_PAGE;
 977: 
 978: 	VERIFY( GetScrollInfo( hWnd, nType, &si ) );
 979: 
 980: 	return si.nPage;
 981: }//GetScrollbarPageSize
 982: 
 983: //*********************************************************
 984: // GetScrollbarRangeMax
 985: // スクロールバーの最大位置を返す
 986: //*********************************************************
 987: int
 988: GetScrollbarRangeMax
 989: 	(
 990: 		HWND hWnd,
 991: 		int  nType
 992: 	)
 993: {
 994: 	// パラメタの仮定
 995: 	ASSERT( IsValidWindow( hWnd ) );
 996: 	ASSERT( ( SB_HORZ == nType )
 997: 	     || ( SB_VERT == nType )
 998: 	     || ( SB_CTL  == nType ) );
 999: 
1000: 	SCROLLINFO si;
1001: 	memzero( &si, sizeof( si ) );
1002: 	si.cbSize = sizeof( si );
1003: 	si.fMask  = SIF_RANGE;
1004: 
1005: 	VERIFY( GetScrollInfo( hWnd, nType, &si ) );
1006: 
1007: 	return si.nMax;
1008: }//GetScrollbarRangeMax
1009: 
1010: //*********************************************************
1011: // GetScrollbarRangeMin
1012: // スクロールバーの最小位置を返す
1013: //*********************************************************
1014: int
1015: GetScrollbarRangeMin
1016: 	(
1017: 		HWND hWnd,
1018: 		int  nType
1019: 	)
1020: {
1021: 	// パラメタの仮定
1022: 	ASSERT( IsValidWindow( hWnd ) );
1023: 	ASSERT( ( SB_HORZ == nType )
1024: 	     || ( SB_VERT == nType )
1025: 	     || ( SB_CTL  == nType ) );
1026: 
1027: 	SCROLLINFO si;
1028: 	memzero( &si, sizeof( si ) );
1029: 	si.cbSize = sizeof( si );
1030: 	si.fMask  = SIF_RANGE;
1031: 
1032: 	VERIFY( GetScrollInfo( hWnd, nType, &si ) );
1033: 
1034: 	return si.nMin;
1035: }//GetScrollbarRangeMin
1036: 
1037: //*********************************************************
1038: // GetScrollbarTrackPos
1039: //*********************************************************
1040: int
1041: GetScrollbarTrackPos
1042: 	(
1043: 		HWND hWnd, 
1044: 		int  nType
1045: 	)
1046: {
1047: 	// パラメタの仮定
1048: 	ASSERT( IsValidWindow( hWnd ) );
1049: 	ASSERT( ( SB_HORZ == nType )
1050: 	     || ( SB_VERT == nType )
1051: 	     || ( SB_CTL  == nType ) );
1052: 
1053: 	SCROLLINFO si;
1054: 	memzero( &si, sizeof( si ) );
1055: 	si.cbSize = sizeof( si );
1056: 	si.fMask  = SIF_TRACKPOS;
1057: 
1058: 	VERIFY( GetScrollInfo( hWnd, nType, &si ) );
1059: 
1060: 	return si.nTrackPos;
1061: }//GetScrollbarTrackPos
1062: 
1063: 
1064: //------------------------------------------------------------------------------------------------------------------
1065: // StatusBar
1066: //------------------------------------------------------------------------------------------------------------------
1067: 
1068: 
1069: //*********************************************************
1070: // IsStatusWindow
1071: //ウィンドウ hStatusbar がステータスバーであれば真を返す
1072: //*********************************************************
1073: bool
1074: IsStatusWindow
1075: 	(
1076: 		HWND hStatusbar
1077: 	)
1078: {
1079: 	VALID_TEST( IsValidWindow( hStatusbar ) );
1080: 	VALID_TEST( IsClassNameWindow( hStatusbar, STATUSCLASSNAME ) );
1081: 
1082: 	return true;
1083: }//IsStatusWindow
1084: 
1085: //*****************************************************************
1086: // StatusBar_SetParts
1087: //*****************************************************************
1088: bool
1089: StatusBar_SetParts
1090: 	(
1091: 		HWND  hStatusbar,
1092: 		int   nParts,
1093: 		int  *pWidths
1094: 	)
1095: {
1096: 	// パラメタの仮定
1097: 	ASSERT( IsStatusWindow( hStatusbar ) );
1098: 	ASSERT( (0 < nParts) && (nParts < 255) );
1099: 	ASSERT( IsValidPtr( pWidths, nParts * sizeof( int ) ) );
1100: 
1101: 	return !! SendMessage( hStatusbar, SB_SETPARTS, nParts, reinterpret_cast<LPARAM>( pWidths ) );
1102: }//StatusBar_SetParts
1103: 
1104: //*****************************************************************
1105: // StatusBar_SetText
1106: //*****************************************************************
1107: bool
1108: StatusBar_SetText
1109: 	(
1110: 		HWND        hStatusbar,
1111: 		int         nIndex,
1112: 		UINT        uType, 
1113: 		const char *text
1114: 	)
1115: {
1116: 	// パラメタの仮定
1117: 	ASSERT( IsStatusWindow( hStatusbar ) );
1118: 	ASSERT( (0 <= nIndex) && (nIndex < 255) );
1119: 	ASSERT( (             0  == uType)
1120: 	     || ( SBT_NOBORDERS  == uType)
1121: 	     || ( SBT_OWNERDRAW  == uType)
1122: 	     || ( SBT_POPOUT     == uType)
1123: 	     || ( SBT_RTLREADING == uType) );
1124: 	ASSERT( IsValidStringPtr( text ) );
1125: 
1126: 	return !! SendMessage( hStatusbar, SB_SETTEXT, ( nIndex | uType ), reinterpret_cast<LPARAM>( text ) );
1127: }//StatusBar_SetText
1128: 
1129: 
1130: //------------------------------------------------------------------------------------------------------------------
1131: // Spin
1132: //------------------------------------------------------------------------------------------------------------------
1133: 
1134: 
1135: //*********************************************************
1136: // IsDlgItemSpinControl
1137: //*********************************************************
1138: bool
1139: IsDlgItemSpinControl
1140: 	(
1141: 		HWND hwndDlg,
1142: 		int  nID
1143: 	)
1144: {
1145: 	VALID_TEST( IsValidWindow( hwndDlg ) );
1146: 
1147: 	HWND hwndSpin = GetDlgItem( hwndDlg, nID );
1148: 	VALID_TEST( IsWindowSpinControl( hwndSpin ) );
1149: 
1150: 	return true;
1151: }//IsDlgItemSpinControl
1152: 
1153: //*********************************************************
1154: // IsWindowSpinControl
1155: //*********************************************************
1156: bool 
1157: IsWindowSpinControl
1158: 	(
1159: 		HWND hwndSpin
1160: 	)
1161: {
1162: 	VALID_TEST( IsValidWindow( hwndSpin ) );
1163: 	VALID_TEST( IsClassNameWindow( hwndSpin, UPDOWN_CLASS ) );
1164: 
1165: 	return true;
1166: }//IsWindowSpinControl
1167: 
1168: //*********************************************************
1169: // Spin_SetBuddy
1170: //*********************************************************
1171: HWND // 関連づけられていたウィンドウ
1172: Spin_SetBuddy
1173: 	(
1174: 		HWND hwndSpin, // スピン・コントロール
1175: 		HWND hwndBuddy // 関連づけるコントロール
1176: 	)
1177: {
1178: 	// パラメタの仮定
1179: 	ASSERT( IsWindowSpinControl( hwndSpin ) );
1180: 	ASSERT( IsValidWindow( hwndBuddy ) );
1181: 
1182: 	return (HWND)SendMessage
1183: 		(
1184: 			hwndSpin, 
1185: 			UDM_SETBUDDY,
1186: 			reinterpret_cast<WPARAM>( hwndBuddy ),
1187: 			0
1188: 		);
1189: }//Spin_SetBuddy
1190: 
1191: //*********************************************************
1192: // Spin_SetPos
1193: //*********************************************************
1194: short
1195: Spin_SetPos
1196: 	(
1197: 		HWND hwndSpin,
1198: 		int  pos
1199: 	)
1200: {
1201: 	// パラメタの仮定
1202: 	ASSERT( IsWindowSpinControl( hwndSpin ) );
1203: 	ASSERT( (0 <= pos) && (pos <= SHRT_MAX) );
1204: 
1205: 	return (short)SendMessage( hwndSpin, UDM_SETPOS, 0, MAKELONG(pos, 0) );
1206: }//Spin_SetPos
1207: 
1208: //*********************************************************
1209: // Spin_SetRange
1210: //*********************************************************
1211: void
1212: Spin_SetRange
1213: 	(
1214: 		HWND hwndSpin,
1215: 		int  nLower, 
1216: 		int  nUpper
1217: 	)
1218: {
1219: 	// パラメタの仮定
1220: 	ASSERT( IsWindowSpinControl( hwndSpin ) );
1221: 	ASSERT( nLower <= nUpper );
1222: 	ASSERT( UD_MINVAL <= nLower );
1223: 	ASSERT( nUpper <= UD_MAXVAL );
1224: 
1225: 	SendMessage( hwndSpin, UDM_SETRANGE, 0, MAKELONG(nUpper, nLower) );
1226: }//Spin_SetRange
1227: 
1228: 
1229: //------------------------------------------------------------------------------------------------------------------
1230: // ToolTip
1231: //------------------------------------------------------------------------------------------------------------------
1232: 
1233: 
1234: //*********************************************************
1235: // CreateToolTip
1236: // TTS_ALWAYSTIP, TTS_NOPREFIX
1237: //*********************************************************
1238: HWND
1239: CreateToolTip
1240: 	(
1241: 		HWND      hWnd,
1242: 		HINSTANCE hInstance,
1243: 		DWORD     dwStyle,
1244: 		DWORD     dwExStyle
1245: 	)
1246: {
1247: 	// パラメタの仮定
1248: 	ASSERT( IsValidInstanceHandle( hInstance ) );
1249: 	ASSERT( IsValidWindow( hWnd ) );
1250: 
1251: 	return CreateWindowEx
1252: 		(
1253: 			dwExStyle,
1254: 			TOOLTIPS_CLASS,
1255: 			null,
1256: 			dwStyle,
1257: 			CW_USEDEFAULT,
1258: 			CW_USEDEFAULT,
1259: 			CW_USEDEFAULT,
1260: 			CW_USEDEFAULT,
1261: 			hWnd,
1262: 			0,
1263: 			hInstance,
1264: 			0 
1265: 		);
1266: }//CreateToolTip
1267: 
1268: //*********************************************************
1269: // IsWindowToolTipControl
1270: //*********************************************************
1271: bool
1272: IsWindowToolTipControl
1273: 	(
1274: 		HWND hwndToolTip
1275: 	)
1276: {
1277: 	VALID_TEST( IsValidWindow( hwndToolTip ) );
1278: 	VALID_TEST( IsClassNameWindow( hwndToolTip, TOOLTIPS_CLASS ) );
1279: 
1280: 	return true;
1281: }//IsWindowToolTipControl
1282: 
1283: //*********************************************************
1284: // ToolTip_AddDlgItem
1285: //   uFlags  …… TTF_SUBCLASS, etc...
1286: //*********************************************************
1287: bool
1288: ToolTip_AddDlgItem
1289: 	(
1290: 		HWND hToolTip,
1291: 		UINT flags,
1292: 		HWND hwndOwner,
1293: 		HWND hwndDlg,
1294: 		int  nID
1295: 	)
1296: {
1297: 	// パラメタの仮定
1298: 	ASSERT( IsWindowToolTipControl( hToolTip ) );
1299: 	ASSERT( IsValidWindow( hwndOwner ) );
1300: 	ASSERT( IsValidWindow( hwndDlg ) );
1301: 	ASSERT( IsValidDlgItem( hwndDlg, nID ) );
1302: 
1303: 	return ToolTip_AddDlgItemString
1304: 		(
1305: 			hToolTip,
1306: 			flags,
1307: 			hwndOwner, 
1308: 			hwndDlg,
1309: 			nID,
1310: 			LPSTR_TEXTCALLBACK 
1311: 		);
1312: }//ToolTip_AddDlgItem
1313: 
1314: //*********************************************************
1315: // ToolTip_AddDlgItemString
1316: //   uFlags  …… TTF_SUBCLASS, etc...
1317: //*********************************************************
1318: bool
1319: ToolTip_AddDlgItemString
1320: 	(
1321: 		HWND  hToolTip,  // 
1322: 		UINT  flags,     // 
1323: 		HWND  hwndOwner, // メッセージを受け取るウィンドウのハンドル
1324: 		HWND  hwndDlg,   // ダイアログへのハンドル
1325: 		int   nID,       // 関連づけるコントロールの識別子
1326: 		char *string     // 
1327: 	)
1328: {
1329: 	// パラメタの仮定
1330: 	ASSERT( IsWindowToolTipControl( hToolTip ) );
1331: 	ASSERT( IsValidWindow( hwndOwner ) );
1332: 	ASSERT( IsValidWindow( hwndDlg ) );
1333: 	ASSERT( IsValidDlgItem( hwndDlg, nID ) );
1334: 	ASSERT( (LPSTR_TEXTCALLBACK == string)
1335: 	     || IsValidStringPtr( string ) );
1336: 
1337: 	HWND hwndCtrl = GetDlgItem( hwndDlg, nID );
1338: 	return ToolTip_AddWindowString
1339: 		(
1340: 			hToolTip,
1341: 			flags,
1342: 			hwndOwner, 
1343: 			hwndCtrl,
1344: 			string
1345: 		);
1346: }//ToolTip_AddDlgItemString
1347: 
1348: //*********************************************************
1349: // ToolTip_AddWindow
1350: //   uFlags  …… TTF_SUBCLASS, etc...
1351: //*********************************************************
1352: bool
1353: ToolTip_AddWindow
1354: 	(
1355: 		HWND hToolTip,
1356: 		UINT flags,
1357: 		HWND hwndOwner, 
1358: 		HWND hwndTool
1359: 	)
1360: {
1361: 	// パラメタの仮定
1362: 	ASSERT( IsWindowToolTipControl( hToolTip ) );
1363: 	ASSERT( IsValidWindow( hwndOwner ) );
1364: 	ASSERT( IsValidWindow( hwndTool ) );
1365: 
1366: 	return ToolTip_AddWindowString
1367: 		(
1368: 			hToolTip,
1369: 			flags, 
1370: 			hwndOwner,
1371: 			hwndTool,
1372: 			LPSTR_TEXTCALLBACK
1373: 		);
1374: }//ToolTip_AddWindow
1375: 
1376: //*********************************************************
1377: // ToolTip_AddWindowString
1378: //   uFlags  …… TTF_SUBCLASS, etc...
1379: //*********************************************************
1380: bool
1381: ToolTip_AddWindowString
1382: 	(
1383: 		HWND  hToolTip,  //
1384: 		UINT  flags,     //
1385: 		HWND  hwndOwner, // メッセージを受け取るウィンドウのハンドル
1386: 		HWND  hwndTool,  // 関連づけるウィンドウへのハンドル
1387: 		char *string     //
1388: 	)
1389: {
1390: 	// パラメタの仮定
1391: 	ASSERT( IsWindowToolTipControl( hToolTip ) );
1392: 	ASSERT( IsValidWindow( hwndOwner ) );
1393: 	ASSERT( IsValidWindow( hwndTool ) );
1394: 	ASSERT( (LPSTR_TEXTCALLBACK == string)
1395: 		|| IsValidStringPtr( string ) );
1396: 
1397: 	TOOLINFO ti;
1398: 	memzero( &ti, sizeof( ti ) );
1399: 	ti.cbSize   = sizeof( ti );
1400: 	ti.uFlags   = flags | TTF_IDISHWND;
1401: 	ti.hwnd     = hwndOwner;
1402: 	ti.uId      = reinterpret_cast<UINT_PTR>( hwndTool );
1403: 	ti.lpszText = string;
1404: 	return !! SendMessage
1405: 		(
1406: 			hToolTip,
1407: 			TTM_ADDTOOL,
1408: 			0, 
1409: 			reinterpret_cast<LPARAM>( &ti )
1410: 		);
1411: }//ToolTip_AddWindowString
1412: 
1413: //*********************************************************
1414: // ToolTip_Enanble
1415: //*********************************************************
1416: void
1417: ToolTip_Enanble
1418: 	(
1419: 		HWND hToolTip,
1420: 		bool bEnable
1421: 	)
1422: {
1423: 	// パラメタの仮定
1424: 	ASSERT( IsWindowToolTipControl( hToolTip ) );
1425: 
1426: 	SendMessage( hToolTip, TTM_ACTIVATE, bEnable, 0 );
1427: }//ToolTip_Enanble
1428: 
1429: //*********************************************************
1430: // ToolTip_SetDelayTime
1431: //    nTime  …… milliseconds
1432: //    dwFlag …… TTDT_INITIAL, TTDT_RESHOW, TTDT_AUTOPOP, TTDT_AUTOMATIC
1433: //*********************************************************
1434: void
1435: ToolTip_SetDelayTime
1436: 	(
1437: 		HWND  hToolTip,
1438: 		DWORD dwFlag,
1439: 		int   nTime
1440: 	)
1441: {
1442: 	// パラメタの仮定
1443: 	ASSERT( IsWindowToolTipControl( hToolTip ) );
1444: 	ASSERT( ( TTDT_INITIAL   == dwFlag )
1445: 	     || ( TTDT_RESHOW    == dwFlag )
1446: 	     || ( TTDT_AUTOPOP   == dwFlag ) 
1447: 	     || ( TTDT_AUTOMATIC == dwFlag ) );
1448: 
1449: 	SendMessage( hToolTip, TTM_SETDELAYTIME, dwFlag, MAKELONG(nTime, 0) );
1450: }//ToolTip_SetDelayTime
1451: 
1452: //*********************************************************
1453: // ToolTip_SetMaxTipWidth
1454: //*********************************************************
1455: LRESULT // 変更前の幅
1456: ToolTip_SetMaxTipWidth
1457: 	(
1458: 		HWND hwndToolTip,
1459: 		int  width
1460: 	)
1461: {
1462: 	// パラメタの仮定
1463: 	ASSERT( IsWindowToolTipControl( hwndToolTip ) );
1464: 	ASSERT( (0 <= width) && (width <= USHRT_MAX) );
1465: 
1466: 	return SendMessage
1467: 		(
1468: 			hwndToolTip,
1469: 			TTM_SETMAXTIPWIDTH,
1470: 			0,
1471: 			width
1472: 		);
1473: }//ToolTip_SetMaxTipWidth
1474: 
1475: //*********************************************************
1476: // ToolTip_TrackActivate
1477: //*********************************************************
1478: void
1479: ToolTip_TrackActivate
1480: 	(
1481: 		      HWND      hToolTip, 
1482: 		      bool      bActivate, 
1483: 		const TOOLINFO *ti
1484: 	)
1485: {
1486: 	// パラメタの仮定
1487: 	ASSERT( IsWindowToolTipControl( hToolTip ) );
1488: 	ASSERT( IsValidReadPtr( ti, sizeof( *ti ) ) );
1489: 
1490: 	SendMessage
1491: 		(
1492: 			hToolTip,
1493: 			TTM_TRACKACTIVATE,
1494: 			bActivate,
1495: 			reinterpret_cast<LPARAM>( ti )
1496: 		);
1497: }//ToolTip_TrackActivate
1498: 
1499: //*********************************************************
1500: // ToolTip_TrackPosition
1501: //*********************************************************
1502: void
1503: ToolTip_TrackPosition
1504: 	(
1505: 		HWND hToolTip, 
1506: 		int  nPosX,
1507: 		int  nPosY
1508: 	)
1509: {
1510: 	// パラメタの仮定
1511: 	ASSERT( IsWindowToolTipControl( hToolTip ) );
1512: 
1513: 	SendMessage( hToolTip, TTM_TRACKPOSITION, 0, MAKELONG(nPosX, nPosY) );
1514: }//ToolTip_TrackPosition
1515: 
1516: 
1517: //------------------------------------------------------------------------------------------------------------------
1518: // Dialog
1519: //------------------------------------------------------------------------------------------------------------------
1520: 
1521: 
1522: //*********************************************************
1523: // MesBox
1524: //*********************************************************
1525: int
1526: MesBox
1527: 	(
1528: 		HWND        hWnd,
1529: 		const char *title,
1530: 		const char *string,
1531: 		UINT        uOption
1532: 	)
1533: {
1534: 	// パラメタの仮定
1535: 	ASSERT( !hWnd || IsValidWindow( hWnd ) );
1536: 	ASSERT( IsValidStringPtr( title ) );
1537: 	ASSERT( IsValidStringPtr( string ) );
1538: 
1539: 	MessageBeep( uOption & (MB_ICONASTERISK|MB_ICONEXCLAMATION|MB_ICONHAND|MB_ICONQUESTION|MB_OK) );
1540:  	return MessageBox( hWnd, string, title, uOption );
1541: }//MesBox
1542: 
1543: //*********************************************************
1544: //  出力書式の使えるメッセージボックス表示関数
1545: //*********************************************************
1546: int
1547: MesBoxEx
1548: 	(
1549: 		HWND        hWnd,
1550: 		UINT        uType,
1551: 		const char *title,
1552: 		const char *format,
1553: 		...
1554: 	)
1555: {
1556: 	// パラメタの仮定
1557: 	ASSERT( !hWnd || IsValidWindow( hWnd ) );
1558: 	ASSERT( IsValidStringPtr( title ) );
1559: 	ASSERT( IsValidStringPtr( format ) );
1560: 
1561: 	// 引数の並びの初期化
1562: 	va_list argptr; // 引数の並び(...)へのポインタ
1563: 	va_start( argptr, format );
1564: 	
1565: 	// 表示する文字列の作成
1566: 	char string[ 1024 ];
1567: 	vsnprintf( string, numof(string), format, argptr );
1568: 	string[ numof(string)-1 ] = '\0';
1569: 	ASSERT( IsValidStringPtr( string ) );
1570: 
1571: 	// メッセージボックスの表示
1572: 	const int nResult = MessageBox( hWnd, string, title, uType );
1573: 
1574: 	// 引数の並びの破棄
1575: 	va_end( argptr );
1576: 
1577: 	return nResult;
1578: }//MesBoxEx
1579: 
1580: //*********************************************************
1581: // ColorBox
1582: //*********************************************************
1583: bool
1584: ColorBox
1585: 	(
1586: 		HWND      hWnd,
1587: 		COLORREF *rgbColor
1588: 	)
1589: {
1590: 	// パラメタの仮定
1591: 	ASSERT( !hWnd || IsValidWindow( hWnd ) );
1592: 	ASSERT( IsValidPtr( rgbColor, sizeof( *rgbColor ) ) );
1593: 
1594: 	return ColorBoxEx( hWnd, null, null, null, CC_RGBINIT, rgbColor, null );
1595: }//ColorBox
1596: 
1597: //*********************************************************
1598: // ColorBoxEx
1599: //*********************************************************
1600: bool
1601: ColorBoxEx
1602: 	(
1603: 		HWND          hWnd,
1604: 		HINSTANCE     hInstance,
1605: 		const char   *Template,
1606: 		LPCCHOOKPROC  HookProc,
1607: 		DWORD         Flags,
1608: 		COLORREF     *rgbColor,
1609: 		LPARAM        UserData
1610: 	)
1611: {
1612: 	// パラメタの仮定
1613: 	ASSERT( !hWnd || IsValidWindow( hWnd ) );
1614: 	ASSERT( IsValidPtr( rgbColor, sizeof( *rgbColor ) ) );
1615: 	ASSERT( IsValidInstanceHandle( hInstance ) );
1616: 
1617: 	CHOOSECOLOR cc;
1618: 	COLORREF    CustColors[16];
1619: 	memzero( &cc, sizeof( cc ) );
1620: 	cc.lStructSize    = sizeof( cc );
1621: 	cc.hwndOwner      = hWnd;
1622: 	cc.hInstance      = (HWND)hInstance;
1623: 	cc.lpTemplateName = Template;
1624: 	cc.lpfnHook       = HookProc;
1625: 	cc.lCustData      = UserData;
1626: 	cc.Flags          = Flags;
1627: 	cc.rgbResult      = *rgbColor;
1628: 	cc.lpCustColors   = CustColors;
1629: 	if ( ChooseColor( &cc ) )
1630: 	{
1631: 		*rgbColor = cc.rgbResult;
1632: 		return true;
1633: 	}
1634: 	return false;
1635: }//ColorBoxEx
1636: 
1637: 
1638: static bool IsValidOpenFileNameDialogFilterPtr
1639: ( const char *filter )
1640: {
1641: 	{for( const char *p = filter; '\0' != *p; p = strtail(p) )
1642: 	{
1643: 		p = 1 + strtail( p );
1644: 		if ( '\0' == *p )
1645: 			return false;
1646: 	}}
1647: 
1648: 	return true;
1649: }
1650: 
1651: 
1652: //*********************************************************
1653: // OpenFileBox
1654: //   Flags …… OFN_HIDEREADONLY, OFN_ENABLEHOOK, OFN_ENABLETEMPLATE, OFN_ALLOWMULTISELECT, etc……
1655: //*********************************************************
1656: bool
1657: OpenFileBox
1658: 	(
1659: 		HWND         hWnd,
1660: 		DWORD        dwFlags,
1661: 		char        *buffer,
1662: 		int          bufsize,
1663: 		const char *defpath, 
1664: 		const char *title,
1665: 		const char *filter
1666: 	)
1667: {
1668: 	// パラメタの仮定
1669: 	ASSERT( IsEnoughPathBufferSize( bufsize ) ); // [WARN]
1670: 	ASSERT( !hWnd || IsValidWindow( hWnd ) );
1671: 	ASSERT( IsValidStringPtr( title ) );
1672: //	ASSERT( IsValidStringPtr( filter ) );
1673: 	ASSERT( IsValidStringPtr( defpath ) );
1674: 	ASSERT( IsValidOpenFileNameDialogFilterPtr( filter ) );
1675: 	ASSERT( IsValidStringBufferPtr( buffer, max(bufsize, 1+MAX_PATH) ) );
1676: 	ASSERT( (strtail(defpath) < buffer) || (buffer + bufsize < defpath) );
1677: 	DESTROY_TEXT_BUFFER( buffer, bufsize ); // [破壊]
1678: 
1679: 	return OpenFileBoxEx
1680: 		(
1681: 			hWnd,
1682: 			null,
1683: 			null, 
1684: 			null, 
1685: 			dwFlags,
1686: 			buffer,
1687: 			bufsize, 
1688: 			defpath, 
1689: 			title,
1690: 			filter,
1691: 			0
1692: 		);
1693: }//OpenFileBox
1694: 
1695: //*********************************************************
1696: // OpenFileBoxEx
1697: //*********************************************************
1698: bool
1699: OpenFileBoxEx
1700: 	(
1701: 		HWND           hWnd,
1702: 		HINSTANCE      hInstance,
1703: 		const char   *Template,
1704: 		LPOFNHOOKPROC  HookProc,
1705: 		DWORD          dwFlags,
1706: 		char          *buffer,
1707: 		int            bufsize,
1708: 		const char   *defpath,
1709: 		const char   *title,
1710: 		const char   *filter,
1711: 		LPARAM         UserData
1712: 	)
1713: {
1714: 	// パラメタの仮定
1715: 	ASSERT( IsEnoughPathBufferSize( bufsize ) ); // [WARN]
1716: 	ASSERT( !hWnd || IsValidWindow( hWnd ) );
1717: 	ASSERT( IsValidStringPtr( title ) );
1718: //	ASSERT( IsValidStringPtr( filter ) );
1719: 	ASSERT( IsValidStringPtr( defpath ) );
1720: 	ASSERT( IsValidOpenFileNameDialogFilterPtr( filter ) );
1721: 	ASSERT( IsValidStringBufferPtr( buffer, max(bufsize, 1+MAX_PATH) ) );
1722: 	ASSERT( (strtail(defpath) < buffer) || (buffer + bufsize < defpath) );
1723: 	ASSERT( !HookProc || IsValidCodePtr( HookProc ) );
1724: 	DESTROY_TEXT_BUFFER( buffer, bufsize ); // [破壊]
1725: 	
1726: 	// デフォルトのパス
1727: 	// デフォルトのファイル名
1728: 	char path[ MAX_PATH_BUF ];
1729: 	strcopy( path, numof( path ), defpath );
1730: 	ASSERT( IsValidStringPtr( path ) );
1731: 	strcopy( buffer, bufsize, CutFileName(path) );
1732: 	ASSERT( IsValidStringPtr( buffer ) );
1733: 	ASSERT( IsValidStringPtr( path ) );
1734: 
1735: 	// ofn の初期化
1736: 	OPENFILENAME ofn;
1737: 	memzero( &ofn, sizeof( ofn ) );
1738: 	ofn.lStructSize       = sizeof( ofn );
1739: 	ofn.hwndOwner         = hWnd;
1740: 	ofn.hInstance         = hInstance;
1741: 	ofn.lpTemplateName    = Template;
1742: 	ofn.lpfnHook          = HookProc;
1743: 	ofn.Flags             = dwFlags | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_ENABLESIZING | OFN_EXPLORER;
1744: 	ofn.lpstrTitle        = title;
1745: 	ofn.lpstrFile         = buffer;
1746: 	ofn.nMaxFile          = bufsize;
1747: 	ofn.lpstrFilter       = filter;
1748: 	ofn.lpstrInitialDir   = path;
1749: 	ofn.lCustData         = UserData;
1750: 	ofn.nFilterIndex      = 0;
1751: 	ofn.lpstrFileTitle    = null;
1752: 	ofn.nMaxFileTitle     = 0;
1753: 	ofn.lpstrCustomFilter = null;
1754: 	ofn.nMaxCustFilter    = 0;
1755: 	ofn.lpstrDefExt       = null;
1756: 	return !! GetOpenFileName( &ofn );
1757: }//OpenFileBoxEx
1758: 
1759: //*********************************************************
1760: // SaveFileBox
1761: //   Flags …… OFN_OVERWRITEPROMPT, OFN_HIDEREADONLY, OFN_FILEMUSTEXIST, etc……
1762: //*********************************************************
1763: bool
1764: SaveFileBox
1765: 	(
1766: 		      HWND   hWnd,
1767: 		      DWORD  dwFlags,
1768: 		      char *buffer,
1769: 		      int    bufsize,
1770: 		const char *defpath,
1771: 		const char *title,
1772: 		const char *filter
1773: 	)
1774: {
1775: 	// パラメタの仮定
1776: 	ASSERT( IsEnoughPathBufferSize( bufsize ) ); // [WARN]
1777: 	ASSERT( !hWnd || IsValidWindow( hWnd ) );
1778: 	ASSERT( IsValidStringPtr( title ) );
1779: //	ASSERT( IsValidStringPtr( filter ) );
1780: 	ASSERT( IsValidStringPtr( defpath ) );
1781: 	ASSERT( IsValidOpenFileNameDialogFilterPtr( filter ) );
1782: 	ASSERT( IsValidStringBufferPtr( buffer, max(bufsize, 1+MAX_PATH) ) );
1783: 	ASSERT( (strtail(defpath) < buffer) || (buffer + bufsize < defpath) );
1784: 	DESTROY_TEXT_BUFFER( buffer, bufsize ); // [破壊]
1785: 
1786: 	return SaveFileBoxEx
1787: 		(
1788: 			hWnd,
1789: 			null,
1790: 			null,
1791: 			null,
1792: 			dwFlags,
1793: 			buffer,
1794: 			bufsize,
1795: 			defpath, 
1796: 			title,
1797: 			filter,
1798: 			0
1799: 		);
1800: }//SaveFileBox
1801: 
1802: //*********************************************************
1803: // SaveFileBoxEx
1804: //*********************************************************
1805: bool
1806: SaveFileBoxEx
1807: 	(
1808: 		HWND           hWnd,
1809: 		HINSTANCE      hInstance,
1810: 		const char   *Template,
1811: 		LPOFNHOOKPROC  HookProc,
1812: 		DWORD          dwFlags,
1813: 		char          *buffer,
1814: 		int            bufsize,
1815: 		const char   *defpath,
1816: 		const char   *title,
1817: 		const char   *filter,
1818: 		LPARAM         UserData
1819: 	)
1820: {
1821: 	// パラメタの仮定
1822: 	ASSERT( IsEnoughPathBufferSize( bufsize ) ); // [WARN]
1823: 	ASSERT( !hWnd || IsValidWindow( hWnd ) );
1824: 	ASSERT( IsValidStringPtr( title ) );
1825: //	ASSERT( IsValidStringPtr( filter ) );
1826: 	ASSERT( IsValidStringPtr( defpath ) );
1827: 	ASSERT( IsValidOpenFileNameDialogFilterPtr( filter ) );
1828: 	ASSERT( IsValidStringBufferPtr( buffer, max(bufsize, 1+MAX_PATH) ) );
1829: 	ASSERT( (strtail(defpath) < buffer) || (buffer + bufsize < defpath) );
1830: 	ASSERT( !HookProc || IsValidCodePtr( HookProc ) );
1831: 	DESTROY_TEXT_BUFFER( buffer, bufsize ); // [破壊]
1832: 
1833: 	// デフォルトのパス
1834: 	// デフォルトのファイル名
1835: 	char path[ MAX_PATH_BUF ];
1836: 	strcopy( path, numof( path ), defpath );
1837: 	ASSERT( IsValidStringPtr( path ) );
1838: 	strcopy( buffer, bufsize, CutFileName(path) );
1839: 	ASSERT( IsValidStringPtr( buffer ) );
1840: 	ASSERT( IsValidStringPtr( path ) );
1841: 
1842: 	// ofn の初期化
1843: 	OPENFILENAME ofn;
1844: 	memzero( &ofn, sizeof( ofn ) );
1845: 	ofn.lStructSize       = sizeof( ofn );
1846: 	ofn.hwndOwner         = hWnd;
1847: 	ofn.hInstance         = hInstance;
1848: 	ofn.lpTemplateName    = Template;
1849: 	ofn.lpfnHook          = HookProc;
1850: 	ofn.Flags             = dwFlags | OFN_ENABLESIZING | OFN_EXPLORER;
1851: 	ofn.lpstrTitle        = title;
1852: 	ofn.lpstrFile         = buffer;
1853: 	ofn.nMaxFile          = bufsize;
1854: 	ofn.lpstrFilter       = filter;
1855: 	ofn.lpstrInitialDir   = path;
1856: 	ofn.lCustData         = UserData;
1857: 	ofn.nFilterIndex      = 0;
1858: 	ofn.lpstrFileTitle    = null;
1859: 	ofn.nMaxFileTitle     = 0;
1860: 	ofn.lpstrCustomFilter = null;
1861: 	ofn.nMaxCustFilter    = 0;
1862: 	ofn.lpstrDefExt       = null;
1863: 	return !! GetSaveFileName( &ofn );
1864: }//SaveFileBoxEx
1865: 
1866: 
1867: //** end **
1868: 

参照:


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

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

水無瀬の部屋 > sample > tools > toolctrl.cpp

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