📄 voipdemo.cpp
字号:
DoMainMouseMove()
Check if the mouse intercepts any of the buttons on the toolbar.
************************************************************************************************/
LRESULT DoMainMouseMove( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
int xPos = LOWORD( lParam );
int yPos = HIWORD( lParam );
int onButtonPointed = m_nButtonPointed;
m_nButtonPointed = -1;
// Check for hitting the toolbar buttons only if toolbar is visible
if ( m_sProp.bToolbar )
{
for ( int c = 0; c < sizeof ( m_sButtons ) / sizeof ( SBUTTONDATA ); c++ )
{
if ( xPos >= m_sButtons[ c ].x && xPos < m_sButtons[ c ].x + m_sButtons[ c ].cx &&
yPos >= GetSystemMetrics( SM_CYMENU ) + m_sButtons[ c ].y && yPos < GetSystemMetrics( SM_CYMENU ) + m_sButtons[ c ].y + m_sButtons[ c ].cy )
{
m_nButtonPointed = c;
break;
}
}
}
else
m_nButtonPointed = -1;
// If the selected button has changed, revalidate the 2 frames
if ( m_nButtonPointed != onButtonPointed )
{
InvalidateButton( onButtonPointed );
InvalidateButton( m_nButtonPointed );
}
return 0;
}
/************************************************************************************************
CenterDialog()
Center the dialog passed in using rect rt1 as it's specifying rectangle.
************************************************************************************************/
VOID
CenterDialog(HWND hDlg, RECT& rt1)
{
int nScreenWidth = GetSystemMetrics( SM_CXFULLSCREEN );
int nScreenHeight = GetSystemMetrics( SM_CYFULLSCREEN );
int NewPosX = ( nScreenWidth - ( rt1.right - rt1.left ) ) / 2;
int NewPosY = ( nScreenHeight - ( rt1.bottom - rt1.top ) ) / 2;
// if the box is larger than the physical screen
if ( NewPosX < 0 )
NewPosX = 0;
if ( NewPosY < 0 )
NewPosY = 0;
SetWindowPos( hDlg, 0, NewPosX, NewPosY,
0, 0, SWP_NOZORDER | SWP_NOSIZE );
}
//
// ListView related functions
//
/************************************************************************************************
InitListViews
Creates listview objects for buddy storage and display, saves HWNDs to global variables.
Also creates the listview owned imagelists to display buddy status.
Note: The font used inside the listviews is a globally-instantiated font m_hFont
************************************************************************************************/
BOOL InitListViews() {
// Online buddy listview
m_hwndOnlineView = CreateWindowEx( LVS_EX_FULLROWSELECT, WC_LISTVIEW, TEXT( "Listview" ),
LVS_SHOWSELALWAYS|LVS_NOCOLUMNHEADER|LVS_AUTOARRANGE|LVS_REPORT|WS_CHILD|WS_TABSTOP|LVS_SORTASCENDING,
4, MAINWND_BUDDYVIEWYSTART,
MAINWND_DEFAULTWIDTH - 8, MAINWND_BUDDYVIEWHEIGHT, // some crummy co-ordinates as we'll have to redraw anyway
m_hWndMain, // parent window of this window
( HMENU )IDC_ONLINEBUDDYLIST, // control identifier (windows defined)
m_hInstance, // app or module associated with window
NULL ); // NULL creating a control
if (!m_hwndOnlineView)
return FALSE;
// Offline buddy listview
m_hwndOfflineView = CreateWindowEx( LVS_EX_FULLROWSELECT, WC_LISTVIEW, TEXT( "Listview" ),
LVS_SHOWSELALWAYS|LVS_NOCOLUMNHEADER|LVS_AUTOARRANGE|LVS_REPORT|WS_CHILD|WS_TABSTOP|LVS_SORTASCENDING,
4, MAINWND_BUDDYVIEWYSTART + MAINWND_BUDDYROWHEIGHT + MAINWND_BUDDYVIEWHEIGHT,
MAINWND_DEFAULTWIDTH - 8, MAINWND_BUDDYVIEWHEIGHT, // some crummy co-ordinates as we'll have to redraw anyway
m_hWndMain, // parent window of this window
( HMENU )IDC_OFFLINEBUDDYLIST, // control identifier (windows defined)
m_hInstance, // app or module associated with window
NULL ); // NULL creating a control
if (!m_hwndOfflineView)
return FALSE;
// create the online image list (all but offline)
HIMAGELIST himlListOn = ImageList_Create (16, 16, ILC_COLORDDB, 10, 20);
HICON hIcon = NULL;
int result = 0;
// populate the image list
int res = -1;
for (int i = 0; GetResFromIndex(i, OnlineIconResTbl) != END_VAL; i++) {
res = GetResFromIndex(i, OnlineIconResTbl);
//res = GetResFromIndex(i, OnlineIconResTbl)
hIcon = (HICON) LoadImage(m_hInstance, MAKEINTRESOURCE(res), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
if (!hIcon) {
VOID* lpBuffer = NULL;
DWORD dwError = GetLastError();
DWORD dwRes = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, NULL, (LPTSTR) &lpBuffer, 50, NULL);
MessageBox( NULL, (LPCTSTR)lpBuffer, L"Error", MB_OK | MB_ICONINFORMATION );
if (dwRes != 0) LocalFree(lpBuffer);
ImageList_Destroy(himlListOn);
return FALSE;
}
result = ImageList_AddIcon(himlListOn, hIcon);
}
// Note: the image list will now be taken care of by the listview
HIMAGELIST h = NULL;
h = ListView_SetImageList(m_hwndOnlineView, himlListOn, LVSIL_SMALL);
// create offline image list
hIcon = NULL;
HIMAGELIST himlListOff = ImageList_Create(16, 16, ILC_COLORDDB, 1, 4);
hIcon = (HICON) LoadImage(m_hInstance, MAKEINTRESOURCE(IDI_STATUSOFFLINE), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
if (!hIcon) {
ImageList_Destroy(himlListOff);
return FALSE;
}
ImageList_AddIcon(himlListOff, hIcon);
// Note: the image list will now be taken care of by the listview
h = ListView_SetImageList (m_hwndOfflineView, himlListOff, LVSIL_SMALL);
// column 1: Icon - Username (Status)
LV_COLUMN lvc;
ZeroMem(lvc);
lvc.mask = LVCF_WIDTH|LVCF_FMT|LVCF_TEXT;
lvc.fmt = LVCFMT_LEFT|LVCFMT_IMAGE;
lvc.cx = 170;
lvc.pszText = L"1";
lvc.iSubItem = 0;
result = ListView_InsertColumn( m_hwndOnlineView, 0, &lvc );
result = ListView_InsertColumn( m_hwndOfflineView, 0, &lvc );
m_hFont = CreateFontIndirect( &m_lfBuddyFont );
SendMessage( m_hwndOnlineView, WM_SETFONT, ( WPARAM )m_hFont, TRUE );
SendMessage( m_hwndOfflineView, WM_SETFONT, ( WPARAM )m_hFont, TRUE );
ListView_SetTextColor( m_hwndOnlineView, m_sStatus[LV_ONLINEBUDDY_STATUSDATA_I].rgbText);
ListView_SetTextColor( m_hwndOfflineView, m_sStatus[LV_OFFLINEBUDDY_STATUSDATA_I].rgbText);
return TRUE;
}
/************************************************************************************************
AddBuddyListView()
This call will add the specified buddy to a listview object for display in the program's
contact list. The buddy's name is placed in a string with his/her status for display and
an icon is selected from the appropriate listview's imagelist for display. Finally, the
buddy's IRTCBuddy pointer is stored as the ListView's LPARAM item for further use and retrieval
of more buddy information.
All phone buddies and non-offline computer buddies will be placed in the online buddy list
If the buddy is offline or has no status and is a computer he/she will be placed in the offline
buddy list .
Note: The ListView postfix of AddBuddy identifies this method from the equivalent RTC method.
(defined in the global header rtcs.h)
************************************************************************************************/
BOOL
AddBuddyListView(
ESTATUS esStat,
IRTCBuddy* pBuddy,
TCHAR* szName,
BUDDYTYPE eBtype
)
{
TCHAR szText[ 256 ], szStatus[ MAX_LOADSTRING ];
LVITEM lviNew;
lviNew.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
LoadString( m_hInstance, esStat, szStatus, MAX_LOADSTRING );
wsprintf( szText, L"%s (%s)", szName, // copy name
szStatus ); // copy status
lviNew.iSubItem = 0;
lviNew.pszText = szText;
lviNew.lParam = (LONG) pBuddy;
// store in the appropriate listview
if (esStat == ES_OFFLINE || esStat == ES_NOSTATUS) {
lviNew.iImage = 0;
lviNew.iItem = ListView_GetItemCount( m_hwndOfflineView );
ListView_InsertItem(m_hwndOfflineView, &lviNew);
} else {
lviNew.iImage = (eBtype == BT_PHONE) ? GetIndexFromRes(IDI_STATUSPHONEBUDDY, OnlineIconResTbl) : GetIndexFromRes((int)esStat, EstatIconTbl );
lviNew.iItem = ListView_GetItemCount( m_hwndOnlineView );
ListView_InsertItem(m_hwndOnlineView, &lviNew);
}
DEBUGMSG( 1, (L"Voipdemo: adding buddy %s, with IRTCBuddy* %i to listview", szText, pBuddy) );
return TRUE;
}
/************************************************************************************************
FindAndRemoveBuddyListView()
This call will locate the buddy specified by pBuddy in the listview and call DeleteItem
on it. The listview will Release() the specified buddy upon a successful delete (handled
by LVN_DELETEITEM in WM_COMMAND of MainWndProc()).
Note: The ListView postfix identifies this method from the equivalent RTC method.
(defined in the global header rtcs.h)
************************************************************************************************/
BOOL
FindAndRemoveBuddyListView( IRTCBuddy* pBuddy, ESTATUS eStat )
{
HWND hwndView = NULL;
if (eStat == ES_OFFLINE || eStat == ES_NOSTATUS)
hwndView = m_hwndOfflineView;
else
hwndView = m_hwndOnlineView;
LV_FINDINFO lvif;
lvif.flags = LVFI_PARAM;
lvif.lParam = (LONG) pBuddy;
LVITEM lvi;
ZeroMem(lvi);
lvi.iItem = ListView_FindItem( hwndView, LISTVIEW_BEGIN, &lvif );
if (lvi.iItem < 0) {
// not found
DEBUGMSG( 1, (L"VoipDemo: EditListView() Unable to find item item with lparam 0x%lx in listview 0x%lx", (PVOID) pBuddy, hwndView ) );
return FALSE;
}
// what to do if not deleted properly?
lvi.iItem = ListView_DeleteItem(hwndView, lvi.iItem);
return TRUE;;
}
/************************************************************************************************
ChangeBuddyListView()
This call will locate the buddy specified by pBuddy in the listview update its information
based upon the new info specified. This information will only affect the listview display
status of the buddy, not the buddy's actual data.
Note: The ListView postfix identifies this method from the equivalent RTC method.
(defined in the global header rtcs.h)
************************************************************************************************/
BOOL
ChangeBuddyListView(
IRTCBuddy* pBuddy,
WCHAR* szName,
BUDDYTYPE enBt,
ESTATUS esStat
)
{
TCHAR szText[ 256 ], szStatus[ MAX_LOADSTRING ];
HWND hwndView = (esStat != ES_OFFLINE) ? m_hwndOnlineView : m_hwndOfflineView;
LV_FINDINFO lvif;
lvif.flags = LVFI_PARAM;
lvif.lParam = (LONG) pBuddy;
LVITEM lvi;
ZeroMem(lvi);
lvi.iItem = ListView_FindItem( hwndView, LISTVIEW_BEGIN, &lvif );
if (lvi.iItem < 0) {
// not found
DEBUGMSG( 1, (L"VoipDemo: EditListView() Unable to find item item with lparam 0x%lx in listview 0x%lx", (PVOID) pBuddy, hwndView ) );
return FALSE;
}
lvi.mask = LVIF_TEXT | LVIF_IMAGE;
LoadString( m_hInstance, esStat, szStatus, MAX_LOADSTRING );
wsprintf( szText, L"%s (%s)", szName, // copy name
szStatus ); // copy status
lvi.pszText = szText;
// figure out which picture to display
if (esStat == ES_OFFLINE) {
lvi.iImage = 0;
} else {
lvi.iImage = (enBt == BT_PHONE) ? GetIndexFromRes(IDI_STATUSPHONEBUDDY, OnlineIconResTbl) : GetIndexFromRes((int)esStat, EstatIconTbl );
}
if (ListView_SetItem(hwndView, &lvi) ) {
DEBUGMSG( 1, (L"VoipDemo: EditListView() modifying item %s, with lparam 0x%lx to listview", szText, (PVOID) pBuddy) );
return TRUE;
}
DEBUGMSG( 1, (L"VoipDemo: EditListView() Unable to modify item item %s with lparam 0x%lx", szText, (PVOID) pBuddy) );
return FALSE;
}
/************************************************************************************************
ChangeBuddyListView()
Determine which listview the buddy is in, then change his displayed status from his RTC status
type. This may cause the buddy to move to a different list (if he goes offline). Also, need
to properly handle the case if the buddy is currently selected.
Assumption:
A computer buddy is assumed as phone buddy status changes will be ignored by RTC Event
Note: The ListView postfix identifies this method from the equivalent RTC method.
(defined in the global header rtcs.h)
************************************************************************************************/
VOID
DoBuddyStatusChangeListView(IRTCBuddy* pBuddy)
{
// which listview is the buddy currently in?
// does he need to be moved to a different listview? (has he gone offline / come online)
HWND hwndCurrentList = NULL;
HWND hwndDestList = NULL;
ESTATUS eNewStat = GetBuddyStatus(pBuddy, BT_COMPUTER);
if (eNewStat == ES_NOSTATUS)
return;
LV_FINDINFO lvif;
ZeroMem(lvif);
lvif.flags = LVFI_PARAM;
lvif.lParam = (LONG) pBuddy;
LVITEM lvi;
ZeroMem(lvi);
// prepare the name/status string
WCHAR szText[200], szStatus[MAX_LOADSTRING];
LoadString(m_hInstance, eNewStat, szStatus, MAX_LOADSTRING);
BSTR bstrName = NULL;
pBuddy->get_Name(&bstrName);
wsprintf(szText, L"%s (%s)", bstrName, szStatus);
SysFreeString(bstrName);
// set up the listview item
lvi.mask = LVIF_PARAM | LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
lvi.pszText = szText;
lvi.iImage = GetIndexFromRes(eNewStat, EstatIconTbl); // safe as we're not doing status for phone buddies
lvi.lParam = (LONG) pBuddy;
BOOL bChangeLists = FALSE;
// find the item
lvi.iItem = ListView_FindItem(m_hwndOnlineView, LISTVIEW_BEGIN, &lvif);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -