WinAPI - GetXxxFormat Functions

Post your working scripts, libraries and tools
User avatar
jNizM
Posts: 2243
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

WinAPI - GetXxxFormat Functions

02 Nov 2015, 09:14

GetXxxFormat Functions (National Language Support Functions) (MSDN-Link)


- GetCurrencyFormat & GetCurrencyFormatEx (Formats a number string as a currency string)
- GetNumberFormat & GetNumberFormatEx (Formats a number string as a number string)
- GetDateFormat & GetDateFormatEx
- GetDurationFormat & GetDurationFormatEx
- GetTimeFormat & GetTimeFormatEx
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2243
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: WinAPI GetXxxFormat Functions

03 Nov 2015, 02:05

GetCurrencyFormat
Formats a number string as a currency string for a locale specified by identifier.

Code: [Select all] [Download] GeSHi © Codebox Plus

GetCurrencyFormat(VarIn, locale := 0x0400)
{
if (size := DllCall("GetCurrencyFormat", "uint", locale, "uint", 0, "ptr", &VarIn, "ptr", 0, "ptr", 0, "int", 0)) {
VarSetCapacity(buf, size << 1, 0)
if (DllCall("GetCurrencyFormat", "uint", locale, "uint", 0, "ptr", &VarIn, "ptr", 0, "str", buf, "int", size))
return buf
}
return false
}

example & output

Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox % GetCurrencyFormat(1149.99)                ; ==> 1.149,99 €        ( LANG_USER_DEFAULT | SUBLANG_DEFAULT    )
MsgBox % GetCurrencyFormat(1149.99, 0x0409) ; ==> $1,149.99 ( LANG_ENGLISH | SUBLANG_ENGLISH_US )
MsgBox % GetCurrencyFormat(1149.99, 0x0809) ; ==> £1,149.99 ( LANG_ENGLISH | SUBLANG_ENGLISH_UK )
MsgBox % GetCurrencyFormat(1149.99, 0x0407) ; ==> 1.149,99 € ( LANG_GERMAN | SUBLANG_GERMAN )

ref:
- GetCurrencyFormat function
- Language Identifier Constants and Strings



GetCurrencyFormatEx (Vista or later)
Formats a number string as a currency string for a locale specified by name.

Code: [Select all] [Download] GeSHi © Codebox Plus

GetCurrencyFormatEx(VarIn, locale := "!x-sys-default-locale")
{
if (size := DllCall("GetCurrencyFormatEx", "ptr", &locale, "uint", 0, "ptr", &VarIn, "ptr", 0, "ptr", 0, "int", 0)) {
VarSetCapacity(buf, size << 1, 0)
if (DllCall("GetCurrencyFormatEx", "ptr", &locale, "uint", 0, "ptr", &VarIn, "ptr", 0, "str", buf, "int", size))
return buf
}
return false
}

example & output

Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox % GetCurrencyFormatEx(1149.99)                 ; ==> 1.149,99 €        ( LANG_USER_DEFAULT | SUBLANG_DEFAULT    )
MsgBox % GetCurrencyFormatEx(1149.99, "en-US") ; ==> $1,149.99 ( LANG_ENGLISH | SUBLANG_ENGLISH_US )
MsgBox % GetCurrencyFormatEx(1149.99, "en-GB") ; ==> £1,149.99 ( LANG_ENGLISH | SUBLANG_ENGLISH_US )
MsgBox % GetCurrencyFormatEx(1149.99, "de-DE") ; ==> 1.149,99 € ( LANG_GERMAN | SUBLANG_GERMAN )

ref:
- GetCurrencyFormatEx function
- Locale Names
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2243
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: WinAPI GetXxxFormat Functions

03 Nov 2015, 02:05

GetNumberFormat
Formats a number string as a number string customized for a locale specified by identifier.

Code: [Select all] [Download] GeSHi © Codebox Plus

GetNumberFormat(VarIn, locale := 0x0400)
{
if (size := DllCall("GetNumberFormat", "uint", locale, "uint", 0, "ptr", &VarIn, "ptr", 0, "ptr", 0, "int", 0)) {
VarSetCapacity(buf, size << 1, 0)
if (DllCall("GetNumberFormat", "uint", locale, "uint", 0, "ptr", &VarIn, "ptr", 0, "str", buf, "int", size))
return buf
}
return false
}

example & output

Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox % GetNumberFormat(1149.99)                  ; ==> 1.149,99         ( LANG_USER_DEFAULT | SUBLANG_DEFAULT    )
MsgBox % GetNumberFormat(1149.99, 0x0409) ; ==> 1,149.99 ( LANG_ENGLISH | SUBLANG_ENGLISH_US )
MsgBox % GetNumberFormat(1149.99, 0x0809) ; ==> 1,149.99 ( LANG_ENGLISH | SUBLANG_ENGLISH_UK )
MsgBox % GetNumberFormat(1149.99, 0x0407) ; ==> 1.149,99 ( LANG_GERMAN | SUBLANG_GERMAN )

ref:
- GetNumberFormat function
- Language Identifier Constants and Strings



GetNumberFormatEx (Vista or later)
Formats a number string as a number string customized for a locale specified by name.

Code: [Select all] [Download] GeSHi © Codebox Plus

GetNumberFormatEx(VarIn, locale := "!x-sys-default-locale")
{
if (size := DllCall("GetNumberFormatEx", "ptr", &locale, "uint", 0, "ptr", &VarIn, "ptr", 0, "ptr", 0, "int", 0)) {
VarSetCapacity(buf, size << 1, 0)
if (DllCall("GetNumberFormatEx", "ptr", &locale, "uint", 0, "ptr", &VarIn, "ptr", 0, "str", buf, "int", size))
return buf
}
return false
}

example & output

Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox % GetNumberFormatEx(1149.99)                   ; ==> 1.149,99         ( LANG_USER_DEFAULT | SUBLANG_DEFAULT    )
MsgBox % GetNumberFormatEx(1149.99, "en-US") ; ==> 1,149.99 ( LANG_ENGLISH | SUBLANG_ENGLISH_US )
MsgBox % GetNumberFormatEx(1149.99, "en-GB") ; ==> 1,149.99 ( LANG_ENGLISH | SUBLANG_ENGLISH_US )
MsgBox % GetNumberFormatEx(1149.99, "de-DE") ; ==> 1.149,99 ( LANG_GERMAN | SUBLANG_GERMAN )

ref:
- GetNumberFormatEx function
- Locale Names
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2243
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: WinAPI GetXxxFormat Functions

03 Nov 2015, 02:05

*reserved for GetDateFormat & GetDateFormatEx
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2243
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: WinAPI GetXxxFormat Functions

03 Nov 2015, 02:16

*reserved for GetDurationFormat & GetDurationFormatEx
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2243
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: WinAPI GetXxxFormat Functions

03 Nov 2015, 03:10

*reserved for GetTimeFormat & GetTimeFormatEx
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
Albireo
Posts: 309
Joined: 16 Oct 2013, 13:53

Re: WinAPI - GetXxxFormat Functions

18 May 2016, 17:10

Thank You!
It works fine.

Do you still intend to supplement with "GetDateFormatEx" and "GetTimeFormatEx"?

//Jan
User avatar
jeeswg
Posts: 2044
Joined: 19 Dec 2016, 01:58
Location: UK

Re: WinAPI - GetXxxFormat Functions

12 Sep 2017, 02:50

@Albireo: jNizM did do a GetDateFormat example here:
Convert .NET DateTime ticks to AHK YYYYMMDDHH24MISS timestamp - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=8992&p=49935#p49935
I was looking forward to some date/time format examples! But when I got there, the cupboard was bare.

I was trying to find out if GetTimeFormat can handle milliseconds, the answer appears to be no. Although I have some date/time and milliseconds examples here:
jeeswg's documentation extension tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=33596

@jNizM: You're welcome to adapt any of these examples.

Another useful link:
Language Identifier Constants and Strings (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/dd318693(v=vs.85).aspx

Here are some examples with GetDateFormat and GetTimeFormat:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 23 guests