Phi*_*ght 0 .net c# datetime monthcalendar
我正在编写一个月历式控件,需要显示一个表示今天日期的字符串.所以在英国文化机器上它会显示出来'Today : 11/02/2009'.
如果恰好使用了不同的文化,比如法语,那么我想用法语单词"今天".
.NET平台是否将此单词作为文化信息的一部分公开,以便我可以自动检索它?我找不到任何暴露但也许我找不到合适的地方.
老..但还是有用的(多大了?VB6老).
基本上,Windows在Comctl32.dll中保留了"今天"的本地化版本.您可以通过loadtringex调用将其捕获:
Private Const IDM_TODAY As Long = 4163
Private Const IDM_GOTODAY As Long = 4164
Public Function GetTodayLocalized(ByVal LocaleId As Long) As String
Static hComCtl32 As Long
Static hComCtl32Initialized As Boolean
Static hComCtl32MustBeFreed As Boolean
Dim s As String
If Not hComCtl32Initialized Then
hComCtl32 = GetModuleHandle("Comctl32.dll")
If hComCtl32 <> 0 Then
hComCtl32MustBeFreed = False
hComCtl32Initialized = True
Else
hComCtl32 = LoadLibrary("Comctl32.Dll")
If Not hComCtl32 = 0 Then
hComCtl32MustBeFreed = True
hComCtl32Initialized = True
End If
End If
End If
If hComCtl32Initialized = False Then
s = "Today"
Else
s = LoadStringEx(hComCtl32, IDM_TODAY, LocaleId)
If s = "" Then
s = "Today"
End If
End If
If hComCtl32MustBeFreed Then
FreeLibrary hComCtl32
hComCtl32MustBeFreed = False
hComCtl32Initialized = False
hComCtl32 = 0
End If
s = Replace(s, "&", "")
If Right(s, 1) = ":" Then
s = Left(s, Len(s) - 1)
End If
GetTodayLocalized = s
End Function
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
485 次 |
| 最近记录: |