*!* 即可完成程序內的轉換及使用,可是個別開發工具轉換起來並不輕易,甚至有些軟件讓用戶手動改控制面板中設置。
*!* 爲了不讓用戶手動更改,所以找了找API函數,寫成在VFP中實現對區域選項的更改。
*----------------------------------------------------------------------------------
*--函 數:MySetLocalInfo(tcOption,tcChangeString)
*--參數 1:不區分大小寫
* tcOption:LongDateFormat ->更改長日期格式
* :ShortDateFormat ->更改短日期格式
* :DateSeparator ->更改日期分隔符
* :TimeFormat ->更改時間格式
* :TimeSeparator ->更改時間分隔符
*--參數 2:區分大小寫
* tcChangeString: ->字符串,如tcOption爲DateSeparator時此處可爲"-"
*--返回值:成功近回.T.,失敗近回.F.
*--作 者:十豆三
*--日 期:2008/04/29
*----------------------------------------------------------------------------------
*--調用示例:
?MySetLocalInfo("LongDateFormat","yyyy'年'MM'月'dd'日'") &&更改長日期格式
?MySetLocalInfo("ShortDateFormat","yyyy-MM-dd") &&更改短日期格式
?MySetLocalInfo("DateSeparator","-") &&更改日期分隔符
?MySetLocalInfo("TimeFormat","HH:mm:ss") &&更改時間格式
?MySetLocalInfo("TimeSeparator",":") &&更改時間分隔符
Function MySetLocalInfo
Parameters tcOption,tcChangeString
If Parameters()<>2 Or Empty(tcOption) Or Empty(tcChangeString)
Return .F.
Endif
Private lnLocal,lpBuffer,lnRetVal
tcOption=Upper(tcOption)
#Define LOCALE_SSHORTDATE 0x1F &&short date format string
#Define LOCALE_SDATE 0x1D &&date separator
#Define LOCALE_SLONGDATE 0x20 &&long date format string
#Define LOCALE_STIMEFORMAT 0x1003 &&time format string
#Define LOCALE_STIME 0x1E &&time separator
#Define HWND_BROADCAST 0xFFFF
#Define WM_WININICHANGE 0x1A
#Define SPI_SETDESKWALLPAPER 20
#Define SPIF_SENDCHANGE 0x2
Declare Integer GetUserDefaultLCID In kernel32
Declare Integer GetLocaleInfo In kernel32 Integer Locale,Integer LCType,String lpLCData,Integer cchData
Declare Integer SetLocaleInfo In kernel32 Integer Locale,Integer LCType,String lpLCData
Declare Integer SendMessage In win32api Integer HWnd,Integer Msg,String wParam,String IParam
Declare Integer SystemParametersInfo In "user32" Integer uiAction,Integer uiParam,Integer pvParam,Integer fWinlni
Do Case
Case tcOption=Upper("LongDateFormat") &&更改長日期格式
lnBufferLen=50
lnType=LOCALE_SLONGDATE
Case tcOption=Upper("ShortDateFormat") &&更改短日期格式,包括日期分隔符
lnBufferLen=20
lnType=LOCALE_SSHORTDATE
Case tcOption=Upper("DateSeparator") &&更改日期分隔符,不改變日期格式
lnBufferLen=2
lnType=LOCALE_SDATE
Case tcOption=Upper("TimeFormat") &&更改時間格式,包括時間分隔符
lnBufferLen=20
lnType=LOCALE_STIMEFORMAT
Case tcOption=Upper("TimeSeparator") &&更改時間分隔符,不改變時間格式
lnBufferLen=2
lnType=LOCALE_STIME
Otherwise
Return .F.
Endcase
lnLocal=GetUserDefaultLCID()
lpBuffer=Replicate(Space(1),lnBufferLen)
lnRetVal=GetLocaleInfo(lnLocal,lnType,@lpBuffer,lnBufferLen)
If Alltrim(lpBuffer)<>tcChangeString
lnRetVal=SetLocaleInfo(lnLocal,lnType,tcChangeString)
Endif
If lnRetVal=0
Return .F.
Endif
*--更新、保存、刷新更改
lnRetVal=SendMessage(HWND_BROADCAST,WM_WININICHANGE,"","") &&該函數將指定的消息發送到一個或多個窗口。此函數爲指定的窗口調用窗口程序,直到窗口程序處理完消息再返回。
lnRetVal=SystemParametersInfo(SPI_SETDESKWALLPAPER,0,0,SPIF_SENDCHANGE) &&該函數查詢或設置系統級參數。該函數也可以在設置參數中更新用戶配置文件。
If lnRetVal=0
Return .F.
Else
Return .T.
Endif
Endfunc