📄 voipdemo.cpp
字号:
if (m_cSelectedBuddy.btBuddyType != BT_PHONE || enBt != BT_PHONE) {
DEBUGMSG( 1, (L"Voipdemo: ListView: Attempting to select more than one non-phone buddy\r\n") );
return TRUE;
}
ASSERT(m_cSelectedBuddy.eStat == ES_ONLINE);
ASSERT(m_cSelectedBuddy.btBuddyType == BT_PHONE);
m_cSelectedBuddy.iSelectedBuddies++;
InvalidateButton(-100);
return FALSE;
} else {
// LVIF_STATE we don't care about
return FALSE;
}
} // case LVN_ITEMCHANGING
break;
case LVN_DELETEITEM:
{
// We need to release the buddy reference if an item is being deleted
// note: also ensure selected globals are ok
HWND hwndList = pnmlv->hdr.hwndFrom; // affected listview
LVITEM lvi;
ZeroMem(lvi);
lvi.iItem = pnmlv->iItem; // contains index of deleted item
lvi.mask = LVIF_PARAM; // only need the pointer to the appropriate buddy
ListView_GetItem(hwndList ,&lvi);
IRTCBuddy* pBuddy = (IRTCBuddy*) lvi.lParam;
// Cleanup the selected stuff
if (pBuddy == m_cSelectedBuddy.pBuddy) {
// deselect the buddy
ListView_SetItemState(hwndList, lvi.iItem, 0, LVIS_SELECTED);
}
ASSERT( pBuddy != NULL );
pBuddy->Release();
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
} // end switch (LVN_ message)
} // end case WM_NOTIFY
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
/************************************************************************************************
DoMainPaint()
Paint the main window. This function handles the toolbar, status bar, and control of the
tool bar objects. It also re-sizes and repositions the listview objects.
************************************************************************************************/
LRESULT DoMainPaint( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
RECT rWnd;
PAINTSTRUCT ps;
int nCurrentStatusHeight = 0;
if ( m_sProp.bStatusbar )
nCurrentStatusHeight = MAINWND_STATUSBARHEIGHT;
int nCurrentClientArea = GetSystemMetrics( SM_CYMENU ) + 6;
if ( m_sProp.bToolbar )
nCurrentClientArea += MAINWND_TOOLBARHEIGHT;
HDC hdc = BeginPaint( hWnd, &ps );
GetClientRect( hWnd, &rWnd );
HBRUSH hWhiteBrush = GetSysColorBrush( COLOR_WINDOW );
HPEN hNullPen = CreatePen( PS_NULL, 0, 0 );
HBRUSH hOldBrush = ( HBRUSH )SelectObject( hdc, hWhiteBrush );
HPEN hOldPen = ( HPEN )SelectObject( hdc, hNullPen );
// Draw the white client area
RoundRect( hdc, rWnd.left + 4, rWnd.top + 4 + GetSystemMetrics( SM_CYMENU ) + 1,
rWnd.right - 4, rWnd.bottom - 4 - nCurrentStatusHeight, 2*8, 2*8 );
// Draw the status bar (only if it's visible)
if ( m_sProp.bStatusbar )
{
RECT ri = { rWnd.left+2, rWnd.bottom - nCurrentStatusHeight, rWnd.right-2, rWnd.bottom-2 };
POINT p[3];
p[0].x = ri.left;
p[0].y = ri.bottom;
p[1].x = ri.left;
p[1].y = ri.top;
p[2].x = ri.right;
p[2].y = ri.top;
HPEN hC = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DDKSHADOW ) );
SelectObject( hdc, hC );
Polyline( hdc, &p[0], 3 );
SelectObject( hdc, hNullPen );
DeleteObject( hC );
p[0].x = ri.left;
p[0].y = ri.bottom;
p[1].x = ri.right;
p[1].y = ri.bottom;
p[2].x = ri.right;
p[2].y = ri.top;
hC = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DLIGHT ) );
SelectObject( hdc, hC );
Polyline( hdc, &p[0], 3 );
SelectObject( hdc, hNullPen );
DeleteObject( hC );
SetBkColor( hdc, GetSysColor( COLOR_3DFACE ) );
SetTextColor( hdc, GetSysColor( COLOR_BTNTEXT ) );
RECT rWnd = { ri.left+1, ri.top+1, ri.right-1, ri.bottom-1 };
ExtTextOut( hdc, rWnd.left + 12, rWnd.top, ETO_CLIPPED|ETO_OPAQUE, &rWnd, L"Ready", _tcslen( L"Ready" ), 0 );
}
// Draw the parts of the toolbar (only if it's visible)
if ( m_sProp.bToolbar )
{
// Draw the Toolbar separator line
RECT rc;
rc.top = MAINWND_TOOLBARHEIGHT + GetSystemMetrics( SM_CYMENU );
rc.bottom = rc.top + 2;
#define SEP_COL_STEPS 32
for ( int c = 0; c < SEP_COL_STEPS; c++ )
{
int nColor = ( SEP_COL_STEPS - 1 - c ) * 255 / ( SEP_COL_STEPS - 1 );
HBRUSH hC = CreateSolidBrush( RGB( nColor, nColor/2+128, 255 ) );
rc.left = rWnd.left + 4 + ( rWnd.right - 4 -1- ( rWnd.left + 4 ) ) * c / SEP_COL_STEPS;
rc.right = rWnd.left + 4 + ( rWnd.right - 4 -1- ( rWnd.left + 4 ) ) * ( c + 1 ) / SEP_COL_STEPS;
FillRect( hdc, &rc, hC );
DeleteObject( hC );
}
// Now stick the buttons on the window
for ( c = 0; c < sizeof ( m_sButtons ) / sizeof ( SBUTTONDATA ); c++ )
{
HBITMAP hButton = 0;
// Disable the button Send, Call, and Page if no buddy is selected
// or if it's the Send and the selected is not computer buddy
// or if it's the Call and the selected is a computer buddy not online
BOOL bButtonDisabled = TRUE;
switch (m_sButtons[ c ].r[ 0 ])
{ // determine if button should be enabled
case IDB_SENDBTN:
if (m_cSelectedBuddy.IMCapable() || m_cSelectedBuddy.iSelectedBuddies == 0)
bButtonDisabled = FALSE;
break;
case IDB_CALLBTN:
if (m_cSelectedBuddy.CallCapable() || m_cSelectedBuddy.iSelectedBuddies == 0)
bButtonDisabled = FALSE;
break;
default:
bButtonDisabled = TRUE;
break;
}// end switch
if (bButtonDisabled)
hButton = LoadBitmap( m_hInstance, MAKEINTRESOURCE( m_sButtons[ c ].r[ 2 ] ) );
else
hButton = LoadBitmap( m_hInstance, MAKEINTRESOURCE( m_sButtons[ c ].r[ 0 ] ) );
// draw whichever button we decided to use
HDC hBmpDC = CreateCompatibleDC( hdc );
HBITMAP hOldBmp = ( HBITMAP )SelectObject( hBmpDC, hButton );
BITMAP sButton;
ZeroMem( sButton );
GetObject( hButton, sizeof( BITMAP ), &sButton );
BitBlt( hdc, rWnd.left + m_sButtons[ c ].x + m_sButtons[ c ].cx/2 - sButton.bmWidth/2, rWnd.top + m_sButtons[ c ].y + m_sButtons[ c ].cy/2 - sButton.bmHeight/2 + GetSystemMetrics( SM_CYMENU ),
sButton.bmWidth, sButton.bmHeight, hBmpDC, 0, 0, SRCCOPY );
SelectObject( hBmpDC, hOldBmp );
DeleteObject( hButton );
DeleteDC( hBmpDC );
}
DrawButtons( hdc );
}
// Draw the buddy list areas
// Position the list window in the area and resize it, only change when necessary
int nY = rWnd.top + nCurrentClientArea + 4;
int nViewTop = nY + 2 * MAINWND_BUDDYROWHEIGHT; // MyStatus + "Online"
#ifndef STATICVIEW
static int nOldViewTop = 0;
if ( nOldViewTop != nViewTop) {
nOldViewTop = nViewTop;
if ( m_hwndOnlineView ) {
SetWindowPos( m_hwndOnlineView, HWND_BOTTOM,
8, nViewTop,
MAINWND_DEFAULTWIDTH - 16, MAINWND_BUDDYVIEWHEIGHT,
SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW);
}
if (m_hwndOfflineView) {
SetWindowPos( m_hwndOfflineView, HWND_BOTTOM,
8, nViewTop + MAINWND_BUDDYVIEWHEIGHT + MAINWND_BUDDYROWHEIGHT,
MAINWND_DEFAULTWIDTH - 16, MAINWND_BUDDYVIEWHEIGHT, // some crummy co-ordinates as we'll have to redraw anyway
SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW );
}
} // end if !( SetBuddyViewSize || Pos)
#endif
// show mypic, mycomputertxt, my presence
// show "Online Buddies"
// show "Offline Buddies"
DoStaticBuddyPaint(hdc, rWnd, nY, nViewTop);
// Finish the painting of this window
SelectObject( hdc, hOldPen );
SelectObject( hdc, hOldBrush );
DeleteObject( hNullPen );
EndPaint( hWnd, &ps);
return 0;
}
/************************************************************************************************
DrawButtons()
Draw the button currently being pointed to.
************************************************************************************************/
void DrawButtons( HDC hdc )
{
if ( m_nButtonPointed > -1 )
{
POINT p[3];
p[0].x = m_sButtons[ m_nButtonPointed ].x;
p[0].y = m_sButtons[ m_nButtonPointed ].y + m_sButtons[ m_nButtonPointed ].cy + GetSystemMetrics( SM_CYMENU );
p[1].x = m_sButtons[ m_nButtonPointed ].x;
p[1].y = m_sButtons[ m_nButtonPointed ].y + GetSystemMetrics( SM_CYMENU );
p[2].x = m_sButtons[ m_nButtonPointed ].x + m_sButtons[ m_nButtonPointed ].cx;
p[2].y = m_sButtons[ m_nButtonPointed ].y + GetSystemMetrics( SM_CYMENU );
HPEN hC = CreatePen( PS_SOLID, 2, RGB( 64, 196, 255 ) );
HPEN hOC = ( HPEN )SelectObject( hdc, hC );
Polyline( hdc, &p[0], 3 );
SelectObject( hdc, hOC );
p[0].x = m_sButtons[ m_nButtonPointed ].x;
p[0].y = m_sButtons[ m_nButtonPointed ].y + m_sButtons[ m_nButtonPointed ].cy + GetSystemMetrics( SM_CYMENU );
p[1].x = m_sButtons[ m_nButtonPointed ].x + m_sButtons[ m_nButtonPointed ].cx;
p[1].y = m_sButtons[ m_nButtonPointed ].y + m_sButtons[ m_nButtonPointed ].cy + GetSystemMetrics( SM_CYMENU );
p[2].x = m_sButtons[ m_nButtonPointed ].x + m_sButtons[ m_nButtonPointed ].cx;
p[2].y = m_sButtons[ m_nButtonPointed ].y + GetSystemMetrics( SM_CYMENU );
DeleteObject( hC );
hC = CreatePen( PS_SOLID, 2, RGB( 0, 64, 196 ) );
SelectObject( hdc, hC );
Polyline( hdc, &p[0], 3 );
SelectObject( hdc, hOC );
DeleteObject( hC );
}
}
/************************************************************************************************
InvalidateButton()
Invalidate the rectangle of the button specified. If the button ID is -100, invalidate all
the buttons.
************************************************************************************************/
void InvalidateButton( int nButton )
{
if ( nButton != -100 && nButton < 0 )
return;
for ( int c = 0; c < sizeof ( m_sButtons ) / sizeof ( SBUTTONDATA ) || nButton != -100; c++ )
{
if ( nButton != -100 )
c = nButton;
RECT cr;
cr.top = m_sButtons[ c ].y + GetSystemMetrics( SM_CYMENU ) - 1;
cr.left = m_sButtons[ c ].x - 1;
cr.bottom = cr.top + m_sButtons[ c ].cy + 2;
cr.right = cr.left + m_sButtons[ c ].cx + 2;
InvalidateRect( m_hWndMain, &cr, FALSE );
if ( nButton != -100 )
break;
}
}
/************************************************************************************************
DoStaticBuddyPaint()
Paint my status and icon as well as the online and offline text items above the listviews to
look something like below
mypic mycomputer (my status)
Online Buddies
[OnlineView]
Offline Buddies
[OfflineView]
************************************************************************************************/
VOID
DoStaticBuddyPaint(HDC hdc, RECT rWnd, int nY, int nViewTop)
{
// draw mystatus, Online header, Offline Header
int i = 0;
// draw mystatus icon
HICON hIc = (HICON) LoadImage( m_hInstance, MAKEINTRESOURCE( GetIndexFromRes((int) m_sProp.esMyStatus, EstatResTbl)), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR );
DrawIconEx( hdc, m_sStatus[ 0 ].x + 4, nY, hIc, 16, 16, 0, 0, DI_NORMAL);
// set string with my info, status info,
TCHAR szText[3][256], szStatus[ MAX_LOADSTRING ];
LoadString( m_hInstance, m_sProp.esMyStatus, szStatus, MAX_LOADSTRING );
wsprintf( szText[0], L"%s (%s)", m_sProp.szMyName, szStatus );
LoadString( m_hInstance, IDS_ONLINEBUDDIES, szText[1], MAX_LOADSTRING );
LoadString( m_hInstance, IDS_OFFLINEBUDDIES, szText[2], MAX_LOADSTRING );
RECT rBuddy = { rWnd.left + 4, nY, rWnd.right - 4 - 4, nY + 16 };
int nTop[3] = { nY,
nY + MAINWND_BUDDYROWHEIGHT, // 'online'
nViewTop + MAINWND_BUDDYVIEWHEIGHT }; // 'offline'
int nLeft[3] = { rBuddy.left + MAINWND_BUDDYICONWIDTH,
rBuddy.left + 2,
rBuddy.left + 2};
LOGFONT lf1 = m_lfBuddyFont;
lf1.lfUnderline = m_sStatus[0].bTextUnderline;
lf1.lfWeight = m_sStatus[0].nTextWeight;
LOGFONT lf2 = m_lfBuddyFont;
lf2.lfUnderline = m_sStatus[2].bTextUnderline;
lf2.lfWeight = m_sStatus[2].nTextWeight;
LOGFONT* lfont[3] = {&lf1, &lf2, &lf2};
HFONT hF = NULL;
// Write text for displayables
for (i = 0; i < 3; i++) {
rBuddy.top = nTop[i];
rBuddy.bottom = nTop[i] + MAINWND_BUDDYROWHEIGHT;
rBuddy.left = nLeft[i];
SetBkColor( hdc, GetSysColor( COLOR_WINDOW ) );
hF = CreateFontIndirect( lfont[i]);
SetTextColor( hdc, m_sStatus[i].rgbText );
HFONT hOF = ( HFONT )SelectObject( hdc, hF );
DrawText( hdc, szText[i], -1, &rBuddy, DT_LEFT|DT_SINGLELINE|DT_VCENTER );
SelectObject( hdc, hOF );
DeleteObject( hF );
}
}
/************************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -