class LboxCombobox : public LboxWintool

  コンストラクタ



コンボボックスと言っても、アプリケーションで使用するのは殆どの場合ドロップダウンリストスタイルです。本オブジェクトではそれを使用しています。

また、通常コンボボックスは表示部分であるテキストの他に内部データを必要とします。その為、リストボックスを内部に作成してペアで使用するようにしています。

一つ目のコンストラクタは既存のコンボボックスを使用するタイプで、これが通常となります。ダイアログ上で貼り付けて GetDlgItem 関数でハンドルを取得してコンストラククタに渡します。

ドロップダウンリストの初期の大きさは、ChangeWindowSize(ウインドウツール) メソッドで設定します。

  
// *********************************************************
// 拡張コンストラクタ
// *********************************************************
LboxCombobox::LboxCombobox( HWND hTarget )
{
	this->hWnd = hTarget;
	List = new LboxListbox( GetParent( hTarget ), 0 );
	LboxCombobox::bCreate = false;
}
LboxCombobox::LboxCombobox( HWND hOwner, int nID )
{
	this->hWnd = CreateWindow(
		"combobox",
		NULL,
		WS_CHILD | CBS_DROPDOWNLIST,
		0,0,0,0,
		hOwner,
		(HMENU)nID,
		LboxGetInstance( hOwner ),
		NULL
	);

	List = new LboxListbox( hOwner, 0 );
	LboxCombobox::bCreate = true;
}

// *********************************************************
// デフォルトコンストラクタ
// *********************************************************
LboxCombobox::LboxCombobox()
{
	LboxCombobox::bCreate = false;
	List = NULL;
}

// *********************************************************
// デストラクタ
// *********************************************************
LboxCombobox::~LboxCombobox()
{
	delete this->List;
	if ( LboxCombobox::bCreate ) {
		if ( this->hWnd != NULL ) {
			DestroyWindow( this->hWnd );
			this->hWnd = NULL;
		}
	}
}
  



  Add



  
// *********************************************************
// コンボボックスにコードと文字列を追加
// 戻り値 : 追加された位置
// *********************************************************
int LboxCombobox::Add( LboxString *LScode, LboxString *LString )
{
	return LboxCombobox::Add(
		LScode->szLboxString,
		LString->szLboxString
	);
}
int LboxCombobox::Add( LPTSTR pszCode, LPTSTR pszBuffer )
{
	List->Add( pszCode );
	return LboxComboAdd(
		LboxCombobox::hWnd,
		pszBuffer
	);
}
  



  Insert

  
// *********************************************************
// コンボボックスに文字列を挿入
// 戻り値 : 挿入された位置
// *********************************************************
int LboxCombobox::Insert( int nIdx, LboxString *LScode, LboxString *LString )
{
	return LboxCombobox::Insert(
		nIdx,
		LScode->szLboxString,
		LString->szLboxString
	);
}
int LboxCombobox::Insert( int nIdx, LPTSTR pszCode, LPTSTR pszBuffer )
{
	List->Insert( nIdx, pszCode );
	return LboxComboInsert(
		LboxCombobox::hWnd,
		nIdx,
		pszBuffer
	);
}
  



  Delete

  
// *********************************************************
// コンボボックスの指定行を削除
// 戻り値 : リスト内に残っている文字列の総数
// 戻り値 : 存在しない行を指定すると -1
// *********************************************************
int LboxCombobox::Delete( int nIdx )
{
	List->Delete( nIdx );
	return LboxComboDelete(
		LboxCombobox::hWnd,
		nIdx
	);
}
  



  Reset

  
// *********************************************************
// コンボボックスのリセット
// 戻り値 : 無し
// *********************************************************
void LboxCombobox::Reset( void )
{
	List->Reset();
	LboxComboReset( LboxCombobox::hWnd );
}
  



  SetWidth,SetHeight

  
// *********************************************************
// コンボボックスのリストボックス部分の幅の設定
// 戻り値 : 無し
// *********************************************************
void LboxCombobox::SetWidth( int nWidth )
{
	LboxComboSetWidth(
		LboxCombobox::hWnd,
		nWidth
	);

}
  

  
// *********************************************************
// コンボボックスの選択部分の高さの設定
// 戻り値 : 無し
// *********************************************************
void LboxCombobox::SetHeight( int nHeight )
{
	LboxComboSetHeight(
		LboxCombobox::hWnd,
		nHeight
	);
}
  



  Count

  
// *********************************************************
// コンボボックスの行数取得
// 戻り値 : 行数
// *********************************************************
int LboxCombobox::Count( void )
{
	return LboxComboCount(
		LboxCombobox::hWnd
	);
}
  



  Select

  
// *********************************************************
// コンボボックスの指定行を選択
// 戻り値 : 無し
// *********************************************************
void LboxCombobox::Select( int nIndex )
{
	LboxComboSelect(
		LboxCombobox::hWnd,
		nIndex
	);
}
  



  FindString

  
// *********************************************************
// コンボボックス内の文字列の検索
// 戻り値 : 一致する行のインデックス(失敗時は-1)
// *********************************************************
int LboxCombobox::FindString( LboxString *LString )
{
	return LboxCombobox::FindString( LString->szLboxString );
}
int LboxCombobox::FindString( LPTSTR lpFind )
{
	return LboxComboFindString(
		LboxCombobox::hWnd,
		lpFind
	);
}
  



  FindData

  
// *********************************************************
// コンボボックス内の内部文字列の検索
// 戻り値 : 一致する行のインデックス(失敗時は-1)
// *********************************************************
int LboxCombobox::FindData( LboxString *LString )
{
	return LboxCombobox::FindData( LString->szLboxString );
}
int LboxCombobox::FindData( LPTSTR lpFind )
{
	return List->FindString(
		lpFind
	);
}
  



  SelectedRow

  
// *********************************************************
// コンボボックスの選択された行の取得
// 戻り値 : 選択された行(選択されていない場合は -1 )
// *********************************************************
int LboxCombobox::SelectedRow( void )
{
	return LboxComboSelectedRow(
		LboxCombobox::hWnd
	);
}
  



  GetText

  
// *********************************************************
// コンボボックスから文字列を取得
// 戻り値 : 取得した文字列の長さ
// 戻り値 : エラーの場合は -1
// *********************************************************
int LboxCombobox::GetText( int nIndex, LboxString *LString )
{
	int ret;

	ret = (int)SendMessage(
		LboxCombobox::hWnd,
		CB_GETLBTEXTLEN,
		(WPARAM)nIndex,
		0L
	);
	if ( ret == CB_ERR ) {
		return -1;
	}
	if ( (DWORD)(ret + 1) > LString->nLboxString ) {
		LString->Resize( ret + 1 );
	}

	ret = (int)SendMessage(
		hWnd,
		CB_GETLBTEXT,
		(WPARAM)nIndex,
		(LPARAM)(LPCTSTR)LString->szLboxString
	);
	if ( ret == CB_ERR ) {
		return -1;
	}

	return ret;
}
  



  GetData

  
// *********************************************************
// コンボボックスから内部文字列を取得
// 戻り値 : 取得した文字列の長さ
// 戻り値 : エラーの場合は -1
// *********************************************************
int LboxCombobox::GetData( int nIndex, LboxString *LString )
{
	return List->GetText(
		nIndex,
		LString
	);
}
  



  SetText

  
// *********************************************************
// コンボボックスの指定行を更新
// 戻り値 : 挿入された位置
// 戻り値 : 失敗すると -1
// *********************************************************
int LboxCombobox::SetText( int nIndex, LboxString *LString )
{
	return LboxCombobox::SetText(
		nIndex,
		LString->szLboxString 
	);
}
int LboxCombobox::SetText( int nIndex, LPTSTR lpString )
{
	return LboxComboSetText(
		LboxCombobox::hWnd,
		nIndex,
		lpString 
	);
}
  



  SelectedGetText

  
// *********************************************************
// 選択した行の文字列を取得
// 戻り値 : 取得した文字列の長さ
// 戻り値 : エラーの場合は -1
// *********************************************************
int LboxCombobox::SelectedGetText( LboxString *LString )
{
	int ret,nIndex;

	nIndex = LboxCombobox::SelectedRow();
	if ( nIndex == -1 ) {
		return -1;
	}

	ret = LboxCombobox::GetText( nIndex, LString );
	if ( ret == -1 ) {
		return -1;
	}

	return ret;
}
  



  SelectedSetText

  
// *********************************************************
// 選択した行に文字列を設定
// 戻り値 : 挿入された位置
// 戻り値 : エラーの場合は -1
// *********************************************************
int LboxCombobox::SelectedSetText( LboxString *LString )
{
	return LboxCombobox::SelectedSetText( LString->szLboxString );
}
int LboxCombobox::SelectedSetText( LPCTSTR pszBuffer )
{
	return LboxComboSelectedSetText(
		LboxCombobox::hWnd,
		pszBuffer
	);
}
  



  SelectedDelete

  
// *********************************************************
// 選択した行を削除
// 戻り値 : リスト内に残っている文字列の総数
// 戻り値 : エラーの場合は -1
// *********************************************************
int LboxCombobox::SelectedDelete( HWND hWnd )
{
	int nIdx;
	nIdx = LboxCombobox::SelectedRow();
	List->Delete( nIdx );
	return LboxComboSelectedDelete( LboxCombobox::hWnd );
}
  



  SelectedGetData

  
// *********************************************************
// 選択した行の内部文字列を取得
// 戻り値 : 取得した文字列の長さ
// 戻り値 : エラーの場合は -1
// *********************************************************
int LboxCombobox::SelectedGetData( LboxString *LString )
{
	int ret,nIndex;

	nIndex = LboxCombobox::SelectedRow();
	if ( nIndex == -1 ) {
		return -1;
	}

	ret = LboxCombobox::GetData( nIndex, LString );
	if ( ret == -1 ) {
		return -1;
	}

	return ret;
}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ