Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.8 KiB

  1. /* npdate - Code for getting and inserting current date and time.
  2. * Copyright (C) 1984-1995 Microsoft Inc.
  3. */
  4. #include "precomp.h"
  5. /* ** Replace current selection with date/time string.
  6. * if fCrlf is true, date/time string should begin
  7. * and end with crlf
  8. */
  9. VOID FAR InsertDateTime (BOOL fCrlf)
  10. {
  11. SYSTEMTIME time ;
  12. TCHAR szDate[80] ;
  13. TCHAR szTime[80] ;
  14. TCHAR szDateTime[sizeof(szDate) + sizeof(szTime) + 10] = TEXT("");
  15. DWORD locale;
  16. BOOL bMELocale;
  17. DWORD dwFlags = DATE_SHORTDATE;
  18. // See if the user locale id is Arabic or Hebrew.
  19. locale = GetUserDefaultLCID();
  20. bMELocale = ((PRIMARYLANGID(LANGIDFROMLCID(locale)) == LANG_ARABIC) ||
  21. (PRIMARYLANGID(LANGIDFROMLCID(locale)) == LANG_HEBREW));
  22. locale = MAKELCID( MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), SORT_DEFAULT) ;
  23. // Get the time
  24. GetLocalTime( &time ) ;
  25. if (bMELocale)
  26. {
  27. //Get the date format that matches the edit control reading direction.
  28. if (GetWindowLong(hwndEdit, GWL_EXSTYLE) & WS_EX_RTLREADING) {
  29. dwFlags |= DATE_RTLREADING;
  30. lstrcat(szDateTime, TEXT("\x200F")); // RLM
  31. } else {
  32. dwFlags |= DATE_LTRREADING;
  33. lstrcat(szDateTime, TEXT("\x200E")); // LRM
  34. }
  35. }
  36. // Format date and time
  37. GetDateFormat(locale,dwFlags, &time,NULL,szDate,CharSizeOf(szDate));
  38. GetTimeFormat(locale,TIME_NOSECONDS,&time,NULL,szTime,CharSizeOf(szTime));
  39. if( fCrlf )
  40. lstrcat(szDateTime, TEXT("\r\n"));
  41. lstrcat(szDateTime, szTime);
  42. lstrcat(szDateTime, TEXT(" "));
  43. lstrcat(szDateTime, szDate);
  44. if( fCrlf )
  45. lstrcat(szDateTime, TEXT("\r\n"));
  46. // send it in one shot; this is also useful for undo command
  47. // so that user can undo the date-time.
  48. SendMessage(hwndEdit, EM_REPLACESEL, TRUE, (LPARAM)szDateTime);
  49. }