Beispiel #1
0
/*-------------------------------------------
  start SNTP session
  check RAS connection and call SNTPStart()
---------------------------------------------*/
BOOL StartSyncTime(HWND hwnd, BOOL bRAS)
{
	if(m_socket != INVALID_SOCKET || m_hGetHost != NULL) return FALSE;
	
	if(bRAS && !IsRASConnection()) return FALSE;
	
	return SNTPStart(hwnd);
}
Beispiel #2
0
/*---------------------------------------------------
	window procedure to process WinSock
---------------------------------------------------*/
LRESULT CALLBACK SNTPWndProc(HWND hwnd, UINT message,
	WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
		case WSOCK_GETHOST: // get IP address
			OnGetHost(hwnd, wParam, lParam);
			return 0;
		case WSOCK_SELECT:  // receive SNTP data
			OnReceive(hwnd, wParam, lParam);
			return 0;
		case (WM_USER + 10):  // command to start
			SNTPStart(hwnd, (char*)lParam);
			return 0;
	}

	return DefWindowProc(hwnd, message, wParam, lParam);
}
Beispiel #3
0
/*---------------------------------------------------
    command to start syncronizing
---------------------------------------------------*/
void StartSyncTime(HWND hwndParent, char* pServer, int nto)
{
	HWND hwnd;
	SYSTEMTIME st;
	char section[] = "SNTP";
	char server[80], s[80];

	if(g_socket != -1 || g_hGetHost != NULL) return;

	if(pServer == NULL || *pServer == 0)
	{
		GetMyRegStr(section, "Server", server, 80, "");
		pServer = server;
	}
	if(nto == 0)
		nto = GetMyRegLong(section, "Timeout", 1000);

	if(*pServer == 0) return;
	hwnd = GetDlgItem(hwndParent, 1);
	if(!hwnd) return;

	nMinuteDif = 0;
	GetMyRegStr(section, "Dif", s, 80, "");
	if(s[0])
	{
		int h, m;
		time2int(&h, &m, s);
		nMinuteDif = h * 60 + m;
	}

	GetLocalTime(&st);
	nLastDay = st.wDay;
	SetMyRegLong(section, "LastDay", nLastDay);
	dwTickCount = GetTickCount();
	bFirst = FALSE;

	nTimeout = nto;

	SNTPStart(hwnd, pServer);
}