msgview.cpp
来自「WIndows mobile 5.0 pocket pc sdk sample 」· C++ 代码 · 共 564 行 · 第 1/2 页
CPP
564 行
// Now allocate a buffer.
CPR((pb = new BYTE[cb]))
// Copy the properties over.
pRowSet = (LPSRowSet)pb;
pVal = (LPSPropValue)(pb + ( sizeof(SRowSet) + sizeof(SRow) ));
// initialize
pRowSet->aRow[0].cValues = 0;
pRowSet->aRow[0].lpProps = pVal;
// begin filling the values
pVal->ulPropTag = PR_RECIPIENT_TYPE;
pVal->Value.ul = MAPI_TO;
++pVal;
++pRowSet->aRow[0].cValues;
pVal->ulPropTag = PR_EMAIL_ADDRESS;
pVal->Value.lpszW = L"14255550000"; // a default number
++pVal;
++pRowSet->aRow[0].cValues;
pVal->ulPropTag = PR_ADDRTYPE;
pVal->Value.lpszW = L"SMS";
++pVal;
++pRowSet->aRow[0].cValues;
pVal->ulPropTag = PR_MESSAGE_CLASS;
pVal->Value.lpszW = (LPTSTR)kszSMSMsgClass;
++pVal;
++pRowSet->aRow[0].cValues;
pRowSet->cRows = 1;
hr = m_pMsg->ModifyRecipients(MODRECIP_ADD, (LPADRLIST)pRowSet);
CHR(hr);
Error:
delete [] pb;
}
void CMsgView::OnCommand(WPARAM wParam, LPARAM lParam)
{
HRESULT hr = S_OK;
BOOL fSend = FALSE;
switch (LOWORD(wParam))
{
case ID_RECORD:
{
fSend = TRUE;
break;
}
case ID_IGNORE:
{
fSend = TRUE;
break;
}
}
if (fSend)
{
//The user wants to send, so let's fill in our return SMS number as the "to" field
SPropValue rgProps[6];
// Change the message class on this message to be a "normal" SMS
rgProps[0].ulPropTag = PR_MESSAGE_CLASS;
rgProps[0].Value.lpszW = (TCHAR*)&(kszSMSMsgClass[0]);
// Also change the subject to add the answer to our question
ULONG cValues = 0;
SPropValue *pspv = NULL;
SizedSPropTagArray(1, spta) = { 1, PR_SUBJECT };
BOOL fdrewsub = FALSE;
if (m_pMsgBase)
{
hr = m_pMsgBase->GetProps((SPropTagArray *) &spta, MAPI_UNICODE, &cValues, &pspv);
CHR(hr);
}
TCHAR szReplyText[160]; //max_sms
wsprintf(szReplyText, L"%s: %s", LOWORD(wParam)==ID_RECORD ? L"RECORD" : L"IGNORE", pspv[0].Value.lpszW);
rgProps[1].ulPropTag = PR_SUBJECT;
rgProps[1].Value.lpszW = szReplyText;
rgProps[2].ulPropTag = PR_CONTENT_LENGTH;
rgProps[2].Value.ul = 0;
rgProps[3].ulPropTag = PR_SENDER_EMAIL_ADDRESS;
rgProps[3].Value.lpszW = L"14255550000";
rgProps[4].ulPropTag = PR_MSG_STATUS;
rgProps[4].Value.ul = MSGSTATUS_RECTYPE_SMS;
rgProps[5].ulPropTag = PR_PROOF_OF_DELIVERY_REQUESTED;
rgProps[5].Value.ul = 0;
// Now set the new message properties
hr = m_pMsg->SetProps(6, rgProps, NULL);
CHR(hr);
//and add our service as a recipient
AddToField();
hr = m_pMsg->SubmitMessage(0);
CHR(hr);
//and we're done with the form
hr = m_pForm->SetMessageStatus(IMessageFormHostEx::CMS_SENT);
CHR(hr);
hr = m_pForm->CloseForm();
CHR(hr);
}
Error:
return;
}
void CMsgView::OnPaint(HDC hdc)
{
HRESULT hr = S_OK;
//draw our TV screen
HBITMAP hBitmap = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_BITMAP_TVSET));
HDC memDC = CreateCompatibleDC(hdc);
HBITMAP hBitmapOld = (HBITMAP)SelectObject(memDC, hBitmap);
RECT rc;
GetClientRect(m_hWnd, &rc);
BITMAP bm;
GetObject(hBitmap, sizeof(BITMAP), &bm);
StretchBlt(hdc, rc.top, rc.left, rc.right-rc.left, rc.bottom-rc.top,
memDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
//cleanup bitmap drawing
SelectObject(memDC, hBitmapOld);
DeleteDC(memDC);
DeleteObject(hBitmap);
rc.left = 50;
rc.right = 190;
rc.top = 140;
rc.bottom = 220;
//black-on-white text
SetTextColor(hdc, RGB(0,0,0));
SetBkColor(hdc, RGB(255,255,255));
ULONG cValues = 0;
SPropValue *pspv = NULL;
SizedSPropTagArray(1, spta) = { 1, PR_SUBJECT };
BOOL fdrewsub = FALSE;
if (m_pMsgBase)
{
hr = m_pMsgBase->GetProps((SPropTagArray *) &spta, MAPI_UNICODE, &cValues, &pspv);
CHR(hr);
if (cValues == 1)
{
if (pspv[0].Value.lpszW)
{
DrawText(hdc, pspv[0].Value.lpszW, -1, &rc, DT_NOPREFIX | DT_LEFT | DT_WORDBREAK);
fdrewsub = TRUE;
}
}
}
if ((!fdrewsub) && (m_pMsg))
{
hr = m_pMsg->GetProps((SPropTagArray *) &spta, MAPI_UNICODE, &cValues, &pspv);
CHR(hr);
if (cValues == 1)
{
if (pspv[0].Value.lpszW)
{
DrawText(hdc, pspv[0].Value.lpszW, -1, &rc, DT_NOPREFIX | DT_LEFT | DT_WORDBREAK);
}
}
}
Error:
return;
}
//*******************************************************************************************
//
// WndProcStatic - Static WndProc entry point to redirect to the member WndProc
//
//*******************************************************************************************
LRESULT CALLBACK CMsgView::WndProcStatic(
HWND hWnd, // In: HWND for window
UINT message, // In: Message to process
WPARAM wParam, // In/Out: Message-specific WPARAM
LPARAM lParam // In/Out: Message-specific LPARAM
)
{
CMsgView* pMsgView = (CMsgView *)GetWindowLong(hWnd, GWL_USERDATA);
LRESULT lResult = 0;
switch (message)
{
case WM_CREATE:
// Get the buffer we were passed and store it.
pMsgView = (CMsgView*)(((LPCREATESTRUCT)lParam)->lpCreateParams);
SetWindowLong(hWnd, GWL_USERDATA, (LPARAM)pMsgView);
if (NULL == pMsgView)
{
lResult = -1;
break;
}
// Intentional fall-through
default:
if (NULL != pMsgView)
{
lResult = pMsgView->WndProc(hWnd, message, wParam, lParam);
}
break;
}
return lResult;
}
//*******************************************************************************************
//
// CreateTVWindow - Register the window class for the game and create the window.
//
//*******************************************************************************************
BOOL CMsgView::CreateTVWindow(
LPCTSTR pszClass,
LPCTSTR pszTitle,
DWORD dwStyle,
LPRECT pRC,
HWND hwndForm,
UINT nID)
{
ASSERT (pszClass != NULL);
WNDCLASS wc;
if (!ms_fRegistered)
{
ASSERT( !GetClassInfo(g_hInst, pszClass, &wc) );
ZeroMemory(&wc, sizeof(wc));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = CMsgView::WndProcStatic;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = g_hInst;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = pszClass;
ms_fRegistered = RegisterClass(&wc);
}
m_hWnd = ::CreateWindow(pszClass, pszTitle, dwStyle, 0, 0,
(*pRC).right-(*pRC).left, (*pRC).bottom - (*pRC).top, hwndForm,
(HMENU) nID, g_hInst, (LPVOID) this);
//if this is a compose form, we need to add buttons for the user's choices
if (m_fCompose)
{
::CreateWindow(L"BUTTON", L"Record", WS_VISIBLE, 55, 190, 60, 25, m_hWnd, (HMENU)ID_RECORD, g_hInst, 0);
::CreateWindow(L"BUTTON", L"Ignore", WS_VISIBLE, 125, 190, 60, 25, m_hWnd, (HMENU)ID_IGNORE, g_hInst, 0);
}
return (NULL != m_hWnd);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?