|
hWnd には、ダイアログボックスのウインドウハンドルを指定します
|
|
|
// *********************************************************
// リストボックスから文字列を取得
// 戻り値 : 取得した文字列の長さ
// *********************************************************
int LboxDlg::ListGetText(int nID, int nIndex, LboxString *LString )
{
int nLen;
while( 1 ) {
nLen = LboxDlg::ListGetText(
nID,
nIndex,
LString->szLboxString,
LString->nLboxString
);
if ( nLen >= (int)(LString->nLboxString) - 2 ) {
if ( LString->nLboxString > LBOX_STRINGMAX ) {
break;
}
LString->Resize( LString->nLboxString + MAX_PATH );
continue;
}
break;
}
return nLen;
}
int LboxDlg::ListGetText(int nID, int nIndex, LPCTSTR pszBuffer, int nSize )
{
return LboxListGetText(
GetDlgItem( LboxDlg::hDlg, nID ),
nIndex,
pszBuffer,
nSize
);
}
| |
|
|
|
|
// *********************************************************
// リストボックスにダンプ結果を表示
// *********************************************************
void LboxListDump( HWND hWnd, LPCTSTR pszBuffer, int nSize )
{
int i,j,nRow,nPos;
char szBuffer[80];
nRow = nPos = 0;
for( i = 0; i < nSize; i += 16 ) {
for( j = i; j < i + 16; j++ ) {
wsprintf(
szBuffer+(j-i)*3,
"%02x ",
0x000000ff & *(pszBuffer+nPos)
);
nPos++;
}
CharUpperBuff( szBuffer, 80 );
LboxListInsert( hWnd, nRow, szBuffer );
nRow++;
}
}
| |
|
|
|
|
// *********************************************************
// リストボックスにフォーマットした文字列を表示
// *********************************************************
void LboxDlg::ListPrintf(int nID, LPSTR FormatString, ...)
{
va_list marker;
char szBuffer[1024];
char *szNewBuff = new char[lstrlen(FormatString)+10];
lstrcpy( szNewBuff, FormatString );
va_start(marker, FormatString);
vsprintf(szBuffer, szNewBuff, marker);
va_end(marker);
unsigned char *pszToken;
int nRow = 0;
pszToken = _mbstok(
(unsigned char *)szBuffer,
(const unsigned char *)"\n"
);
while( pszToken != NULL ) {
LboxListInsert(
GetDlgItem( LboxDlg::hDlg, nID ),
nRow,
(LPCTSTR)pszToken
);
nRow++;
pszToken = _mbstok( NULL, (const unsigned char *)"\n" );
}
delete [] szNewBuff;
}
| |
|
|
|
pszBuffer には、pszDelimiter で区切られた 0 個以上のトークンを含む文字列へのポインタを渡します
|
|
|
// *********************************************************
// クリップボードにコピー
// 行の終わりには、改行コードを付加
// bSelect が true の場合は 選択した行のみコピーする
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxListCopyClipboard( HWND hWnd, BOOL bSelect )
{
DWORD nSize;
int nRows,i;
BOOL bFlg;
nSize = 0;
nRows = LboxListCount( hWnd );
for( i = 0; i < nRows; i++ ) {
if ( bSelect ) {
bFlg = (BOOL)SendMessage(
hWnd,
LB_GETSEL,
(WPARAM)i,
0L
);
if ( !bFlg ) {
continue;
}
}
nSize += (DWORD)SendMessage(
hWnd,
LB_GETTEXTLEN,
(WPARAM)i,
0L
);
nSize++;
}
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;
for( i = 0; i < nRows; i++ ) {
if ( bSelect ) {
bFlg = (BOOL)SendMessage(
hWnd,
LB_GETSEL,
(WPARAM)i,
0L
);
if ( !bFlg ) {
continue;
}
}
SendMessage(
hWnd,
LB_GETTEXT,
(WPARAM)i,
(LPARAM)(LPCTSTR)pMem
);
lstrcat( pMem, "\n" );
pMem = pMem + lstrlen( pMem );
}
GlobalUnlock( hGlobal );
OpenClipboard( NULL );
EmptyClipboard();
SetClipboardData(CF_TEXT, hGlobal);
CloseClipboard();
return true;
}
| |
|
|
|
|
// *********************************************************
// ステータスバーの実装
// 戻り値 : 無し
// *********************************************************
void LboxDlg::StatusCreate( int nID )
{
if ( LboxDlg::hStatus != NULL ) {
DestroyWindow(
LboxDlg::hStatus
);
}
LboxDlg::hStatus =
CreateWindowEx(
0,
STATUSCLASSNAME,
(LPCTSTR)NULL,
WS_CHILD | WS_VISIBLE,
0, 0, 0, 0,
LboxDlg::hDlg,
(HMENU)(nID),
LboxGetInstance(GetParent(LboxDlg::hDlg)),
NULL
);
SendMessage(
LboxDlg::hStatus,
SB_SIMPLE,
(WPARAM)true,
0L
);
}
| |
|
|
|