CAFE

vb6 api

제어판의 국가별 날짜형식 바꾸기CopyMemory,PostMessage,EnumDateFormats,GetSystemDefaultLCID ,GetLocaleInfo,SetLocaleInfo

작성자올란도|작성시간09.01.29|조회수319 목록 댓글 0

Public thisCombo As ComboBox

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
              (Destination As Any, _
               Source As Any, _
               ByVal Length As Long)

Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
              (ByVal hwnd As Long, _
               ByVal wMsg As Long, _
               ByVal wParam As Long, _
               lParam As Any) As Long

Public Declare Function EnumDateFormats Lib "kernel32" Alias "EnumDateFormatsA" _
              (ByVal lpDateFmtEnumProc As Long, _
               ByVal Locale As Long, _
               ByVal dwFlags As Long) As Long
  
Public Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long

Public Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" _
              (ByVal Locale As Long, _
               ByVal LCType As Long, _
               ByVal lpLCData As String, _
               ByVal cchData As Long) As Long

Public Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" _
              (ByVal Locale As Long, _
               ByVal LCType As Long, _
               ByVal lpLCData As String) As Long

Public Const LOCALE_SLANGUAGE As Long = &H2     'localized name of language
Public Const LOCALE_SSHORTDATE As Long = &H1F   'short date format string
Public Const LOCALE_SLONGDATE As Long = &H20    'long date format string
Public Const DATE_LONGDATE As Long = &H2
Public Const DATE_SHORTDATE As Long = &H1

Public Const HWND_BROADCAST As Long = &HFFFF&
Public Const WM_SETTINGCHANGE As Long = &H1A

Public Function GetUserLocaleInfo(ByVal dwLocaleID As Long, _
                                  ByVal dwLCType As Long) As String
    Dim sReturn As String
    Dim r As Long
 
    'call the function passing the Locale type
    'variable to retrieve the required size of  'the string buffer needed
    r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))
    If r Then                          'pad the buffer with spaces
        sReturn = Space$(r)            'and call again passing the buffer
        r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))
        If r Then
            'r holds the size of the string
            'including the terminating null
            GetUserLocaleInfo = Left$(sReturn, r - 1)
        End If
    End If
End Function
   
Public Function EnumCalendarDateProc(lpDateFormatString As Long) As Long
    'application-defined callback function for EnumDateFormats
    'populates combo assigned to global var thisCombo
     thisCombo.AddItem StringFromPointer(lpDateFormatString)
    'return 1 to continue enumeration
    EnumCalendarDateProc = 1
End Function

Private Function StringFromPointer(lpString As Long) As String
    Dim pos As Long
    Dim buffer As String     'pad a string to hold the data
   
    buffer = Space$(128)     'copy the string pointed to by the return value
    CopyMemory ByVal buffer, lpString, ByVal Len(buffer)
    'remove the trailing null and trim
    pos = InStr(buffer, Chr$(0))
    If pos Then
        StringFromPointer = Left$(buffer, pos - 1)
    End If
End Function

2. 폼에 TextBox 하나, ComboBox 하나, Command Button 을 하나 만들고 버튼과
   폼로드 이벤트에 다음과 같이 코딩하시기 바랍니다.

Private Sub Command1_Click()
    Dim LCID As Long
    Dim newFormat As String
   
    LCID = GetSystemDefaultLCID()
    newFormat = Combo1.Text
    If newFormat <> "" Then        'set the new long date format
        Call SetLocaleInfo(LCID, LOCALE_SSHORTDATE, newFormat)
        'send a system notification message that a change was made
        Call PostMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0&, ByVal 0&)
        'update the textbox and label
        Text1 = GetUserLocaleInfo(LCID, LOCALE_SSHORTDATE)
        'assign the target combo box control
        Set thisCombo = Form1.Combo1
        thisCombo.Clear            'enumerate new long date formats
        Call EnumDateFormats(AddressOf EnumCalendarDateProc, LCID, DATE_SHORTDATE)
    End If
End Sub

Private Sub Form_Load()
    Dim LCID As Long
   
    LCID = GetSystemDefaultLCID()
    ' show localized name of language
    ' Text1 = GetUserLocaleInfo(LCID, LOCALE_SLANGUAGE)
    '-------------------------  'assign the target combo box control
    ' Set thisCombo = Form1.Combo1    'enumerate available long date formats
    ' Call EnumDateFormats(AddressOf EnumCalendarDateProc, LCID, DATE_LONGDATE)
    ' Show the user's Long date format string
    ' Text1 = GetUserLocaleInfo(LCID, LOCALE_SLONGDATE)
    '-------------------------  'assign the target combo box control
    Set thisCombo = Form1.Combo1     'enumerate available short date formats
    Call EnumDateFormats(AddressOf EnumCalendarDateProc, LCID, DATE_SHORTDATE)
    'Show the user's Short date format string
    Text1 = GetUserLocaleInfo(LCID, LOCALE_SSHORTDATE)
End Sub

다음검색
현재 게시글 추가 기능 열기

댓글

댓글 리스트
맨위로

카페 검색

카페 검색어 입력폼