求助,得到系统时间。

rambo2008 2009-09-09 02:55:25
小弟想在window mobile设备上,得到当前系统时间,然后把时间写入一个指定的.TXT中。

不用CTime和CString相关的东西;用GetSystemTime或GetLocalTime,怎么问代码要怎么写?

现在帖出代码,下面代码可以把得到短信的内容写入到a.txt中,如何再加上得到短信的时间????


HRESULT CMailRuleClient::ProcessMessage(IMsgStore *pMsgStore, ULONG cbMsg, LPENTRYID lpMsg,
ULONG cbDestFolder, LPENTRYID lpDestFolder, ULONG *pulEventType, MRCHANDLED *pHandled)
{
HRESULT hr = S_OK;
SizedSPropTagArray(1, sptaSubject) = { 1, PR_SUBJECT};
SizedSPropTagArray(1, sptaEmail) = { 1, PR_SENDER_EMAIL_ADDRESS};
ULONG cValues = 0;
SPropValue *pspvSubject = NULL;
SPropValue *pspvEmail = NULL;
IMessage *pMsg = NULL;
HRESULT hrRet = S_OK;

// Get the message from the entry ID
hr = pMsgStore->OpenEntry(cbMsg, lpMsg, NULL, 0, NULL, (LPUNKNOWN *) &pMsg);
if (FAILED(hr))
{

RETAILMSG(TRUE, (TEXT("Unable to get the message!\r\n")));
goto Exit;
}

// For SMS, the subject is also the message body
hr = pMsg->GetProps((SPropTagArray *) &sptaSubject, MAPI_UNICODE, &cValues, &pspvSubject);
if (FAILED(hr))
{

RETAILMSG(TRUE, (TEXT("Unable to get the message body!\r\n")));
goto Exit;
}
// get the sender's address or phone number
hr = pMsg->GetProps((SPropTagArray *) &sptaEmail, MAPI_UNICODE, &cValues, &pspvEmail);

if (FAILED(hr))
{

RETAILMSG(TRUE, (TEXT("Couldn't get the sender's address!\r\n")));

goto Exit;
}

if(wcsstr(pspvEmail->Value.lpszW,_T("100861")) != NULL) //拦截10086
{

hr = DeleteMessage(pMsgStore, pMsg, cbMsg, lpMsg, cbDestFolder, lpDestFolder, pulEventType, pHandled);//从短信列表中删除
//写入文件
HANDLE hf = CreateFile(TEXT("\\a.txt"),GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,NULL,NULL);
if(hf == INVALID_HANDLE_VALUE)
return FALSE;

//utf-16转utf-8
int Size = WideCharToMultiByte(CP_ACP, 0, pspvSubject->Value.lpszW, -1, NULL, 0,NULL,NULL);
char *temp = new char[Size + 1];

if( !temp )
{
delete []temp;
OutputDebugString(L"初始化失败!");
return FALSE;
}
temp[Size] = '\0';
//映射一个unicode字符串到一个多字节字符串。
WideCharToMultiByte (CP_ACP, 0, pspvSubject->Value.lpszW, -1, temp, Size,NULL,NULL);

SetFilePointer (hf, NULL, NULL, FILE_END) ;

DWORD dwWritten=0;


temp=temp+"000000";



if( !WriteFile(hf,temp,strlen(temp)*sizeof(char),&dwWritten,NULL) )
{
CloseHandle(hf);
return FALSE;
}

WriteFile(hf,"\n",strlen("\n")*sizeof(char),&dwWritten,NULL);
delete []temp;
CloseHandle(hf);


}
else
{
// a 'normal' message, pass it on
*pHandled = MRC_NOT_HANDLED;
}


// Clean up
Exit:
if (pspvEmail)
{
MAPIFreeBuffer(pspvEmail);
}
if (pspvSubject)
{
MAPIFreeBuffer(pspvSubject);
}
if (pMsg)
{
pMsg->Release();
}


return hr;
}
...全文
95 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
rambo2008 2009-09-10
  • 打赏
  • 举报
回复
清楚了 ,谢谢大家。
MoXiaoRab 2009-09-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 rambo2008 的回复:]
UP
[/Quote]
LZ还有哪里不清楚?
jyh_baoding 2009-09-10
  • 打赏
  • 举报
回复
方法很多,基本是取出时间,按要求格式化,保存
qq539929779 2009-09-10
  • 打赏
  • 举报
回复
time(0);
rambo2008 2009-09-09
  • 打赏
  • 举报
回复
UP
oyljerry 2009-09-09
  • 打赏
  • 举报
回复
GetLocalTime() 等获得的是SYSTEMTIME等结构,里面就有年月日小时分秒等信息
zoulie 2009-09-09
  • 打赏
  • 举报
回复
C语言的行不?
time_t t = time(0);
char tmp[64];
time_t m = 0; //消除pclint警告

m = strftime( tmp, sizeof(tmp), "%Y%U",localtime(&t) );
muzizongheng 2009-09-09
  • 打赏
  • 举报
回复
VOID PrintTime( CHAR* msg )
{
SYSTEMTIME st;

GetLocalTime( &st );

FormatSt( st, (CHAR*) buf );


GetSystemTime( &tst );
FormatSt( tst, buf );
printf("GetSystemTime: %s\n", buf);


printf("%s %s\n", msg, buf);

}

zaodt 2009-09-09
  • 打赏
  • 举报
回复
GetLocalTime 获取本时区时间,然后根据你的需要写入文件即可;


SYSTEMTIME st;
GetLocalTime( &st );

TCHAR buf[50];

wprintf( _T("%d年%d..."), st.... );
muzizongheng 2009-09-09
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <string.h>
#include <time.h>

void main( void )
{
struct tm *newtime;
char am_pm[] = "AM";
time_t long_time;

time( &long_time ); /* Get time as long integer. */
newtime = localtime( &long_time ); /* Convert to local time. */

if( newtime->tm_hour > 12 ) /* Set up extension. */
strcpy( am_pm, "PM" );
if( newtime->tm_hour > 12 ) /* Convert from 24-hour */
newtime->tm_hour -= 12; /* to 12-hour clock. */
if( newtime->tm_hour == 0 ) /*Set hour to 12 if midnight. */
newtime->tm_hour = 12;

printf( "%.19s %s\n", asctime( newtime ), am_pm );
}

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧