📄 sessioninfo.cpp
字号:
( sizeof( WCHAR ) * (dwNameLen + 1) );
// Allocate space
SI_MSG_GROUPINFO* pMsg = (SI_MSG_GROUPINFO*) new BYTE[ dpBufDesc.dwBufferSize ];
if( NULL == pMsg )
{
Unlock();
return E_OUTOFMEMORY;
}
// Set the data pointer
dpBufDesc.pBufferData = (BYTE*) pMsg;
// Store values
pMsg->dwMsgID = SI_MSGID_GROUPINFO;
pMsg->dpnID = idGroup;
pMsg->dwNameLength = dwNameLen;
// Pack the strings
LPWSTR pStr = (LPWSTR) (pMsg+1);
DXUtil_ConvertGenericStringToWideCch( pStr, pGroup->strName, dwNameLen+1 );
// Release the lock
Unlock();
// Send the information
DPNHANDLE dpAsync;
switch( m_eType )
{
case PEER:
hr = m_pPeer->SendTo( idTarget, &dpBufDesc, 1, 0, SI_ASYNC_CONTEXT, &dpAsync, DPNSEND_NOCOMPLETE | DPNSEND_NOLOOPBACK );
break;
case SERVER:
hr = m_pServer->SendTo( idTarget, &dpBufDesc, 1, 0, SI_ASYNC_CONTEXT, &dpAsync, DPNSEND_NOCOMPLETE | DPNSEND_NOLOOPBACK );
break;
default:
hr = E_FAIL;
break;
}
// Release allocated memory and return
SAFE_DELETE_ARRAY( pMsg );
return hr;
}
//-----------------------------------------------------------------------------
// Name: SynchronizeWithPlayer()
// Desc: Send all stored group and player information to the player with the
// given ID
//-----------------------------------------------------------------------------
HRESULT CSessionInfo::SynchronizeWithPlayer( DPNID id )
{
HRESULT hr = S_OK;
Lock();
// Send all player and group information
for( UINT i=0; i < m_pPlayers->Count(); i++ )
{
CSIPlayer* pPlayer = (CSIPlayer*) m_pPlayers->GetPtr( i );
// Attempt to send
hr = SendPlayerInfoToPlayer( pPlayer->id, id );
if( FAILED(hr) )
break;
}
for( i=0; i < m_pGroups->Count(); i++ )
{
CSIGroup* pGroup = (CSIGroup*) m_pGroups->GetPtr( i );
// Attempt to send
hr = SendGroupInfoToPlayer( pGroup->id, id );
if( FAILED(hr) )
break;
}
Unlock();
return hr;
}
//-----------------------------------------------------------------------------
// Name: ShowDialog()
// Desc: Show the dialog UI for all stored player, group, and message data.
//-----------------------------------------------------------------------------
HRESULT CSessionInfo::ShowDialog( HWND hParent )
{
// If a dialog already exists, bring it to the front
if( m_hDlg )
{
if( FALSE == BringWindowToTop( m_hDlg ) )
return E_FAIL;
}
else
{
// If there is an old thread handle, release it now
SafeDestroyThread( &m_hDlgThread );
// Launch a new dialog thread
DWORD dwThreadID;
m_hDlgParent = hParent;
m_hDlgThread = chBEGINTHREADEX( NULL, 0, StaticDialogThread, (void*) this, 0, &dwThreadID );
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: StaticDialogThread()
// Desc: Message pump thread for modeless dialogs
//-----------------------------------------------------------------------------
DWORD WINAPI CSessionInfo::StaticDialogThread( void* pvRef )
{
CSessionInfo* pThis = (CSessionInfo*) pvRef;
pThis->m_hDlgPlayers = CreateDialog( GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_SI_PLAYERS), pThis->m_hDlgParent, StaticDlgProcPlayers );
pThis->m_hDlgMessages = CreateDialog( GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_SI_MESSAGES), pThis->m_hDlgParent, StaticDlgProcMessages );
pThis->m_hDlg = CreateDialog( GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_SI_MAIN), pThis->m_hDlgParent, StaticDlgProcMain );
ShowWindow( pThis->m_hDlg, SW_SHOW );
MSG msg;
while( GetMessage( &msg, NULL, 0, 0) )
{
// Forward the message to the dialog
if( IsDialogMessage( pThis->m_hDlg, &msg ) )
continue;
if( IsDialogMessage( pThis->m_hDlgPlayers, &msg ) )
continue;
if( IsDialogMessage( pThis->m_hDlgMessages, &msg ) )
continue;
}
// Release the window resources
DestroyWindow( pThis->m_hDlgMessages );
pThis->m_hDlgMessages = NULL;
DestroyWindow( pThis->m_hDlgPlayers );
pThis->m_hDlgPlayers = NULL;
DestroyWindow( pThis->m_hDlg );
pThis->m_hDlg = NULL;
return 0;
}
//-----------------------------------------------------------------------------
// Name: StaticDlgProcMain()
// Desc: Static dialog procedure sorts incoming messages according to the
// window handle and assigns them to the member dialog procedure for the
// correct instance
//-----------------------------------------------------------------------------
INT_PTR CALLBACK CSessionInfo::StaticDlgProcMain( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
if( g_pSI )
return g_pSI->DlgProcMain( hDlg, uMsg, wParam, lParam );
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: StaticDlgProcPlayers()
// Desc: Static dialog procedure sorts incoming messages according to the
// window handle and assigns them to the member dialog procedure for the
// correct instance
//-----------------------------------------------------------------------------
INT_PTR CALLBACK CSessionInfo::StaticDlgProcPlayers( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
if( g_pSI )
return g_pSI->DlgProcPlayers( hDlg, uMsg, wParam, lParam );
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: StaticDlgProcMessages()
// Desc: Static dialog procedure sorts incoming messages according to the
// window handle and assigns them to the member dialog procedure for the
// correct instance
//-----------------------------------------------------------------------------
INT_PTR CALLBACK CSessionInfo::StaticDlgProcMessages( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
if( g_pSI )
return g_pSI->DlgProcMessages( hDlg, uMsg, wParam, lParam );
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: DlgProcMain()
// Desc: Dialog procedure for the UI
//-----------------------------------------------------------------------------
INT_PTR CALLBACK CSessionInfo::DlgProcMain( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch( uMsg )
{
case WM_INITDIALOG:
{
SetParent( m_hDlgPlayers, GetDlgItem( hDlg, IDC_SI_TAB ) );
SetParent( m_hDlgMessages, GetDlgItem( hDlg, IDC_SI_TAB ) );
// Set the window title
DPN_APPLICATION_DESC* pAppDesc;
if( SUCCEEDED( GetDpAppDesc( &pAppDesc ) ) )
{
TCHAR strTitle[ 256 ];
DXUtil_ConvertWideStringToGenericCch( strTitle, pAppDesc->pwszSessionName, 256-50 );
lstrcat( strTitle, TEXT(" - Session Info") );
SendMessage( hDlg, WM_SETTEXT, 0, (LPARAM) strTitle );
}
// Add tabs
TCITEM tcItem = {0};
tcItem.mask = TCIF_TEXT;
tcItem.pszText = TEXT("Players");
SendMessage( GetDlgItem( hDlg, IDC_SI_TAB ), TCM_INSERTITEM, 0, (LPARAM) &tcItem );
tcItem.pszText = TEXT("Messages");
SendMessage( GetDlgItem( hDlg, IDC_SI_TAB ), TCM_INSERTITEM, 1, (LPARAM) &tcItem );
RECT rcWindow = {0};
GetWindowRect( GetDlgItem( hDlg, IDC_SI_TAB ), &rcWindow );
SendMessage( GetDlgItem( hDlg, IDC_SI_TAB ), TCM_ADJUSTRECT, FALSE, (LPARAM) &rcWindow );
POINT ptWindow = { rcWindow.left, rcWindow.top };
ScreenToClient( GetDlgItem( hDlg, IDC_SI_TAB ), &ptWindow );
MoveWindow( m_hDlgPlayers, ptWindow.x, ptWindow.y, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top, FALSE );
MoveWindow( m_hDlgMessages, ptWindow.x, ptWindow.y, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top, FALSE );
ShowWindow( m_hDlgPlayers, SW_SHOW );
SAFE_DELETE_ARRAY( pAppDesc );
return TRUE;
}
case WM_COMMAND:
switch( LOWORD(wParam) )
{
case IDCANCEL:
SendMessage( hDlg, WM_CLOSE, 0, 0 );
return TRUE;
}
break;
case WM_NOTIFY:
{
NMHDR* pHdr = (NMHDR*) lParam;
switch( pHdr->code )
{
case TCN_SELCHANGE:
DWORD dwCurSel = SendMessage( GetDlgItem( hDlg, IDC_SI_TAB ), TCM_GETCURSEL, 0, 0 );
ShowWindow( m_hDlgPlayers, ( 0 == dwCurSel ) ? SW_SHOW : SW_HIDE );
ShowWindow( m_hDlgMessages, ( 1 == dwCurSel ) ? SW_SHOW : SW_HIDE );
return TRUE;
}
break;
}
case WM_CLOSE:
if( m_hDlgThread )
PostQuitMessage( 0 );
else
EndDialog( hDlg, 0 );
return TRUE;
}
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: DlgProcPlayers()
// Desc: Dialog procedure for the UI
//-----------------------------------------------------------------------------
INT_PTR CALLBACK CSessionInfo::DlgProcPlayers( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch( uMsg )
{
case WM_INITDIALOG:
{
// Set custom dialog settings
if( m_hNameFont )
SendMessage( GetDlgItem( hDlg, IDC_SI_NAME ), WM_SETFONT, (WPARAM) m_hNameFont, TRUE );
if( m_hConnectionFont )
SendMessage( GetDlgItem( hDlg, IDC_SI_DESCRIPTION ), WM_SETFONT, (WPARAM) m_hConnectionFont, TRUE );
// Refresh the dialog contents
PaintDialog( hDlg );
m_bDlgValid = TRUE;
// Set the refresh timer
SetTimer( hDlg, SI_REFRESH_TIMER, SI_REFRESH_INTERVAL, NULL );
return TRUE;
}
case WM_TIMER:
{
if( FALSE == m_bDlgValid )
PaintDialog( hDlg );
return TRUE;
}
case WM_COMMAND:
{
switch( LOWORD(wParam) )
{
case IDC_SI_PLAYERS:
{
if( LBN_SELCHANGE == HIWORD(wParam) )
{
DWORD dwCurSel;
DWORD dwItemData;
if( LB_ERR != ( dwCurSel = SendMessage( (HWND) lParam, LB_GETCURSEL, 0, 0 ) ) &&
LB_ERR != ( dwItemData = SendMessage( (HWND) lParam, LB_GETITEMDATA, dwCurSel, 0 ) ) )
DisplayPlayer( dwItemData, hDlg );
return TRUE;
}
break;
}
case IDC_SI_GROUPS:
{
if( LBN_SELCHANGE == HIWORD(wParam) )
{
DWORD dwCurSel;
DWORD dwItemData;
if( LB_ERR != ( dwCurSel = SendMessage( (HWND) lParam, LB_GETCURSEL, 0, 0 ) ) &&
LB_ERR != ( dwItemData = SendMessage( (HWND) lParam, LB_GETITEMDATA, dwCurSel, 0 ) ) )
DisplayGroup( dwItemData, hDlg );
return TRUE;
}
break;
}
case IDC_SI_MEMBERSHIP:
{
if( LBN_SELCHANGE == HIWORD(wParam) )
{
DWORD dwCurSel;
DWORD dwItemData;
if( LB_ERR != ( dwCurSel = SendMessage( (HWND) lParam, LB_GETCURSEL, 0, 0 ) ) &&
LB_ERR != ( dwItemData = SendMessage( (HWND) lParam, LB_GETITEMDATA, dwCurSel, 0 ) ) )
{
if( LB_ERR != SendMessage( GetDlgItem( hDlg, IDC_SI_PLAYERS ), LB_GETCURSEL, 0, 0 ) )
DisplayGroup( dwItemData, hDlg );
else if( LB_ERR != SendMessage( GetDlgItem( hDlg, IDC_SI_GROUPS ), LB_GETCURSEL, 0, 0 ) )
DisplayPlayer( dwItemData, hDlg );
}
return TRUE;
}
break;
}
}
break;
}
}
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: DlgProcMessages()
// Desc: Dialog procedure for the UI
//-----------------------------------------------------------------------------
INT_PTR CALLBACK CSessionInfo::DlgProcMessages( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch( uMsg )
{
case WM_INITDIALOG:
{
// List box settings
PostMessage( GetDlgItem( hDlg, IDC_SI_DPLAYMSG ), LB_INITSTORAGE, SI_MAX_MESSAGES, sizeof(TCHAR) * 256 );
PostMessage( GetDlgItem( hDlg, IDC_SI_APPMSG ), LB_INITSTORAGE, SI_MAX_MESSAGES, sizeof(TCHAR) * 256 );
PostMessage( GetDlgItem( hDlg, IDC_SI_DPLAYMSG ), LB_SETHORIZONTALEXTENT, 400, 0 );
PostMessage( GetDlgItem( hDlg, IDC_SI_APPMSG ), LB_SETHORIZONTALEXTENT, 400, 0 );
// Fill the message windows
m_DPlayMessages.Lock();
for( UINT i=0; i < m_DPlayMessages.GetNumOfMessages(); i++ )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -