📄 calleriddisplayitem.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#include "CallerIdDisplayItem.hpp"
#include "resource.h"
#include <Common.hpp>
#include "Layout.hpp"
const UINT CCallerIDDisplayItem_t::sc_idxNumber = 0;
const UINT CCallerIDDisplayItem_t::sc_idxCallerID = 1;
/*------------------------------------------------------------------------------
CCallerIDDisplayItem_t::CCallerIDDisplayItem_t
Ctor
Parameters:
: String containing the phone number
: Length of the number or -1 to indicate a null-terminated string
------------------------------------------------------------------------------*/
CCallerIDDisplayItem_t::CCallerIDDisplayItem_t(
const WCHAR * c_wszNumber,
UINT cchNumber /* = - 1 */
)
{
PREFAST_ASSERT(c_wszNumber);
if (cchNumber == -1)
{
m_wstrNumber.assign(c_wszNumber);
}
else
{
m_wstrNumber.assign(c_wszNumber, cchNumber);
}
}
CCallerIDDisplayItem_t::~CCallerIDDisplayItem_t()
{
}
/*------------------------------------------------------------------------------
CCallerIDDisplayItem_t::Draw
Draws the display item
Parameters:
hdc: the device context to draw into
prc: the rectangle to draw into
fSelected: TRUE if this item is selected
Returns (HRESULT): indicating success or failure
------------------------------------------------------------------------------*/
HRESULT
CCallerIDDisplayItem_t::Draw(
HDC hdc,
const RECT * prc,
BOOL fSelected,
BOOL fTopItem
)
{
PREFAST_ASSERT(prc);
COLORREF crOld = -1;
UINT bkOld = -1;
HFONT hfntOld = NULL,
hfntNumber = NULL,
hfntCallerID = NULL;
WCHAR wszBuffer[MAX_PATH] = L"";
RECT rcDraw = *prc;
//Draw the background of the item
HRESULT hr = DrawBand(
hdc,
prc,
fSelected,
fTopItem
);
if (SUCCEEDED(hr))
{
hfntCallerID = PHGetFont(phfStandardTextBold); //LoadCachedFont(IDS_FONT_STANDARDTEXT_BOLD);
hfntNumber = PHGetFont(phfStandardText); //LoadCachedFont(IDS_FONT_STANDARDTEXT);
if (! hfntCallerID || !hfntNumber)
{
ASSERT(FALSE);
hr = HRESULT_FROM_WIN32(GetLastError());
}
}
if (SUCCEEDED(hr))
{
rcDraw.left += Layout_t::LabeledControlLabelMarginWidth();
rcDraw.right -= Layout_t::LabeledControlLabelMarginWidth();
rcDraw.top += Layout_t::CallRecordTextMarginHeight();
rcDraw.bottom -= Layout_t::CallRecordTextMarginHeight();
//select the desired fonts/colors/bkmode
hfntOld = (HFONT)SelectObject(hdc, hfntCallerID);
crOld = SetTextColor(hdc, (fSelected) ? PHGetColor(phcDisplayItemSelectedTextColor): PHGetColor(phcDisplayItemTextColor));
bkOld = SetBkMode(hdc, TRANSPARENT);
//draw the caller id at the top
GetSubItemText(sc_idxCallerID, wszBuffer, _countof(wszBuffer));
if (wszBuffer[0])
{
hr = (DrawText(
hdc,
wszBuffer,
-1,
&rcDraw,
DT_TOP | DT_LEFT | DT_SINGLELINE | DT_NOPREFIX
) != 0) ?
S_OK :
HRESULT_FROM_WIN32(GetLastError());
}
ZeroMemory(wszBuffer, sizeof(wszBuffer));
StringCchCopy(wszBuffer, _countof(wszBuffer), m_wstrNumber);
//draw the formatted number at the bottom
if (SUCCEEDED(hr) && wszBuffer[0])
{
SelectObject(hdc, hfntNumber);
hr = (DrawText(
hdc,
wszBuffer,
-1,
&rcDraw,
DT_BOTTOM | DT_LEFT | DT_SINGLELINE | DT_NOPREFIX
) != 0) ?
S_OK :
HRESULT_FROM_WIN32(GetLastError());
}
SelectObject(hdc, hfntOld);
SetTextColor(hdc, crOld);
SetBkMode (hdc, bkOld);
}
return hr;
}
/*------------------------------------------------------------------------------
CCallerIDDisplayItem_t::GetHeight
Returns the height of the item
------------------------------------------------------------------------------*/
BOOL
CCallerIDDisplayItem_t::GetHeight(
UINT * pfHeight
)
{
PREFAST_ASSERT(pfHeight);
*pfHeight = Layout_t::MainDefaultItemHeight();
return TRUE;
}
/*------------------------------------------------------------------------------
CCallerIDDisplayItem_t::GetText
Get the main text of the item
------------------------------------------------------------------------------*/
HRESULT
CCallerIDDisplayItem_t::GetText(
WCHAR *wszText,
INT cchText
)
{
return GetSubItemText(sc_idxNumber, wszText, cchText);
}
/*------------------------------------------------------------------------------
CCallerIDDisplayItem_t::GetSubItemText
Gets a specific text member of the item
------------------------------------------------------------------------------*/
HRESULT
CCallerIDDisplayItem_t::GetSubItemText(
UINT idxSubItem,
__in_ecount(cchText) WCHAR* wszText,
UINT cchText
)
{
PREFAST_ASSERT(wszText);
HRESULT hr = S_OK;
*wszText = 0;
switch (idxSubItem)
{
case sc_idxNumber:
StringCchCopy(wszText, cchText, m_wstrNumber);
break;
case sc_idxCallerID:
//cache the caller id
if (m_wstrCallerId[0])
{
StringCchCopy(wszText, cchText, m_wstrCallerId);
}
else
{
//Try to get the caller id associated with the number of the number
// ToDo: Need to check from database or contacts
/*if (!(GetCallerIdFromDatabase(m_wstrNumber, wszText, cchText) && !GetCallerIdFromContacts(m_wstrNumber, wszText, cchText)) || !wszText[0])
{
const WCHAR *c_wszUnknown = LoadReadOnlyString(IDS_CALLERID_UNKNOWNEXTERNAL);
if (! c_wszUnknown)
{
ASSERT(FALSE);
c_wszUnknown = L"Unknown";
}
wcsncpy(
wszText,
c_wszUnknown,
cchText
);
wszText[cchText - 1] = 0;
}*/
const WCHAR *c_wszUnknown = (const WCHAR *)LoadString(
GlobalData_t::s_ModuleInstance,
IDS_CALLERID_UNKNOWNEXTERNAL,
NULL,
0
);
StringCchCopy(wszText, cchText, c_wszUnknown);
wszText[cchText - 1] = 0;
m_wstrCallerId.assign(wszText);
}
break;
default:
hr = S_FALSE;
}
wszText[cchText - 1] = 0;
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -