当前位置:  开发笔记 > 编程语言 > 正文

是否存在依赖于.NET Culture的"今日"字符串?

如何解决《是否存在依赖于.NETCulture的"今日"字符串?》经验,为你挑选了1个好方法。

我正在编写一个月历式控件,需要显示一个表示今天日期的字符串.所以在英国文化机器上它会显示出来'Today : 11/02/2009'.

如果恰好使用了不同的文化,比如法语,那么我想用法语单词"今天".

.NET平台是否将此单词作为文化信息的一部分公开,以便我可以自动检索它?我找不到任何暴露但也许我找不到合适的地方.



1> user53794..:

老..但还是有用的(多大了?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

推荐阅读
家具销售_903
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有