class LboxListview : public LboxWintool,public LboxToken

  リストビューコントロールのプロパティ



  
LBOX_* イベントを使用するには、このクラスのインスタンスを作成する必要があります
  






  オブジェクトの作成と削除



ダイアログの場合

  
LboxDlg *Dlg;
LboxListview *Lview;
LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	switch( message )
	{
		case WM_INITDIALOG:
			Dlg = new LboxDlg( hDlg );
			Lview = new LboxListview( GetDlgItem( hDlg, IDC_LIST1 ) );
			Lview->Grid( );
			return TRUE;

		case WM_COMMAND:
			if( LOWORD(wParam) == IDCANCEL ) {
				Dlg->End( LOWORD(wParam) );
				delete Lview;
				return TRUE;
			}
			break;
	}
	return FALSE;
}
  

メインウインドウの場合

  
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch( message ) {
		case WM_CREATE:
			LvTable = new LboxListview(
				hWnd,
				LBOX_LISTVIEW_EDITABLE |
				LBOX_LISTVIEW_CREATE
			);
			LvTable->Grid( );

			Win = new LboxWin( hWnd );
			Win->StatusCreate( ID_STATUS );
			Win->ScreenFit( );
			break;

		case WM_SIZE:
			Win->StatusFit( wParam, lParam );
			LvTable->ParentFit(
				(DWORD)wParam,
				0, 0,
				Win->GetHeight( Win->hStatus ),
				0
			);

			break;

		case WM_DESTROY:
			delete LvTable;
			delete Win;

			PostQuitMessage( 0 );
			break;

		default:
			return DefWindowProc( hWnd, message, wParam, lParam );
	}
	return 0;
}
  



  タイトルの作成

  
LboxDlg *Dlg;
LboxListview *Lview;
LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	switch( message )
	{
		case WM_INITDIALOG:
			Dlg = new LboxDlg( hDlg );
			Lview = new LboxListview( GetDlgItem( hDlg, IDC_LIST1 ) );
			Lview->Grid( );

			Lview->AddColumn( LVCFMT_LEFT, 70, "コード" );
			Lview->AddColumn( LVCFMT_LEFT, 150, "氏名" );
			Lview->AddColumn( LVCFMT_LEFT, 150, "フリガナ" );
			Lview->AddColumn( LVCFMT_LEFT, 100, "電話番号" );

			return TRUE;

		case WM_COMMAND:
			if( LOWORD(wParam) == IDCANCEL ) {
				Dlg->End( LOWORD(wParam) );
				delete Lview;
				return TRUE;
			}
			break;
	}
	return FALSE;
}
  



  データの作成

  
LboxDlg *Dlg;
LboxListview *Lview;
LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	switch( message )
	{
		case WM_INITDIALOG:
			Dlg = new LboxDlg( hDlg );
			Lview = new LboxListview( GetDlgItem( hDlg, IDC_LIST1 ) );
			Lview->Grid( );

			Lview->AddColumn( LVCFMT_LEFT, 70, "コード" );
			Lview->AddColumn( LVCFMT_LEFT, 150, "氏名" );
			Lview->AddColumn( LVCFMT_LEFT, 150, "フリガナ" );
			Lview->AddColumn( LVCFMT_LEFT, 100, "電話番号" );

			return TRUE;

		case WM_COMMAND:
			if( LOWORD(wParam) == IDCANCEL ) {
				Dlg->End( LOWORD(wParam) );
				delete Lview;
				return TRUE;
			}

			if( LOWORD(wParam) == IDC_BUTTON1 ) {
				Lview->AddRow();
				Lview->SetColumnText( 0, "0001" );
				Lview->SetColumnText( 1, "山田太郎" );
				Lview->SetColumnText( 2, "ヤマダタロウ" );
				Lview->SetColumnText( 3, "123-456-7890" );
			}
			break;
	}
	return FALSE;
}
  



  コンストラクタ

lightbox.lib で使用するオリジナルイベントは、全て LboxListview の拡張コンストラクタ2で、dwFlag に 0x00000001 をセットする事によって実装されます。直接 Lisview に関係無いイベントも含まれているので、アプリケーション作成時にはかならずどこかで LboxListbiew(0x00000001) をインスタンス化しておいて下さい

  
// *********************************************************
// デフォルトコンストラクタ
// *********************************************************
LboxListview::LboxListview()
{
	LboxListview::Rowid = 0;
	LboxListview::hHeader = NULL;
	LboxListview::lpSkipColumn = "";
	LboxListview::hhkFlg = false;
	LboxListview::dwInitFlag = 0;
	this->hWnd = NULL;
	LboxListview::hCombo = NULL;
	LboxListview::hEdit = NULL;
	LboxListview::hMenu = NULL;
	LboxListview::hFont = NULL;
	LboxListview::ColumnType = NULL;
	LboxListview::ColumnSize = NULL;

	ListView_SetExtendedListViewStyle(
		this->hWnd,
		LVS_EX_SUBITEMIMAGES
	);

	LboxListview::Buffer = new LboxString( );
}

// *********************************************************
// 拡張コンストラクタ
// *********************************************************
LboxListview::LboxListview( HWND hTarget )
{
	LboxListview::Rowid = 0;
	LboxListview::hHeader = NULL;
	LboxListview::lpSkipColumn = "";
	LboxListview::hhkFlg = false;
	LboxListview::dwInitFlag = 0;
	LboxListview::ColumnType = NULL;
	LboxListview::ColumnSize = NULL;
	this->hWnd = hTarget;
	LboxListview::hEdit = 
		LboxCreateEdit( this->hWnd, 50001 );
	if ( LboxListview::hEdit != NULL ) {
		HFONT hFont;

		hFont = (HFONT)SendMessage( this->hWnd, WM_GETFONT, 0, 0 );
		SendMessage( LboxListview::hEdit, WM_SETFONT, (WPARAM)hFont, 0 );
		LboxMoveWindowTop( LboxListview::hEdit );
	}
	LboxListview::hCombo = 
		LboxCreateDropdownListbox( this->hWnd, 50002 );
	if ( LboxListview::hCombo != NULL ) {
		HFONT hFont;

		hFont = (HFONT)SendMessage( this->hWnd, WM_GETFONT, 0, 0 );
		SendMessage( LboxListview::hCombo, WM_SETFONT, (WPARAM)hFont, 0 );
		LboxMoveWindowTop( LboxListview::hCombo );
	}

	LboxListview::hMenu = NULL;
	LboxListview::hFont = NULL;

	ListView_SetExtendedListViewStyle(
		this->hWnd,
		LVS_EX_SUBITEMIMAGES
	);
	LboxListview::Buffer = new LboxString( );
	LboxListview::hHeader = ListView_GetHeader( this->hWnd );
}

// *********************************************************
// 拡張コンストラクタ2
// *********************************************************
LboxListview::LboxListview( HWND hTarget, DWORD dwFlag )
{
	LboxListview::Rowid = 0;
	LboxListview::hHeader = NULL;
	LboxListview::lpSkipColumn = "";
	LboxListview::hhkFlg = false;
	LboxListview::dwInitFlag = dwFlag;
	LboxListview::ColumnType = NULL;
	LboxListview::ColumnSize = NULL;

	if ( dwFlag & 0x00000002 ) {
		LboxListview::nID = nBaseId;
		nBaseId++;
		this->hWnd = CreateWindowEx(
			0,
			WC_LISTVIEW,
			"",
			WS_CHILD | WS_VISIBLE | WS_BORDER |
			LVS_REPORT | LVS_SHOWSELALWAYS,
			0, 0, 0, 0,
			hTarget,
			(HMENU)(LboxListview::nID),
			LboxGetInstance( hTarget ),
			NULL
		);
	}
	else {
		this->hWnd = hTarget;
	}

	LboxListview::hCombo = 
		LboxCreateDropdownListbox( this->hWnd, 50002 );
	if ( LboxListview::hCombo != NULL ) {
		HFONT hFont;

		hFont = (HFONT)SendMessage( this->hWnd, WM_GETFONT, 0, 0 );
		SendMessage( LboxListview::hCombo, WM_SETFONT, (WPARAM)hFont, 0 );
		LboxMoveWindowTop( LboxListview::hCombo );
	}
	LboxListview::hEdit = 
		LboxCreateEdit( this->hWnd, 50001 );
	if ( LboxListview::hEdit != NULL ) {
		HFONT hFont;

		hFont = (HFONT)SendMessage( this->hWnd, WM_GETFONT, 0, 0 );
		SendMessage( LboxListview::hEdit, WM_SETFONT, (WPARAM)hFont, 0 );
		LboxMoveWindowTop( LboxListview::hEdit );
	}

	if ( dwFlag & 0x00000001 ) {

		if ( hhk == NULL ) {
			LboxListview::hhkFlg = true;
			hhk = SetWindowsHookEx(
				WH_CALLWNDPROCRET,
				CallWndRetProc,
				NULL,
				GetCurrentThreadId()				
			);

			hhkPost = SetWindowsHookEx(
				WH_GETMESSAGE,
				GetMsgProc,
				NULL,
				GetCurrentThreadId()				
			);
		}

	}

	LboxListview::hMenu = NULL;
	LboxListview::hFont = NULL;

	ListView_SetExtendedListViewStyle(
		this->hWnd,
		LVS_EX_SUBITEMIMAGES
	);
	LboxListview::Buffer = new LboxString( );
	LboxListview::hHeader = ListView_GetHeader( this->hWnd );
}

// *********************************************************
// デストラクタ
// *********************************************************
LboxListview::~LboxListview()
{
	if ( LboxListview::hEdit != NULL ) {
		DestroyWindow( LboxListview::hEdit );
		LboxListview::hEdit = NULL;
	}
	if ( LboxListview::hCombo != NULL ) {
		DestroyWindow( LboxListview::hCombo );
		LboxListview::hCombo = NULL;
	}
	if ( LboxListview::hhkFlg ) {
		if ( hhk != NULL ) {
			UnhookWindowsHookEx( hhk );
			hhk = NULL;
		}
		if ( hhkPost != NULL ) {
			UnhookWindowsHookEx( hhkPost );
			hhkPost = NULL;
		}
	}
	if ( LboxListview::hMenu != NULL ) {
		DestroyMenu( LboxListview::hMenu );
		LboxListview::hMenu = NULL;
	}

	if ( LboxListview::hFont != NULL ) {
		DeleteObject( LboxListview::hFont );
		LboxListview::hFont = NULL;
	}

	if ( LboxListview::dwInitFlag & 0x00000002 ) {
		if ( this->hWnd != NULL ) {
			DestroyWindow( this->hWnd );
			this->hWnd = NULL;
		}
	}
	if ( LboxListview::ColumnType != NULL ) {
		delete LboxListview::ColumnType;
	}
	if ( LboxListview::ColumnSize != NULL ) {
		delete LboxListview::ColumnSize;
	}
	delete LboxListview::Buffer;
}
  



  AddColumn

  
// *********************************************************
// リストビューに列追加
// 戻り値 : 無し
// *********************************************************
void LboxListview::AddColumn(
int nFmt, int nWidth, LboxString *LString
)
{
	LboxListview::AddColumn(
		nFmt,
		nWidth,
		LString->szLboxString
	);
}
void LboxListview::AddColumn(
int nFmt, int nWidth, LPTSTR szTitle
)
{
	int nCol;
	LV_COLUMN col;

	ZeroMemory( &col, sizeof( LV_COLUMN ) );
	col.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;

	col.fmt = nFmt;
	col.cx = nWidth;
	col.pszText = szTitle;
	nCol = LboxListview::ColumnCount( );
	ListView_InsertColumn(hWnd, nCol, &col);
}
  



  GetColumnTitle

  
// *********************************************************
// リストビューの列のタイトルを取得
// 戻り値 : 無し
// *********************************************************
void LboxListview::GetColumnTitle( int nCol, LboxString *LString )
{
	int nLen;

	while( 1 ) {
		LboxListview::GetColumnTitle(
			nCol,
			LString->szLboxString,
			LString->nLboxString
		);
		nLen = lstrlen( LString->szLboxString );
		if ( nLen >= (int)(LString->nLboxString) - 2 ) {
			if ( LString->nLboxString > LBOX_STRINGMAX ) {
				break;
			}
			LString->Resize( LString->nLboxString + MAX_PATH );
			continue;
		}
		break;
	}
}
void LboxListview::GetColumnTitle( int nCol, LPTSTR szBuffer, int nSize )
{
	LV_COLUMN col;

	ZeroMemory( &col, sizeof( LV_COLUMN ) );
	col.mask = LVCF_TEXT;

	col.pszText = szBuffer;
	col.cchTextMax = nSize;

	ListView_GetColumn(
		this->hWnd,
		nCol,
		&col
	);
}
  



  SetColumnTitle

  
// *********************************************************
// リストビューの列のタイトルを設定
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetColumnTitle( int nCol, LboxString *LString )
{
	LboxListview::SetColumnTitle( nCol, LString->szLboxString );
}
void LboxListview::SetColumnTitle( int nCol, LPTSTR szBuffer )
{
	LV_COLUMN col;

	ZeroMemory( &col, sizeof( LV_COLUMN ) );
	col.mask = LVCF_TEXT;

	col.pszText = szBuffer;

	ListView_SetColumn(
		this->hWnd,
		nCol,
		&col
	);
}
  



  ShowColumnHeader

  
// *********************************************************
// カラムヘッダーの表示・非表示
// 戻り値 : 無し
// *********************************************************
void LboxListview::ShowColumnHeader( BOOL bShow )
{
	if ( bShow ) {
		LboxRemoveWindowStyle(
			LboxListview::hWnd,
			LVS_NOCOLUMNHEADER
		);
	}
	else {
		LboxAddWindowStyle(
			LboxListview::hWnd,
			LVS_NOCOLUMNHEADER
		);
	}
}
  



  AddRow

  
// *********************************************************
// リストビューに行追加
// 戻り値 : 追加された行。エラーの場合は -1
// *********************************************************
int LboxListview::AddRow( void )
{
	int nLastRow;

	nLastRow = LboxListview::Count();
	LboxListview::nCurrentRow = nLastRow;
	return LboxListview::InsertRow( nLastRow );
}
  



  Count

  
// *********************************************************
// リストビューの行数取得
// 戻り値 : 行数
// *********************************************************
int LboxListview::Count( void )
{
	return ListView_GetItemCount(
		LboxListview::hWnd
	);
}
  



  DeleteRow

  
// *********************************************************
// リストビューの行を削除
// 戻り値 : 無し
// *********************************************************
void LboxListview::DeleteRow( int nRow )
{
	ListView_DeleteItem(
		LboxListview::hWnd,
		nRow
	);
}
  



  FindNextRow

  
// *********************************************************
// 行の検索
// 戻り値 : true 行発見, false 対象行無し
// 初回は、nRow に -1 を渡す
// *********************************************************
BOOL LboxListview::FindNextRow( int *nRow )
{
	int nRows;

	nRows = LboxListview::Count();
	
	if ( (*nRow) + 1 < nRows ) {
		(*nRow)++;
		LboxListview::nCurrentRow = (*nRow);
		return true;
	}

	return false;
}
  



  FindNextSelectedRow

  
// *********************************************************
// 選択された行の検索
// 戻り値 : true 行発見, false 対象行無し
// 初回は、nRow に -1 を渡す
// *********************************************************
BOOL LboxListview::FindNextSelectedRow( int *nRow )
{
	int nRows,i;

	nRows = LboxListview::Count();
	
	for( i = (*nRow) + 1; i < nRows; i++ ) {
		if ( LboxListview::IsState( i, LVIS_SELECTED ) ) {
			*nRow = i;
			LboxListview::nCurrentRow = i;
			return true;
		}
	}

	return false;
}
  



  InsertRow

  
// *********************************************************
// リストビューに行挿入
// 戻り値 : 挿入された行。エラーの場合は -1
// *********************************************************
int LboxListview::InsertRow( int nRow )
{
#if CODING == 1
	LVITEMA row;
#else
	LV_ITEM row;
#endif
	
	ZeroMemory( &row, sizeof( LV_ITEM ) );
	row.mask		= LVIF_TEXT;
	row.pszText		= "";
	row.iItem		= nRow;
	LboxListview::nCurrentRow = nRow;

	return ListView_InsertItem(
		LboxListview::hWnd,
		&row
	);
}
  



  IsState

  
// *********************************************************
// 状態のチェック
// 戻り値 : true その状態である, false その状態でない
// LVIS_FOCUSED : フォーカスがある
// LVIS_SELECTED : 選択されている
// *********************************************************
BOOL LboxListview::IsState( int nRow, UINT uFlg )
{
	UINT uRet;

	uRet = ListView_GetItemState(
		LboxListview::hWnd,
		nRow,
		uFlg		
	);
	if ( uRet & uFlg ) {
		return true;
	}
	return false;
}
  



  SetCurrentRow

  
// *********************************************************
// リストビューの内部カレント行を設定
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetCurrentRow( int nRow )
{
	LboxListview::nCurrentRow = nRow;
}
  



  SetSelect

  
// *********************************************************
// 行の選択状態の変更
// 戻り値 : 無し
// bFlg が true ならば選択、false ならば選択解除
// *********************************************************
void LboxListview::SetSelect( int nRow, BOOL bFlg )
{
	if ( bFlg ) {
		ListView_SetItemState(
			LboxListview::hWnd,
			nRow,
			LVIS_SELECTED,
			LVIS_SELECTED
		);
	}
	else {
		ListView_SetItemState(
			LboxListview::hWnd,
			nRow,
			0,
			LVIS_SELECTED
		);
	}
}
  



  ColumnCount

  
// *********************************************************
// リストビューの列数取得
// 戻り値 : 列数
// *********************************************************
int LboxListview::ColumnCount( void )
{
	int i;
#if CODING == 1
	LVCOLUMNA test;
#else
	LV_COLUMN test;
#endif

	ZeroMemory( &test, sizeof( LV_COLUMN ) );
	test.mask = LVCF_FMT;

	i = 0;
	while( 1 ) {
		if ( !ListView_GetColumn( hWnd, i, &test ) ) {
			break;
		}
		i++;
		if ( i > 100 ) {
			break;
		}
	}
	return i;
}
  



  DeleteColumn

  
// *********************************************************
// リストビューの列を削除
// 戻り値 : 無し
// *********************************************************
void LboxListview::DeleteColumn( int nCol )
{
	ListView_DeleteColumn(
		LboxListview::hWnd,
		nCol
	);
}
  



  GetColumnText

  
// *********************************************************
// リストビューの列のテキストを取得
// 戻り値 : 無し
// *********************************************************
void LboxListview::GetColumnText( int nCol, LboxString *LString )
{
	int nLen;

	while( 1 ) {
		LboxListview::GetColumnText(
			nCol,
			LString->szLboxString,
			LString->nLboxString
		);
		nLen = lstrlen( LString->szLboxString );
		if ( nLen >= (int)(LString->nLboxString) - 2 ) {
			if ( LString->nLboxString > LBOX_STRINGMAX ) {
				break;
			}
			LString->Resize( LString->nLboxString + MAX_PATH );
			continue;
		}
		break;
	}

}
void LboxListview::GetColumnText( int nCol, LPTSTR szBuffer, int nSize )
{
	ListView_GetItemText(
		this->hWnd,
		LboxListview::nCurrentRow,
		nCol,
		szBuffer,
		nSize
	)
}
  



  GetColumnWidth

  
// *********************************************************
// リストビューの列の幅を取得
// 戻り値 : 列の幅
// *********************************************************
int LboxListview::GetColumnWidth( int nCol )
{
	return ListView_GetColumnWidth(
		LboxListview::hWnd,
		nCol
	);
}
  



  InsertColumn

  
// *********************************************************
// リストビューに列挿入
// 戻り値 : 無し
// nFmt 用定数
// LVCFMT_CENTER : 中央
// LVCFMT_LEFT   : 左寄せ
// LVCFMT_RIGHT  : 右寄せ
// *********************************************************
void LboxListview::InsertColumn(
int nCol, int nFmt, int nWidth, LboxString *LString
)
{
	LboxListview::InsertColumn(
		nCol,
		nFmt,
		nWidth,
		LString->szLboxString
	);
}
void LboxListview::InsertColumn(
int nCol, int nFmt, int nWidth, LPTSTR szTitle
)
{
	LV_COLUMN col;

	ZeroMemory( &col, sizeof( LV_COLUMN ) );
	col.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;

	col.fmt = nFmt;
	col.cx = nWidth;
	col.pszText = szTitle;
	ListView_InsertColumn(hWnd, nCol, &col);
}
  



  LoadColumnText

  
// *********************************************************
// リストビューのカラムデータをエディットコントロールにセット
// 戻り値 : 無し
// *********************************************************
void LboxListview::LoadColumnText( int nRow, int nCol )
{
	if ( nRow == -1 ) {
		return;
	}

	char *szBuffer = new char[512];

	Buffer->Printf( "%d", nCol );
	if ( Buffer->Case( LboxListview::lpSkipColumn ) ) {
		delete [] szBuffer;
		return;
	}

	ListView_GetItemText(
		this->hWnd,
		nRow,
		nCol,
		szBuffer,
		512
	);
	SetWindowText( LboxListview::hEdit, szBuffer );

	RECT rt;

	ListView_GetSubItemRect(
		this->hWnd,
		nRow,
		nCol,
		LVIR_LABEL,
		&rt
	);
	LboxMoveWindow(
		LboxListview::hEdit,
		rt.left,
		rt.top-2
	);
	LboxChangeWindowSize(
		LboxListview::hEdit,
		rt.right - rt.left,
		rt.bottom - rt.top + 3
	);
	ShowWindow( LboxListview::hEdit, SW_SHOW );
	::SetFocus( LboxListview::hEdit );

	nEditRow = nRow;
	nEditCol = nCol;

	LboxEditNumberonly( LboxListview::hEdit, false );
	LboxEditLimitText( LboxListview::hEdit, 0 );

	int nType,nSize;
	nType = 0;
	nSize = 0;
	LboxToken *Token;
	Token = new LboxToken();
	LboxString *LString;
	LString = new LboxString();
	if ( LboxListview::ColumnType != NULL ) {
		Token->CreateToken( LboxListview::ColumnType->szLboxString, "," );
		if ( Token->nCount >= nCol ) {
			LString->operator = ( Token->Token[nCol] );
			nType = LString->Atoi();
		}
	}
	if ( LboxListview::ColumnSize != NULL ) {
		Token->CreateToken( LboxListview::ColumnSize->szLboxString, "," );
		if ( Token->nCount >= nCol ) {
			LString->operator = ( Token->Token[nCol] );
			nSize = LString->Atoi();
		}
	}
	delete LString;
	delete Token;
	if ( nType == 1 ) {
		LboxEditNumberonly( LboxListview::hEdit, true );
	}
	LboxEditLimitText( LboxListview::hEdit, nSize );

	delete [] szBuffer;
}
void LboxListview::LoadColumnText( int nRow, int nCol, int nType, int nSize )
{
	LboxListview::LoadColumnText( nRow, nCol );
	if ( nType == 1 ) {
		LboxEditNumberonly( LboxListview::hEdit, true );
	}
	LboxEditLimitText( LboxListview::hEdit, nSize );

}
  



  SetColumnText

  
// *********************************************************
// リストビューの列のテキストを設定
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetColumnText( int nCol, LboxString *LString )
{
	LboxListview::SetColumnText( nCol, LString->szLboxString );
}
void LboxListview::SetColumnText( int nCol, LPTSTR szBuffer )
{
	ListView_SetItemText(
		this->hWnd,
		LboxListview::nCurrentRow,
		nCol,
		szBuffer
	)
}
  



  SetColumnWidth

  
// *********************************************************
// リストビューの列の幅を設定
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetColumnWidth( int nCol, int nSize )
{
	ListView_SetColumnWidth(
		LboxListview::hWnd,
		nCol,
		nSize
	);
}
  



  Notify

  
// *********************************************************
// WM_NOTIFYメッセージ用ポスト関数
// 戻り値 : 無し
// *********************************************************
void LboxListviewNotifyPost(
UINT message, HWND hTarget, HWND hLview, int nRow, int nCol )
{
	switch( message ) {
		case NM_RCLICK:
			PostMessage(
				hTarget,
				LBOX_LV_RCLICK,
				(WPARAM)hLview,
				(LPARAM)(MAKELPARAM(nRow,nCol))
			);
			break;
		case NM_DBLCLK:
			PostMessage(
				hTarget,
				LBOX_LV_DBLCLK,
				(WPARAM)hLview,
				(LPARAM)(MAKELPARAM(nRow,nCol))
			);
			break;
		case NM_RDBLCLK:
			PostMessage(
				hTarget,
				LBOX_LV_RDBLCLK,
				(WPARAM)hLview,
				(LPARAM)(MAKELPARAM(nRow,nCol))
			);
			break;
		case NM_CLICK:
			PostMessage(
				hTarget,
				LBOX_LV_CLICK,
				(WPARAM)hLview,
				(LPARAM)(MAKELPARAM(nRow,nCol))
			);
			break;
		case NM_RETURN:
			PostMessage(
				hTarget,
				LBOX_LV_RETURN,
				(WPARAM)hLview,
				(LPARAM)(MAKELPARAM(nRow,nCol))
			);
			break;
		case NM_SETFOCUS:
			PostMessage(
				hTarget,
				LBOX_LV_SETFOCUS,
				(WPARAM)hLview,
				0
			);
			break;
		case NM_KILLFOCUS:
			PostMessage(
				hTarget,
				LBOX_LV_KILLFOCUS,
				(WPARAM)hLview,
				0
			);
			break;
	}

}

// *********************************************************
// WM_NOTIFYメッセージを取得してユーザメッセージを送る
// 戻り値 : メッセージ( 0 の時は対象外 )
// *********************************************************
UINT LboxListview::Notify( HWND hTarget, LPARAM lParam )
{
	HWND hLv;
	LPNMLISTVIEW lpNmlv;
	int nRow;

	lpNmlv = (LPNMLISTVIEW)lParam;
	hLv = lpNmlv->hdr.hwndFrom;

	// メッセ−ジがこのオブジェクトである場合
	if ( hLv == this->hWnd ) {

		LboxListview::Action = lpNmlv->hdr.code;
		LboxListview::hCurrent = lpNmlv->hdr.hwndFrom;
		LboxListview::nCurrentId = lpNmlv->hdr.idFrom;

		if ( LboxListview::Action == NM_RCLICK ) {
			LboxListview::nCurrentCol = lpNmlv->iSubItem;
			LboxListview::nCurrentRow = lpNmlv->iItem;
			LboxListviewNotifyPost(
				LboxListview::Action,
				hTarget,
				hLv,
				LboxListview::nCurrentRow,
				LboxListview::nCurrentCol
			);
			if ( LboxListview::hMenu != NULL ) {
				HMENU hPopup;

				hPopup = GetSubMenu(
					LboxListview::hMenu,
					LboxListview::nCurrentPopup
				);
				LboxWintool::ClientToScreen(
					&lpNmlv->ptAction
				);
				TrackPopupMenu(
					hPopup,
					TPM_LEFTALIGN | TPM_TOPALIGN,
					lpNmlv->ptAction.x,
					lpNmlv->ptAction.y,
					0,
					hTarget,
					NULL
				);
			}
			return lpNmlv->hdr.code;
		}

		switch( LboxListview::Action ) {
			case NM_DBLCLK:
			case NM_RDBLCLK:
			case NM_CLICK:
				LboxListview::nCurrentCol = lpNmlv->iSubItem;
				LboxListview::nCurrentRow = lpNmlv->iItem;
				break;
			case NM_RETURN:
				LboxListview::nCurrentCol = 0;
				nRow = -1;
				LboxListview::FindNextSelectedRow( &nRow );
				break;
		}

		LboxListviewNotifyPost(
			LboxListview::Action,
			hTarget,
			hLv,
			LboxListview::nCurrentRow,
			LboxListview::nCurrentCol
		);
		return lpNmlv->hdr.code;
	}

	return 0;
}
  

使用例

  
// リストビューの通知イベント
case WM_NOTIFY:
	if ( Table != NULL ) {
		Table->Notify( hWnd, lParam );
	}
	break;

case LBOX_LV_DBLCLK:
	if ( Table->IsHandle( (HWND)wParam ) ) {
		// 行が選択されている
		if ( LVROW(lParam) != -1 ) {
		}
	}
	break;
  



  CreatePopup

  
// *********************************************************
// ポップアップメニューの実装
// 戻り値 : 無し
// *********************************************************
void LboxListview::CreatePopup( DWORD mId, int nPos )
{
	if ( LboxListview::hMenu != NULL ) {
		DestroyMenu( LboxListview::hMenu );
	}
	LboxListview::hMenu = 
		LoadMenu(
		LboxGetInstance( LboxListview::hWnd ),
			MAKEINTRESOURCE(mId)
		);

	LboxListview::nCurrentPopup = nPos;
}
  



  SelectPopup

  
// *********************************************************
// ポップアップメニューの選択
// 戻り値 : 無し
// *********************************************************
void LboxListview::SelectPopup( int nPos )
{
	LboxListview::nCurrentPopup = nPos;
}
  



  GetInfo

  
// *********************************************************
// 情報の取得
// 戻り値 : 情報構造体メンバ変数へのポインタ
// *********************************************************
LBOXLISTVIEWINFO *LboxListview::GetInfo( void )
{
	LboxListview::llvi.nCurVisibleTopIndex = 
		ListView_GetTopIndex( LboxListview::hWnd );

	LboxListview::llvi.nVisibleCountPerPage = 
		ListView_GetCountPerPage( LboxListview::hWnd );

	LboxListview::llvi.nSelectedCount = 
		ListView_GetSelectedCount( LboxListview::hWnd );

	LboxListview::llvi.cBkColor = 
		ListView_GetBkColor( LboxListview::hWnd );

	LboxListview::llvi.cTextBkColor = 
		ListView_GetTextBkColor( LboxListview::hWnd );

	LboxListview::llvi.cTextColor = 
		ListView_GetTextColor( LboxListview::hWnd );

	return &(LboxListview::llvi);
}
  



  CopyClipboard

  
char *szTag1 = "<TABLE >";
char *szTag2 = "<TR>";
char *szTag3 = "</TR>";
char *szTag4 = "<TD>";
char *szTag5 = "</TD>";
char *szTag6 = "</TABLE>";
char *szTag7 = "<TH>";
char *szTag8 = "</TH>";
// *********************************************************
// クリップボードにコピー
// 行の終わりには、改行コードを付加
// bSelect が true の場合は 選択した行のみコピーする
// bTitle が true の場合は、タイトルもコピーする
// nType
//  0 : タブ
//  1 : カンマ(CSV)
//  3 : \
//  4 : HTML テーブルタグ
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxListview::CopyClipboard( BOOL bSelect, BOOL bTitle, int nType )
{
	DWORD nRows,nCols;
	DWORD nSize;
	DWORD i;
	char *szBuffer = new char[MAX_PATH];

	if ( nType < 0 || nType > 3 ) {
		return false;
	}
	char delim[3][4];
	lstrcpy( delim[0], "\t" );
	lstrcpy( delim[1], "," );
	lstrcpy( delim[2], "\\" );

	nRows = LboxListview::Count();
	nCols = LboxListview::ColumnCount();

	nSize = 0;
	if ( bTitle ) {
		for( i = 0; i < nCols; i++ ) {
			LboxListview::GetColumnTitle(
				i,
				szBuffer,
				MAX_PATH
			);
			nSize += lstrlen( szBuffer );
			nSize++;
			if ( nType == 3 ) {
				nSize += lstrlen( szTag7 );
				nSize += lstrlen( szTag8 );
			}
		}
		nSize++;
		if ( nType == 3 ) {
			nSize += lstrlen( szTag2 );
			nSize += lstrlen( szTag3 );
		}
	}

	int nRow;
	nRow = -1;
	while( LboxListview::FindNextRow( &nRow ) ) {
		if ( bSelect ) {
			if ( false == LboxListview::IsState(
				nRow,
				LVIS_SELECTED
				) ) {
				continue;
			}
		}
		for( i = 0; i < nCols; i++ ) {
			LboxListview::GetColumnText(
				i,
				szBuffer,
				MAX_PATH
			);
			nSize += lstrlen( szBuffer );
			nSize++;
			if ( nType == 3 ) {
				nSize += lstrlen( szTag4 );
				nSize += lstrlen( szTag5 );
			}
		}
		nSize++;
		if ( nType == 3 ) {
			nSize += lstrlen( szTag2 );
			nSize += lstrlen( szTag3 );
		}
	}

	if ( nType == 3 ) {
		nSize += lstrlen( szTag1 );
		nSize += lstrlen( szTag6 );
	}

	HGLOBAL hGlobal;
	LPTSTR pMem;

	hGlobal = GlobalAlloc(GHND, nSize + 128 );
	if ( hGlobal == NULL ) {
		return false;
	}
	pMem = (LPTSTR)GlobalLock( hGlobal );
	if ( pMem == NULL ) {
		GlobalFree( hGlobal );
		return false;
	}
	
	*pMem = 0x00;

	if ( nType == 3 ) {
		lstrcat( pMem, szTag1 );
	}

	if ( bTitle ) {
		if ( nType == 3 ) {
			lstrcat( pMem, szTag2 );
		}
		for( i = 0; i < nCols; i++ ) {
			if ( nType == 3 ) {
				lstrcat( pMem, szTag7 );
			}
			else {
				if ( i != 0 ) {
					lstrcat( pMem, delim[nType] );
				}
			}
			LboxListview::GetColumnTitle(
				i,
				szBuffer,
				MAX_PATH
			);
			lstrcat( pMem, szBuffer );
			if ( nType == 3 ) {
				lstrcat( pMem, szTag8 );
			}
		}
		if ( nType == 3 ) {
			lstrcat( pMem, szTag3 );
		}
		lstrcat( pMem, "\n" );
		pMem += lstrlen( pMem );;
	}

	nRow = -1;
	while( LboxListview::FindNextRow( &nRow ) ) {
		if ( bSelect ) {
			if ( false == LboxListview::IsState(
				nRow,
				LVIS_SELECTED
				) ) {
				continue;
			}
		}
		if ( nType == 3 ) {
			lstrcat( pMem, szTag2 );
		}
		for( i = 0; i < nCols; i++ ) {
			if ( nType == 3 ) {
				lstrcat( pMem, szTag4 );
			}
			else {
				if ( i != 0 ) {
					lstrcat( pMem, delim[nType] );
				}
			}
			LboxListview::GetColumnText(
				i,
				szBuffer,
				MAX_PATH
			);
			lstrcat( pMem, szBuffer );
			if ( nType == 3 ) {
				lstrcat( pMem, szTag5 );
			}
		}
		if ( nType == 3 ) {
			lstrcat( pMem, szTag3 );
		}
		lstrcat( pMem, "\n" );
		pMem += lstrlen( pMem );;
	}

	if ( nType == 3 ) {
		lstrcat( pMem, szTag6 );
	}

	GlobalUnlock( hGlobal );
	OpenClipboard( NULL );
	EmptyClipboard();
	SetClipboardData(CF_TEXT, hGlobal);
	CloseClipboard();

	delete [] szBuffer;

	return true;
}
  



  Fit

  
// *********************************************************
// カラム幅とデータ幅との調整
// 戻り値 : 無し
// *********************************************************
void LboxListview::Fit( int nCol )
{
	ListView_SetColumnWidth(
		this->hWnd,
		nCol,
		LVSCW_AUTOSIZE_USEHEADER  
	);
	return;
}
void LboxListview::Fit( void )
{
	int nCols,i;

	nCols = LboxListview::ColumnCount();
	for( i = 0; i < nCols; i++ ) {
		ListView_SetColumnWidth(
			this->hWnd,
			i,
			LVSCW_AUTOSIZE_USEHEADER  
		);
	}
}
  



  Grid

  
// *********************************************************
// リストビューをグリッドにする
// 戻り値 : 無し
// *********************************************************
void LboxListview::Grid( void )
{
	ListView_SetExtendedListViewStyle(
		LboxListview::hWnd,
		LVS_EX_GRIDLINES | 
		LVS_EX_FULLROWSELECT |
		LVS_EX_SUBITEMIMAGES
	);
}
  



  Initialize

  
// *********************************************************
// リストビューの行と列の初期化
// 戻り値 : 無し
// *********************************************************
void LboxListview::Initialize( void )
{
	LboxListview::Reset();

	int i,nCols;

	nCols = LboxListview::ColumnCount();
	
	for( i = 0; i < nCols; i++ ) {
		LboxListview::DeleteColumn( 0 );
	}
	LboxListview::Rowid = 0;

}
  



  ParentFit

  
// *********************************************************
// 親ウインドウにフィットさせる
// 戻り値 : 無し
// *********************************************************
void LboxListview::ParentFit( DWORD dwSizeType,
	int x, int y, int sub_h, int sub_w )
{
	HWND hParent;
	RECT rt;

	if ( dwSizeType == SIZE_RESTORED || SIZE_MAXIMIZED ) {
		hParent = GetParent( LboxListview::hWnd );
		if ( hParent != NULL ) {
			GetClientRect( hParent, &rt );
			LboxMoveWindow( LboxListview::hWnd, x, y );
			LboxChangeWindowSize(
				LboxListview::hWnd,
				rt.right - x - sub_w,
				rt.bottom - y - sub_h
			);
		}
	}
}
  



  Reset

  
// *********************************************************
// リストビューの行を全て削除
// 戻り値 : 無し
// *********************************************************
void LboxListview::Reset( void )
{
	ListView_DeleteAllItems(
		this->hWnd
	);
	LboxListview::Rowid = 0;
}
  



  Scroll

  
// *********************************************************
// 指定行、指定カラムを表示位置にスクロール
// 戻り値 : 無し
// *********************************************************
void LboxListview::Scroll( int nRow, int nCol )
{
	POINT pt;
	int i,nWidth;
	RECT rt;

	ListView_GetItemPosition(
		LboxListview::hWnd,
		nRow-1,
		&pt
	);		

	ListView_GetViewRect( 
		LboxListview::hWnd,
		&rt
	);

	nWidth = -1024;
	ListView_Scroll(
		LboxListview::hWnd,
		-1024,
		0
	);

	nWidth = 0;
	for( i = 0; i < nCol; i++ ) {
		nWidth += LboxListview::GetColumnWidth( i );
	}
	ListView_Scroll(
		LboxListview::hWnd,
		nWidth,
		pt.y
	);
}
  



  SetFont

  
// *********************************************************
// フォントのセット
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxListview::SetFont( int nType, int nSize, BOOL bBold )
{
	if ( LboxListview::hFont != NULL ) {
		DeleteObject( LboxListview::hFont );
	}
	LboxListview::hFont = LboxCreateFont(
		nType,
		nSize,
		bBold
	);
	if ( LboxListview::hFont == NULL ) {
		return false;
	}

	SendMessage(
		this->hWnd,
		WM_SETFONT,
		(WPARAM)(LboxListview::hFont),
		MAKELPARAM(true, 0)
	);

	if ( LboxListview::hEdit != NULL ) {
		SendMessage( LboxListview::hEdit,
			WM_SETFONT,
			(WPARAM)(LboxListview::hFont),
			0
		);
	}
	if ( LboxListview::hCombo != NULL ) {
		SendMessage( LboxListview::hCombo,
			WM_SETFONT,
			(WPARAM)(LboxListview::hFont),
			0
		);
	}

	return true;
}
  



  SetSelectAll

  
// *********************************************************
// 全ての行の選択状態の変更
// 戻り値 : 無し
// bFlg が true ならば選択、false ならば選択解除
// *********************************************************
void LboxListview::SetSelectAll( BOOL bFlg )
{
	int nRow;
	nRow = -1;
	while( LboxListview::FindNextRow( &nRow ) ) {
		LboxListview::SetSelect( nRow, bFlg );
	}
}
  



  SetImageList

  
// *********************************************************
// イメージリストを実装する
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetImageList( LboxImagelist *obj )
{
	ListView_SetImageList(
		this->hWnd,
		obj->hImgList,
		LVSIL_SMALL 
	);
}
  



  SetImage

  
// *********************************************************
// リストビューのカラムにイメージを追加
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetImage(
int nTargetRow, int nTargetCol, int nImage )
{
	LVITEM lvi;

	ZeroMemory( &lvi, sizeof( LVITEM ) );
	lvi.mask = LVIF_IMAGE;
	lvi.iItem = nTargetRow;
	lvi.iSubItem = nTargetCol;
	lvi.iImage = nImage;

	ListView_SetItem( LboxListview::hWnd, &lvi );
}
  



  LoadColumnTextCombo

  
// *********************************************************
// リストビューのカラムデータをコンボボックスにセット
// 戻り値 : 無し
// *********************************************************
void LboxListview::LoadColumnTextCombo( int nRow, int nCol )
{
	if ( nRow == -1 ) {
		return;
	}

	char *szBuffer = new char[512];

	Buffer->Printf( "%d", nCol );

	ListView_GetItemText(
		this->hWnd,
		nRow,
		nCol,
		szBuffer,
		512
	);

	int nComboRow;
	nComboRow = LboxComboFindString( LboxListview::hCombo, szBuffer );
	LboxComboSelect( LboxListview::hCombo, nComboRow );

	RECT rt,rtCombo;

	ListView_GetSubItemRect(
		this->hWnd,
		nRow,
		nCol,
		LVIR_LABEL,
		&rt
	);
	LboxMoveWindow(
		LboxListview::hCombo,
		rt.left,
		rt.top-3
	);
	GetWindowRect(
		LboxListview::hCombo,
		&rtCombo
	);
	LboxChangeWindowSize(
		LboxListview::hCombo,
		rt.right - rt.left,
		rtCombo.bottom - rtCombo.top
	);
	LboxComboSetHeight(
		LboxListview::hCombo,
		(LPARAM)(rt.bottom - rt.top)
	);

	ShowWindow( LboxListview::hCombo, SW_SHOW );
	::SetFocus( LboxListview::hCombo );

	nEditRow = nRow;
	nEditCol = nCol;

	delete [] szBuffer;
}
  



  LoadColumnTextNext

  
// *********************************************************
// リストビューのカラムデータを次のエディットコントロールにセット
// 戻り値 : 無し
// *********************************************************
void LboxListview::LoadColumnTextNext( void )
{
	int nRowCount,nColCount;
	int nRow,nCol;
	BOOL bBreak;
	int nType,nSize;

	LboxListview::HideEdit( );
	nRowCount = LboxListview::Count();
	nColCount = LboxListview::ColumnCount();

	nRow = LboxListview::nEditRow;
	nCol = LboxListview::nEditCol + 1;
	bBreak = false;
	while( 1 ) {
		if ( bBreak ) {
			break;
		}
		if ( nRow + 1 > nRowCount ) {
			nRow = 0;
			continue;
		}
		while( 1 ) {
			if ( nCol + 1 > nColCount ) {
				nCol = 0;
				break;
			}
			Buffer->Printf( "%d", nCol );
			if ( Buffer->Case( LboxListview::lpSkipColumn ) ) {
				nCol++;
				continue;
			}

			nType = 0;
			nSize = 0;
			LboxToken *Token;
			Token = new LboxToken();
			LboxString *LString;
			LString = new LboxString();
			if ( LboxListview::ColumnType != NULL ) {
				Token->CreateToken(
					LboxListview::ColumnType->szLboxString, "," );
				if ( Token->nCount >= nCol ) {
					LString->operator = ( Token->Token[nCol] );
					nType = LString->Atoi();
				}
			}
			if ( LboxListview::ColumnSize != NULL ) {
				Token->CreateToken(
					LboxListview::ColumnSize->szLboxString, "," );
				if ( Token->nCount >= nCol ) {
					LString->operator = ( Token->Token[nCol] );
					nSize = LString->Atoi();
				}
			}
			delete LString;
			delete Token;
			LboxListview::LoadColumnText( nRow, nCol, nType, nSize );

			bBreak = true;
			break;
		}
		nRow++;
	}

}
  



  SetSkipColumn

  
// *********************************************************
// カラムの非編集対象bフリスト文字列をセット
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetSkipColumn( LPTSTR lpTarget )
{
	LboxListview::lpSkipColumn = lpTarget;
}
  



  SetColumnType

  
// *********************************************************
// カラムのタイプの設定
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetColumnType( LPTSTR lpType )
{
	if ( LboxListview::ColumnType != NULL ) {
		delete LboxListview::ColumnType;
	}
	LboxListview::ColumnType = new LboxString( lpType );
}
  



  SetColumnSize

  
// *********************************************************
// カラムのサイズの設定
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetColumnSize( LPTSTR lpSize )
{
	if ( LboxListview::ColumnSize != NULL ) {
		delete LboxListview::ColumnSize;
	}
	LboxListview::ColumnSize = new LboxString( lpSize );
}
  



  SetBkColor

  
// *********************************************************
// 背景色を設定する
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetBkColor( COLORREF clrBk )
{
	ListView_SetBkColor(
		this->hWnd,
		clrBk		
	);		
	ListView_SetTextBkColor(
		this->hWnd,
		clrBk		
	);		

}
  



  SetComboData

  
// *********************************************************
// 内部コンボボックスのリストボックスにデータを設定
// lpData にセットしたいデータをカンマ区切りでセット
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetComboData( LboxString *LString )
{
	LboxListview::SetComboData( LString->szLboxString );
}
void LboxListview::SetComboData( LPTSTR lpData )
{
	LboxToken *Ltoken = new LboxToken(	);

	Ltoken->CreateToken( lpData, "," );

	int i;
	LboxComboReset( LboxListview::hCombo );
	for( i = 0; i < Ltoken->nCount; i++ ) {
		LboxComboAdd(
			LboxListview::hCombo,
			Ltoken->Token[i]
		);
	}

	delete Ltoken;
}
  



  SetComboWidth

  
// *********************************************************
// 内部コンボボックスのリストボックス部分の幅設定
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetComboWidth( int nWidth )
{
	LboxComboSetWidth(
		LboxListview::hCombo,
		nWidth
	);
}
  



  ApplyCheckbox

  
// *********************************************************
// チェックボックスの実装を設定・解除する
// 戻り値 : 無し
// *********************************************************
void LboxListview::ApplyCheckbox( BOOL bFlg )
{
	if ( bFlg ) {
		ListView_SetExtendedListViewStyleEx(
			LboxListview::hWnd,
			LVS_EX_CHECKBOXES,
			LVS_EX_CHECKBOXES
		);
	}
	else {
		ListView_SetExtendedListViewStyleEx(
			LboxListview::hWnd,
			LVS_EX_CHECKBOXES,
			0
		);
	}
}
  



  GetCheck

  
// *********************************************************
// チェックボックスの状態を取得する
// 戻り値 : 無し
// *********************************************************
BOOL LboxListview::GetCheck( int nIndex )
{
	return ListView_GetCheckState(
		LboxListview::hWnd,
		nIndex
	);
}
  



  SetCheck

  
// *********************************************************
// チェックボックスをONまたはOFFにセットする
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetCheck( int nIndex, BOOL bFlg )
{
	ListView_SetCheckState(
		LboxListview::hWnd,
		nIndex,
		bFlg
	);
  



  Sort

  
// *********************************************************
// ソート
// nOrder
// 0 : 順ソート, 1 : 逆ソート
// 戻り値 : 無し
// *********************************************************
void LboxListview::Sort( int nColumn, int nOrder )
{
	LBOXLISTVIEWSORT lvsort;
	lvsort.hWnd = this->hWnd;
	lvsort.nColumn = nColumn;
	lvsort.nOrder = nOrder;
	ListView_SortItems(
		this->hWnd, 		
		(PFNLVCOMPARE)(LboxListview::SortProc),
		(LPARAM)&lvsort
	);		
}
  



  HideEdit

  
// *********************************************************
// 編集用エディトコントロールを非表示にする
// 戻り値 : 無し
// *********************************************************
void LboxListview::HideEdit( void )
{
	ShowWindow( LboxListview::hEdit, SW_HIDE );
}
  



  GetImage

  
// *********************************************************
// リストビューのカラムのイメージ番号を取得
// 戻り値 : 無し
// *********************************************************
int LboxListview::GetImage(
int nTargetRow, int nTargetCol )
{
	LVITEM lvi;

	ZeroMemory( &lvi, sizeof( LVITEM ) );
	lvi.mask = LVIF_IMAGE;
	lvi.iItem = nTargetRow;
	lvi.iSubItem = nTargetCol;

	ListView_GetItem( this->hWnd, &lvi );

	return lvi.iImage;
}
  



  GetColumnTextNext

  
// *********************************************************
// リストビューのカラムデータを次のエディットコントロールにセット
// 戻り値 : 無し
// *********************************************************
void LboxListview::GetColumnTextNext(
	int *pRow, int *pCol, int *pType, int *pSize )
{
	int nRowCount,nColCount;
	int nRow,nCol;
	BOOL bBreak;
	int nType,nSize;

	LboxListview::HideEdit( );
	nRowCount = LboxListview::Count();
	nColCount = LboxListview::ColumnCount();

	nRow = LboxListview::nEditRow;
	nCol = LboxListview::nEditCol + 1;
	bBreak = false;
	while( 1 ) {
		if ( bBreak ) {
			break;
		}
		if ( nRow + 1 > nRowCount ) {
			nRow = 0;
			continue;
		}
		while( 1 ) {
			if ( nCol + 1 > nColCount ) {
				nCol = 0;
				break;
			}
			Buffer->Printf( "%d", nCol );
			if ( Buffer->Case( LboxListview::lpSkipColumn ) ) {
				nCol++;
				continue;
			}

			nType = 0;
			nSize = 0;
			LboxToken *Token;
			Token = new LboxToken();
			LboxString *LString;
			LString = new LboxString();
			if ( LboxListview::ColumnType != NULL ) {
				Token->CreateToken(
					LboxListview::ColumnType->szLboxString, "," );
				if ( Token->nCount >= nCol ) {
					LString->operator = ( Token->Token[nCol] );
					nType = LString->Atoi();
				}
			}
			if ( LboxListview::ColumnSize != NULL ) {
				Token->CreateToken(
					LboxListview::ColumnSize->szLboxString, "," );
				if ( Token->nCount >= nCol ) {
					LString->operator = ( Token->Token[nCol] );
					nSize = LString->Atoi();
				}
			}
			delete LString;
			delete Token;

			*pRow = nRow;
			*pCol = nCol;
			*pType = nType;
			*pSize = nSize;

			bBreak = true;
			break;
		}
		nRow++;
	}

}
  



  CopyString

  
// *********************************************************
// 文字列オブジェクトにコピー
// 行の終わりには、改行コードを付加
// bSelect が true の場合は 選択した行のみコピーする
// bTitle が true の場合は、タイトルもコピーする
// nType
//  0 : タブ
//  1 : カンマ(CSV)
//  2 : \
//  3 : HTML テーブルタグ
//	100 : タブ区切りタイトルのみ
//	101 : カンマ区切りタイトルのみ
//	102 : 改行区切りタイトルのみ
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxListview::CopyString(
	BOOL bSelect, BOOL bTitle, int nType, LboxString *LString )
{

	DWORD nRows,nCols;
	DWORD i;
	int nSaveType;

	nSaveType = nType;

	// 通常文字列としてクリア
	LString->SetChar( 0, 0 );

	// ワーク用文字列オブジェクト
	LboxString *LstrWork;
	LstrWork = new LboxString();

	// デリミタ
	char delim[5][4];
	lstrcpy( delim[0], "\t" );
	lstrcpy( delim[1], "," );
	lstrcpy( delim[2], "\\" );
	lstrcpy( delim[4], "\n" );

	nRows = LboxListview::Count();
	nCols = LboxListview::ColumnCount();

	// タイトル部分の作成
	if ( nType == 3 ) {
		// <TABLE>
		LString->operator += ( szTag1 );
	}
	if ( bTitle ) {
		if ( nType == 3 ) {
			// <TR>
			LString->operator += ( szTag2 );
		}
		switch( nSaveType ) {
			case 100:
				nType = 0;
				break;
			case 101:
				nType = 1;
				break;
			case 102:
				nType = 4;
				break;
		}
		for( i = 0; i < nCols; i++ ) {
			if ( nType == 3 ) {
				// <TH>
				LString->operator += ( szTag7 );
			}
			else {
				if ( i != 0 ) {
					LString->operator += ( delim[nType] );
				}
			}
			LboxListview::GetColumnTitle(
				i,
				LstrWork
			);
			LString->operator += ( LstrWork );
			if ( nType == 3 ) {
				// </TH>
				LString->operator += ( szTag8 );
			}
		}
		if ( nType == 3 ) {
			// </TR>
			LString->operator += ( szTag3 );
		}
		if ( nSaveType >= 100 ) {
			delete LstrWork;
			return true;
		}
		LString->operator += ( "\n" );
	}

	// データ部分の作成
	int nRow;
	nRow = -1;
	while( LboxListview::FindNextRow( &nRow ) ) {
		// 選択行のみ
		if ( bSelect ) {
			if ( false == LboxListview::IsState(
				nRow,
				LVIS_SELECTED
				) ) {
				continue;
			}
		}
		if ( nType == 3 ) {
			// <TR>
			LString->operator += ( szTag2 );
		}
		for( i = 0; i < nCols; i++ ) {
			if ( nType == 3 ) {
				// <TD>
				LString->operator += ( szTag4 );
			}
			else {
				if ( i != 0 ) {
					LString->operator += ( delim[nType] );
				}
			}
			LboxListview::GetColumnText(
				i,
				LstrWork
			);
			LString->operator += ( LstrWork );
			if ( nType == 3 ) {
				// </TD>
				LString->operator += ( szTag5 );
			}
		}
		if ( nType == 3 ) {
			// </TR>
			LString->operator += ( szTag3 );
		}
		LString->operator += ( "\n" );
	}

	if ( nType == 3 ) {
		// </TABLE>
		LString->operator += ( szTag6 );
		LString->operator += ( "\n" );
	}

	delete LstrWork;

	return true;
}
  



  SetColumnPrintf

  
void LboxListview::SetColumnPrintf( int nCol, LPTSTR FormatString, ... )
{
	LboxString *LString;
	LString = new LboxString( 1024 );
	va_list marker;

	va_start(marker, FormatString);
	wvsprintf(LString->szLboxString, FormatString, marker);
	va_end(marker);
	LboxListview::SetColumnText( nCol, LString );

	delete LString;
}
  



  SetColumnFmt

  
// *********************************************************
// リストビューのカラムのフォーマット設定
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetColumnFmt( int nCol, int nFmt )
{
	LV_COLUMN col;

	ZeroMemory( &col, sizeof( LV_COLUMN ) );
	col.mask = LVCF_FMT;

	col.fmt = nFmt;
	ListView_SetColumn(hWnd, nCol, &col);
}
  



  FindPreviousRow

  
// *********************************************************
// 行の逆検索
// 戻り値 : true 行発見, false 対象行無し
// 初回は、nRow に -1 を渡す
// *********************************************************
BOOL LboxListview::FindPreviousRow( int *nRow )
{
	if ( (*nRow) == -1 ) {
		if ( LboxListview::Count() == 0 ) {
			return false;
		}
		LboxListview::nCurrentRow = LboxListview::Count() - 1;
		return true;
	}
	
	if ( (*nRow) - 1 >= 0 ) {
		(*nRow)--;
		LboxListview::nCurrentRow = (*nRow);
		return true;
	}

	return false;
}
  



  FindPreviousSelectedRow

  
// *********************************************************
// 選択された行の逆検索
// 戻り値 : true 行発見, false 対象行無し
// 初回は、nRow に -1 を渡す
// *********************************************************
BOOL LboxListview::FindPreviousSelectedRow( int *nRow )
{
	int i;

	if ( (*nRow) == -1 ) {
		if ( LboxListview::Count() == 0 ) {
			return false;
		}
		(*nRow) = LboxListview::Count();
	}
	
	for( i = (*nRow) - 1; i >= 0; i-- ) {
		if ( LboxListview::IsState( i, LVIS_SELECTED ) ) {
			*nRow = i;
			LboxListview::nCurrentRow = i;
			return true;
		}
	}

	return false;
}
  



  DestroyPopup

  
// *********************************************************
// ポップアップメニューの破棄
// 戻り値 : 無し
// *********************************************************
void LboxListview::DestroyPopup( void )
{
	if ( LboxListview::hMenu != NULL ) {
		DestroyMenu( LboxListview::hMenu );
		hMenu = NULL;
	}
}
  










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





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

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ