예제 #1
0
BOOL CDateDialog::OnInitDialog()
{
	CCSDialog::OnInitDialog();

	m_pListBox = &m_listBox; // set static member
	GetLocalTime(&m_time);
	m_id = GetUserDefaultLCID();

	EnumDateFormats(DateFmtEnumProc, m_id, DATE_SHORTDATE);
	EnumDateFormats(DateFmtEnumProc, m_id, DATE_LONGDATE);
	EnumTimeFormats(TimeFmtEnumProc, m_id, 0);

	m_pListBox = NULL;
	m_listBox.SetCurSel(0);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // EXCEPTION: OCX Property Pages should return FALSE
}
예제 #2
0
파일: date.c 프로젝트: RareHare/reactos
/* Init short date control box */
VOID
InitShortDateCB(HWND hwndDlg, LCID lcid)
{
    TCHAR szShortDateFmt[MAX_SAMPLES_STR_SIZE];
    INT nRetCode;

    /* Limit text lengths */
    SendMessage(GetDlgItem(hwndDlg, IDC_SHRTDATEFMT_COMBO),
                CB_LIMITTEXT,
                MAX_SHRTDATEFMT,
                0);
    SendMessage(GetDlgItem(hwndDlg, IDC_SHRTDATESEP_COMBO),
                CB_LIMITTEXT,
                MAX_SHRTDATESEP,
                0);

    /* Get current short date format */
    GetLocaleInfo(lcid,
                  LOCALE_SSHORTDATE,
                  szShortDateFmt,
                  MAX_SAMPLES_STR_SIZE);

    /* Clear all box content */
    SendMessage(GetDlgItem(hwndDlg, IDC_SHRTDATEFMT_COMBO),
                CB_RESETCONTENT,
                (WPARAM)0,
                (LPARAM)0);

    /* Enumerate short date formats */
    hwndEnum = GetDlgItem(hwndDlg, IDC_SHRTDATEFMT_COMBO);
    EnumDateFormats(ShortDateFormatEnumProc, lcid, DATE_SHORTDATE);

    /* Set current item to value from registry */
    nRetCode = SendMessage(GetDlgItem(hwndDlg, IDC_SHRTDATEFMT_COMBO),
                           CB_SELECTSTRING,
                           -1,
                           (LPARAM)szShortDateFmt);

    /* If it is not successful, add new value to list and select them */
    if (nRetCode == CB_ERR)
    {
        SendMessage(GetDlgItem(hwndDlg, IDC_SHRTDATEFMT_COMBO),
                    CB_ADDSTRING,
                    0,
                    (LPARAM)szShortDateFmt);
        SendMessage(GetDlgItem(hwndDlg, IDC_SHRTDATEFMT_COMBO),
                    CB_SELECTSTRING,
                    -1,
                    (LPARAM)szShortDateFmt);
    }
}
예제 #3
0
BOOL GetSupportedDateTimeFormats(
    LPCTSTR szDateFormatPrefix,
    LPCTSTR szTimeFormatPrefix,
    LPTSTR szBuffer,
    int nMaxChars)
{
    // Initialize the global strings
    szStringBufferBegin = szBuffer;
    szStringBuffer      = szBuffer;
    szStringBufferEnd   = szBuffer + nMaxChars - 1;

    // Put the date format prefix, if any
    if(szStringBuffer != NULL)
    {
        while(szStringBuffer < szStringBufferEnd && *szDateFormatPrefix != 0)
            *szStringBuffer++ = *szDateFormatPrefix++;
    }

    // Put the date formats
    EnumDateFormats(CollectFormatsProc, LOCALE_USER_DEFAULT, DATE_SHORTDATE);
    EnumDateFormats(CollectFormatsProc, LOCALE_USER_DEFAULT, DATE_LONGDATE);

    // Put the time format prefix, if any
    if(szStringBuffer != NULL)
    {
        while(szStringBuffer < szStringBufferEnd && *szTimeFormatPrefix != 0)
            *szStringBuffer++ = *szTimeFormatPrefix++;
    }

    // Put the time formats
    EnumTimeFormats(CollectFormatsProc, LOCALE_USER_DEFAULT, 0);

    // Terminate the string and return
    *szStringBuffer = 0;
    return TRUE;
}
예제 #4
0
///////////////////////////////////////////////////////////////////////////////////////////
//  Function:       InitNLSFields
//
//  Description:    Initialize NLS formatting fields for a given LCID
//
//  Comments:
//
///////////////////////////////////////////////////////////////////////////////////////////
void InitNLSFields(HWND hDlg, LCID lcid)
{
    TCHAR   tcsTemp[MAX_STR];
    HWND    hList = NULL;

    // Init larg number fields...
    LoadString(g_hInst, STR_LARGEPOSNUMBER, g_tcsTemp, MAX_STR);
    GetNumberFormat(lcid, 0, g_tcsTemp, NULL, tcsTemp, MAX_STR);
    SetWindowText(GetDlgItem(hDlg, IDC_POS_NUMBER), tcsTemp);

    LoadString(g_hInst, STR_LARGENEGNUMBER, g_tcsTemp, MAX_STR);
    GetNumberFormat(lcid, 0, g_tcsTemp, NULL, tcsTemp, MAX_STR);
    SetWindowText(GetDlgItem(hDlg, IDC_NEG_NUMBER), tcsTemp);

    // Init the currency field format...
    LoadString(g_hInst, STR_LARGEPOSNUMBER, g_tcsTemp, MAX_STR);
    GetCurrencyFormat(lcid, 0, g_tcsTemp, NULL, tcsTemp, MAX_STR);
    SetWindowText(GetDlgItem(hDlg, IDC_POS_CURRENCY), tcsTemp);

    LoadString(g_hInst, STR_LARGENEGNUMBER, g_tcsTemp, MAX_STR);
    GetCurrencyFormat(lcid, 0, g_tcsTemp, NULL, tcsTemp, MAX_STR);
    SetWindowText(GetDlgItem(hDlg, IDC_NEG_CURRENCY), tcsTemp);

    // Init time field format...
    // Delete our previous list of items...
    hList = GetDlgItem(g_hDlg, IDC_TIMEFORMAT);
    if(NULL != hList)
    {
        SendMessage(hList, CB_RESETCONTENT , 0, 0);

        // Enumerates the time formats that are available for a specified locale.
        EnumTimeFormats(EnumTimeFormatsProc, lcid, 0);
        SendMessage(hList, CB_SETCURSEL, 0, 0);          // item index
        SendMessage(hList, CB_GETLBTEXT, 0, (LPARAM) g_tcsTemp);
        GetTimeFormat(lcid, 0, NULL, g_tcsTemp, tcsTemp, MAX_STR);
        SetWindowText(GetDlgItem(hDlg, IDC_TIMESAMPLE), tcsTemp);
    }

    // Init calendar field format...
    // Delete our previous list of items...
    hList = GetDlgItem(g_hDlg, IDC_CALFORMAT);
    if(NULL != hList)
    {
        SendMessage(hList, CB_RESETCONTENT , 0, 0);

        // Enumerates the short date formats that are available for a specified locale.
        EnumCalendarInfo(EnumCalendarInfoProc, lcid, ENUM_ALL_CALENDARS, CAL_SCALNAME);
        SendMessage(hList, CB_SETCURSEL, 0, 0);          // item index
        SendMessage(hList, CB_GETLBTEXT, 0, (LPARAM) g_tcsTemp);
    }

    // Init short date field format...
    // Delete our previous list of items...
    hList = GetDlgItem(g_hDlg, IDC_SDATEFORMAT);
    if(NULL != hList)
    {
        SendMessage(hList, CB_RESETCONTENT , 0, 0);

        // Enumerates the short date formats that are available for a specified locale.
        EnumDateFormats(EnumSDateFormatsProc, lcid, DATE_SHORTDATE);
        SendMessage(hList, CB_SETCURSEL, 0, 0);          // item index
        SendMessage(hList, CB_GETLBTEXT, 0, (LPARAM) g_tcsTemp);
        GetDateFormat(lcid, 0, NULL, g_tcsTemp, tcsTemp, MAX_STR);
        SetWindowText(GetDlgItem(hDlg, IDC_SDATESAMPLE), tcsTemp);
    }

    // Init long date field format...
    // Delete our previous list of items...
    hList = GetDlgItem(g_hDlg, IDC_LDATEFORMAT);
    if(NULL != hList)
    {
        SendMessage(hList, CB_RESETCONTENT , 0, 0);

        // Enumerates the long date formats that are available for a specified locale
        EnumDateFormats(EnumLDateFormatsProc, lcid, DATE_LONGDATE);
        SendMessage(hList, CB_SETCURSEL, 0, 0);          // item index
        SendMessage(hList, CB_GETLBTEXT, 0, (LPARAM) g_tcsTemp);
        GetDateFormat(lcid, 0, NULL, g_tcsTemp, tcsTemp, MAX_STR);
        SetWindowText(GetDlgItem(hDlg, IDC_LDATESAMPLE), tcsTemp);
    }
}
예제 #5
0
NTSTATUS TextToFileTime(LPCTSTR szText, PFILETIME pFt)
{
    SYSTEMTIME st = {0};
    FILETIME ft;
    LPTSTR szEndChar = NULL;

    // Prepare the local variables to be filled by callbacks
    bDateConverted = FALSE;
    bTimeConverted = FALSE;
    szTempDateTime = szText;
    pTempSt = &st;

    // First of all, try to convert the filetime from human-readable form
    if(bDateConverted == FALSE)
        EnumDateFormats(EnumDateFormatsProc, LOCALE_USER_DEFAULT, DATE_SHORTDATE);
    if(bDateConverted == FALSE)
        EnumDateFormats(EnumDateFormatsProc, LOCALE_USER_DEFAULT, DATE_LONGDATE);
    if(bTimeConverted == FALSE)
        EnumTimeFormats(EnumTimeFormatsProc, LOCALE_USER_DEFAULT, 0);

    // If both date and time converted, we have succeeded
    if(bDateConverted && bTimeConverted)
    {
        if(!SystemTimeToFileTime(&st, &ft))
            return STATUS_INVALID_DATA_FORMAT;
        if(!LocalFileTimeToFileTime(&ft, pFt))
            return STATUS_INVALID_DATA_FORMAT;
        return STATUS_SUCCESS;
    }

    // Try to convert 64-bit value in the form of ################ or 0x################
    if(Text2Hex64(szText, (PLONGLONG)&ft) != ERROR_SUCCESS)
    {
        // Try to convert the 64-bit value in the form of ########-########
        ft.dwHighDateTime = StrToInt(szText, &szEndChar, 16);
        if(szEndChar == NULL || szEndChar[0] != _T('-'))
            return STATUS_INVALID_DATA_FORMAT;

        ft.dwLowDateTime = StrToInt(szEndChar+1, &szEndChar, 16);
        if(szEndChar[0] != 0 && szEndChar[0] != _T(' '))
            return STATUS_INVALID_DATA_FORMAT;
    }

    // We accept "FFFFFFFF-FFFFFFFF" as input
    if(ft.dwHighDateTime == 0xFFFFFFFF && ft.dwLowDateTime == 0xFFFFFFFF)
    {
        pFt->dwHighDateTime = ft.dwHighDateTime;
        pFt->dwLowDateTime = ft.dwLowDateTime;
        return STATUS_SUCCESS;
    }

    // We accept "00000000-00000000" as input
    if(ft.dwHighDateTime == 0 && ft.dwLowDateTime == 0)
    {
        pFt->dwHighDateTime = ft.dwHighDateTime;
        pFt->dwLowDateTime = ft.dwLowDateTime;
        return STATUS_SUCCESS;
    }

    // Convert from local time to file time
    if(LocalFileTimeToFileTime(&ft, pFt))
        return STATUS_SUCCESS;

    // Conversion failed
    return STATUS_INVALID_DATA_FORMAT;
}