リストビュー


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



  タイトルの作成




  

#include <lightbox.h>
LboxListview *Lview;
LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	switch( message )
	{
		case WM_INITDIALOG:
			Lview = new LboxListview( GetDlgItem( hDlg, IDC_LIST1 ) );
			return TRUE;

		case WM_COMMAND:
			if( LOWORD(wParam) == IDCANCEL ) {
				EndDialog(hDlg, LOWORD(wParam));
				delete Lview;
				return TRUE;
			}
			if( LOWORD(wParam) == IDC_BUTTON1 ) {
				Lview->AddColumn( LVCFMT_LEFT, 70, "コード" );
				Lview->AddColumn( LVCFMT_LEFT, 150, "氏名" );
				Lview->AddColumn( LVCFMT_LEFT, 150, "フリガナ" );
				Lview->AddColumn( LVCFMT_LEFT, 100, "電話番号" );
			}
			break;
	}
	return FALSE;
}
  

  データの作成

  

#include <lightbox.h>
LboxListview *Lview;
LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	switch( message )
	{
		case WM_INITDIALOG:
			Lview = new LboxListview( GetDlgItem( hDlg, IDC_LIST1 ) );
			Lview->AddColumn( LVCFMT_LEFT, 70, "コード" );
			Lview->AddColumn( LVCFMT_LEFT, 150, "氏名" );
			Lview->AddColumn( LVCFMT_LEFT, 150, "フリガナ" );
			Lview->AddColumn( LVCFMT_LEFT, 100, "電話番号" );
			Lview->Grid();
			return TRUE;

		case WM_COMMAND:
			if( LOWORD(wParam) == IDCANCEL ) {
				EndDialog(hDlg, LOWORD(wParam));
				delete Lview;
				return TRUE;
			}
			// 行追加
			if( LOWORD(wParam) == IDC_BUTTON1 ) {
				Lview->AddRow();
				Lview->AddRow();
				Lview->AddRow();
				Lview->AddRow();
			}
			// カレント行設定
			if( LOWORD(wParam) == IDC_BUTTON2 ) {
				Lview->SetCurrentRow( 1 );
			}
			// カラムテキストを設定
			if( LOWORD(wParam) == IDC_BUTTON3 ) {
				Lview->SetColumnText( 0, "0001" );
				Lview->SetColumnText( 1, "山田太郎" );
				Lview->SetColumnText( 2, "ヤマダタロウ" );
				Lview->SetColumnText( 3, "123-456-7890" );
			}
			break;
	}
	return FALSE;
}
  

  拡張コンストラクタ

エディットコントロールのフック無し

  

// *********************************************************
// 拡張コンストラクタ
// *********************************************************
LboxListview::LboxListview( HWND hList )
{
	LboxListview::hWnd = hList;
	LboxListview::hEdit = NULL;
	LboxListview::hEdit = 
		LboxCreateEdit( hList, 50001 );
	if ( LboxListview::hEdit != NULL ) {
		HFONT hFont;

		hFont = (HFONT)SendMessage( hList, WM_GETFONT, 0, 0 );
		SendMessage( LboxListview::hEdit, WM_SETFONT, (WPARAM)hFont, 0 );
		LboxMoveWindowTop( LboxListview::hEdit );
	}

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

エディットコントロールのフック有り

  

// *********************************************************
// 拡張コンストラクタ
// *********************************************************
LboxListview::LboxListview( HWND hList, DWORD dwFlag )
{
	LboxListview::hWnd = hList;
	LboxListview::hEdit = NULL;
	LboxListview::hEdit = 
		LboxCreateEdit( hList, 50001 );
	if ( LboxListview::hEdit != NULL ) {
		HFONT hFont;

		hFont = (HFONT)SendMessage( hList, WM_GETFONT, 0, 0 );
		SendMessage( LboxListview::hEdit, WM_SETFONT, (WPARAM)hFont, 0 );
		LboxMoveWindowTop( LboxListview::hEdit );
	}

	if ( dwFlag & 0x00000001 ) {

		hhk = SetWindowsHookEx(
			WH_CALLWNDPROCRET,
			CallWndRetProc,
			NULL,
			GetCurrentThreadId()				
		);

	}

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

※ フックは、最初に作成するリストビューのみに使用します。二つ目以降のリストビューは、フック無しのほうを使用して下さい

  

#define LBOX_EN_LISTVIEW	WM_USER + 1
// *********************************************************
// エディットコントロール用のフックプロシージャ
// *********************************************************
LRESULT CALLBACK CallWndRetProc(
	int code,// フックコード
	WPARAM wParam,// 削除フラグ
	LPARAM lParam// メッセージが入った構造体へのポインタ
)
{
	CWPRETSTRUCT *msg;
	HWND hOwner;
	HWND hListview;

	msg = (CWPRETSTRUCT *)lParam;
	if ( LOWORD(msg->wParam) == 50001 ) {
		if ( msg->message == WM_COMMAND ) {
			hListview = GetParent( (HWND)msg->lParam );
			hOwner = GetParent( hListview );
			if ( msg->message == WM_COMMAND ) {
				SendMessage(
					hOwner,
					LBOX_EN_LISTVIEW,
					msg->wParam,
					msg->lParam
				);
			}
			if ( HIWORD(msg->wParam) == EN_KILLFOCUS ) {
				char *szBuffer = new char[512];

				GetWindowText(
					(HWND)msg->lParam,
					szBuffer,
					512
				);

				ListView_SetItemText(
					hListview,
					nEditRow,
					nEditCol,
					szBuffer
				)
				ShowWindow( (HWND)msg->lParam, SW_HIDE );
				delete [] szBuffer;
			}
		}
	}

	return CallNextHookEx( hhk, code, wParam, lParam );
}
  

  最初に実行するメンバ関数

  

// *********************************************************
// リストビューに列挿入
// 戻り値 : 無し
// nFmt 用定数
// LVCFMT_CENTER : 中央
// LVCFMT_LEFT   : 左寄せ
// LVCFMT_RIGHT  : 右寄せ
// *********************************************************
void LboxListview::InsertColumn(
int nCol, int nFmt, int nWidth, LPTSTR szTitle
)
{
#if CODING == 1
	LVCOLUMNA col;
#else
	LV_COLUMN col;
#endif

	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);
}

// *********************************************************
// リストビューに列追加
// 戻り値 : 無し
// *********************************************************
void LboxListview::AddColumn(
int nFmt, int nWidth, LPTSTR szTitle
)
{
	int nCol;
#if CODING == 1
	LVCOLUMNA col;
#else
	LV_COLUMN col;
#endif

	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);
}
  

  行関係のメンバ関数

  

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

// *********************************************************
// リストビューに行挿入
// 戻り値 : 挿入された行。エラーの場合は -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
	);
}

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

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

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

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

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

  列関係のメンバ関数

  

// *********************************************************
// リストビューの列数取得
// 戻り値 : 列数
// *********************************************************
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;
}

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

// *********************************************************
// リストビューの列のテキストを取得
// 戻り値 : 無し
// *********************************************************
void LboxListview::GetColumnText( int nCol, LPTSTR szBuffer, int nSize )
{
	ListView_GetItemText(
		LboxListview::hWnd,
		LboxListview::nCurrentRow,
		nCol,
		szBuffer,
		nSize
	)
}

// *********************************************************
// リストビューの列のタイトルを設定
// 戻り値 : 無し
// *********************************************************
void LboxListview::SetColumnTitle( int nCol, LPTSTR szBuffer )
{
#if CODING == 1
	LVCOLUMNA col;
#else
	LV_COLUMN col;
#endif

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

	col.pszText = szBuffer;

	ListView_SetColumn(
		LboxListview::hWnd,
		nCol,
		&col
	);
}

// *********************************************************
// リストビューの列のタイトルを取得
// 戻り値 : 無し
// *********************************************************
void LboxListview::GetColumnTitle( int nCol, LPTSTR szBuffer, int nSize )
{
#if CODING == 1
	LVCOLUMNA col;
#else
	LV_COLUMN col;
#endif

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

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

	ListView_GetColumn(
		LboxListview::hWnd,
		nCol,
		&col
	);
}

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

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

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

  イベント処理

  

// *********************************************************
// WM_NOTIFYメッセージを取得する
// 戻り値 : メッセージ
// *********************************************************
UINT LboxListview::Notify( LPARAM lParam )
{
	LPNMLISTVIEW lpNmlv;

	lpNmlv = (LPNMLISTVIEW)lParam;
	LboxListview::nCurrentCol = lpNmlv->iSubItem;
	LboxListview::nCurrentRow = lpNmlv->iItem;
	LboxListview::Action = lpNmlv->hdr.code;
	LboxListview::hCurrent = lpNmlv->hdr.hwndFrom;
	LboxListview::nCurrentId = lpNmlv->hdr.idFrom;

	if ( LboxListview::hCurrent == LboxListview::hWnd ) {
		if ( LboxListview::Action == NM_RCLICK ) {
			if ( LboxListview::hMenu != NULL ) {
				HMENU hPopup;

				hPopup = GetSubMenu(
					LboxListview::hMenu,
					LboxListview::nCurrentPopup
				);
				ClientToScreen(
					LboxListview::hWnd,
					&lpNmlv->ptAction
				);
				TrackPopupMenu(
					hPopup,
					TPM_LEFTALIGN | TPM_TOPALIGN,
					lpNmlv->ptAction.x,
					lpNmlv->ptAction.y,
					0,
					GetParent(LboxListview::hWnd),
					NULL
				);
			}
		}
	}

	return lpNmlv->hdr.code;
}
  

以下使用例

  

case WM_NOTIFY:
	Lview->Notify( lParam );
	if ( Lview->nCurrentId == IDC_LIST3 ) {
		switch( Lview->Action ) {
			case NM_DBLCLK:
				// データの無い場所をダブルクリックした場合
				if ( Lview->nCurrentRow == -1 ) {
					break;
				}
				// 第一カラムは処理しない
				if ( Lview->nCurrentCol != 0 ) {
					Lview->LoadColumnText(
						Lview->nCurrentRow,
						Lview->nCurrentCol
					);
				}
				break;
		}
	}
	break;
  

以下ポップアップメニュー用

  

// *********************************************************
// ポップアップメニューの実装
// 戻り値 : 無し
// *********************************************************
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;
}

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

  エディットコントロール用

対象カラムデータをエディットコントロールへセットして表示させます

  

// *********************************************************
// リストビューのカラムデータをエディットコントロールにセット
// 戻り値 : 無し
// *********************************************************
void LboxListview::LoadColumnText( int nRow, int nCol )
{
	char *szBuffer = new char[512];
	ListView_GetItemText(
		LboxListview::hWnd,
		nRow,
		nCol,
		szBuffer,
		512
	);
	SetWindowText( LboxListview::hEdit, szBuffer );

	RECT rt;

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

	nEditRow = nRow;
	nEditCol = nCol;

	delete [] szBuffer;
}
  

  情報取得

※ 情報構造体
  

typedef struct _LBOXLISTVIEWINFO {
	int nCurVisibleTopIndex;
	int nVisibleCountPerPage;
	int nSelectedCount;
	COLORREF cBkColor;
	COLORREF cTextBkColor;
	COLORREF cTextColor;
} LBOXLISTVIEWINFO;
  

  

// *********************************************************
// 情報の取得
// 戻り値 : 情報構造体メンバ変数へのポインタ
// *********************************************************
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);
}

// *********************************************************
// 状態のチェック
// 戻り値 : 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;
}
  

  リストビューに対する処理

  

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

	int i,nCols;

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

}
  

  

// *********************************************************
// 行の検索
// 戻り値 : 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;
}

// *********************************************************
// 選択された行の検索
// 戻り値 : 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;
}
  

以下 FindNextSelectedRow の使用例

  

int nRow;

nRow = -1;
while( Lview->FindNextSelectedRow( &nRow ) ) {
	Lview->SetColumnText( 4, "*** OK ***" );
}
  

  

// *********************************************************
// 行の選択状態の変更
// 戻り値 : 無し
// 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
		);
	}
}
  

  

char *szTag1 = "<TABLE border=1>";
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;
}
  

  

// *********************************************************
// カラム幅とデータ幅との調整
// 戻り値 : 無し
// *********************************************************
void LboxListview::Fit( void )
{
	int nStartRow,nEndRow,nCols,i,j;
	int nLen,nMax;
	char *szBuffer = new char[MAX_PATH];

	nCols = LboxListview::Count();
	LboxListview::GetInfo();
	nStartRow = LboxListview::llvi.nCurVisibleTopIndex;
	nEndRow = nStartRow + LboxListview::llvi.nVisibleCountPerPage;

	for( i = 0; i < nCols; i++ ) {
		LboxListview::GetColumnTitle( i, szBuffer, MAX_PATH );
		nMax = ListView_GetStringWidth(
			LboxListview::hWnd,
			szBuffer
		);
		for( j = nStartRow; j <= nEndRow; j++ ) {
			LboxListview::SetCurrentRow( j );
			LboxListview::GetColumnText( i, szBuffer, MAX_PATH );
			nLen = ListView_GetStringWidth(
				LboxListview::hWnd,
				szBuffer
			);
			if ( nLen > nMax ) {
				nMax = nLen;
			}
		}
		nMax += 14;
		LboxListview::SetColumnWidth( i, nMax );
	}

	delete [] szBuffer;
}
  

  リストビューに対する処理 (2)

  

// *********************************************************
// フォントのセット
// 戻り値 : 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(
		LboxListview::hWnd,
		WM_SETFONT,
		(WPARAM)(LboxListview::hFont),
		MAKELPARAM(true, 0)
	);

	return true;
}

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

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

// *********************************************************
// 指定行、指定カラムを表示位置にスクロール
// 戻り値 : 無し
// *********************************************************
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
	);
}
  




yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[cmaterial]
Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
24/04/20 22:06:00
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube