windows api创建网络时钟
来源:互联网 发布:苹果版戒色软件 编辑:程序博客网 时间:2024/05/16 01:12
VOID CALLBACK NetTimerProc ( HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
WSADATA wsaData;
//初始化Socket库
WSAStartup(MAKEWORD(2,0),&wsaData);
//创建一根电线
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
SOCKADDR_IN sa;
sa.sin_family=AF_INET;
//设置电线连接服务器端的端口
sa.sin_port = htons(IPPORT_TIMESERVER);
//ping www.ac.time.cn--->201.72.145.8
sa.sin_addr.S_un.S_addr = inet_addr("216.229.0.179");
//为什么不用设置客户端的端口,难道不需要客户端的端口吗?
if(connect(sock,(SOCKADDR *)&sa,sizeof(sa))==SOCKET_ERROR)
{
ShowError();
return;
}
unsigned long ulTime = 0;
recv(sock,(char *)&ulTime,sizeof(unsigned long),0);
ulTime = ntohl(ulTime);//网络字节顺序转换为本地字节顺序
SYSTEMTIME st;
UINT64 uiCurTime, uiBaseTime, uiResult;
uiBaseTime = ((UINT64) HIGHTIME << 32) + LOWTIME;
uiCurTime = (UINT64)ulTime * (UINT64)10000000;
uiResult = uiBaseTime + uiCurTime;
FileTimeToSystemTime((LPFILETIME)&uiResult, &st);
TCHAR strNetTime[256];
ZeroMemory(strNetTime,sizeof(strNetTime)/sizeof(char));
wsprintf(strNetTime,"%i年 %i月 %i日 %i : %i : %i",st.wYear,st.wMonth,st.wDay,st.wHour+8,st.wMinute,st.wSecond);
HWND hwndStaticTime = GetDlgItem(hwnd,IDC_STATICTIME);
Edit_SetText(hwndStaticTime,strNetTime);
closesocket(sock);
WSACleanup();
}
- windows api创建网络时钟
- 《Windows API》创建窗口
- WINDOWS创建网络驱动器
- WINDOWS创建网络驱动器
- windows API 创建系统托盘图标
- windows API 创建系统托盘图标
- windows API 创建系统托盘图标
- windows api创建socket模板
- windows api创建定时器模板
- 创建时钟
- Windows Mobile创建网络连接
- windows 创建wifi共享网络
- Windows创建网络映射命令
- Windows Sockets API实现网络异步通讯
- Windows Sockets API实现网络异步通讯
- Windows Sockets API实现网络异步通讯
- Windows Sockets API实现网络异步通讯
- Windows Sockets API实现网络异步通讯
- flash定时器(秒级)
- 注意,react声明组件时,第一个字母必须大写。
- ACM之LeetCode中Longest Substring Without Repeating Characters
- Ipad 与 PC 内网传输文件
- 高精度模板BigInteger
- windows api创建网络时钟
- 1044. 火星数字(20)PAT乙级&&1100. Mars Numbers (20)PAT甲级
- python进行桶排序与基数排序总结
- Problem B. Sherlock and Watson Gym Secrets Google APAC 2017 University Test Round B
- Java代码判断数据库中某张表是否存在
- POJ 1064Cable master(二分查找)
- module 'scipy.misc' has no attribute 'imread'
- JavaScript 旋转的星空
- htk进阶学习