Function to get the regional format settings

HMG Unicode versions 3.1.x related

Moderator: Rathinagiri

Post Reply
User avatar
hmgchang
Posts: 239
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia
Has thanked: 1 time
Been thanked: 4 times

Function to get the regional format settings

Post by hmgchang » Sat Mar 31, 2018 11:48 pm

Dear All,

Is there any functions to get the regional format settings of the OS ?
regional format setting.JPG
Win10 regional format setting
regional format setting.JPG (52.61 KiB) Viewed 863 times
TIA

best rgds
Chang
Just Hmg It !

User avatar
dragancesu
Posts: 543
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia
Has thanked: 12 times
Been thanked: 97 times

Post by dragancesu » Sun Apr 01, 2018 9:39 am

Windows Registry contain data what you need, just read
settings.jpg
settings.jpg (239.07 KiB) Viewed 821 times

KDJ
Posts: 206
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 243 times

Post by KDJ » Sun Apr 01, 2018 10:33 am

hmgchang wrote:
Sat Mar 31, 2018 11:48 pm
Is there any functions to get the regional format settings of the OS ?
Yes, Win API function - GetLocaleInfo (or GetLocaleInfoEx): https://msdn.microsoft.com/en-us/librar ... s.85).aspx

User avatar
hmgchang
Posts: 239
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia
Has thanked: 1 time
Been thanked: 4 times

Post by hmgchang » Mon Apr 02, 2018 6:48 am

Thanks for the replies,
but how to do it with Hmg ?
an samples ?

TIA
Just Hmg It !

User avatar
bpd2000
Posts: 1017
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 164 times
Been thanked: 72 times

Post by bpd2000 » Mon Apr 02, 2018 8:14 am

hmgchang wrote:
Mon Apr 02, 2018 6:48 am
Thanks for the replies,
but how to do it with Hmg ?
an samples ?

TIA
Suppose you want to know Country value from Registry, try working example

Code: Select all

/*
 * HMG - Harbour Win32 GUI library Demo
 *
 * Copyright 2002-2008 Roberto Lopez <mail.box.hmg@gmail.com>
 * http://www.hmgforum.com//
 * bpd2000
*/
#include "hmg.ch"

PROCEDURE Main()
 ReadRegistryTest()
Return nil

Procedure ReadRegistryTest()

    private reg_key := 'HKEY_CURRENT_USER\Control Panel\International\sCountry'
  	reg_key_value := win_regRead ( reg_key) 

    MsgInfo ( reg_key_value, 'Reg_key_value' )

Return
BPD
Convert Dream into Reality through HMG

edk
Posts: 307
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 85 times
Been thanked: 234 times

Post by edk » Mon Apr 02, 2018 9:34 am

KDJ wrote:
Sun Apr 01, 2018 10:33 am
hmgchang wrote:
Sat Mar 31, 2018 11:48 pm
Is there any functions to get the regional format settings of the OS ?
Yes, Win API function - GetLocaleInfo (or GetLocaleInfoEx): https://msdn.microsoft.com/en-us/librar ... s.85).aspx
Thanks Krzysztof.
I did something like this:

Code: Select all

#include "hmg.ch"
#include "hmgwinnls.ch"			//Constants for HMG_GetLocaleInfo

Function Main

cDec := HMG_GetLocaleInfo( LOCALE_SDECIMAL )
cNeg := HMG_GetLocaleInfo( LOCALE_SNEGATIVESIGN )
cTho := HMG_GetLocaleInfo( LOCALE_STHOUSAND )
cGro := HMG_GetLocaleInfo( LOCALE_SGROUPING )

DEFINE WINDOW frm1 AT 159 , 333 WIDTH 397 HEIGHT 416 MAIN

   	@ 30, 30 LABEL Label_1 VALUE "Decimal symbol:" AUTOSIZE
	@ 30,190 LABEL Label_1a VALUE cDec BACKCOLOR WHITE
	
	@ 60, 30 LABEL Label_2 VALUE "No. of digits after decimal:" AUTOSIZE
	@ 60,190 LABEL Label_2a VALUE HMG_GetLocaleInfo( LOCALE_IDIGITS ) BACKCOLOR WHITE
	
	@ 90, 30 LABEL Label_3 VALUE "Digit grouping symbol:" AUTOSIZE
	@ 90,190 LABEL Label_3a VALUE cTho BACKCOLOR WHITE
	
	@120, 30 LABEL Label_4 VALUE "Digit grouping:" AUTOSIZE
	@120,190 LABEL Label_4a VALUE IF(cGro = '0', '123456789', ;
				  IF(cGro == '3;0', '123'+cTho+'456'+cTho+'789', ;
				  IF(cGro == '3;0;0', '123456'+cTho+'789', ;
				  IF(cGro == '3;2;0', '12'+cTho+'34'+cTho+'56'+cTho+'789', 'Invalid' )))) BACKCOLOR WHITE
		
	@150, 30 LABEL Label_5 VALUE "Negative sign symbol:" AUTOSIZE
	@150,190 LABEL Label_5a VALUE cNeg BACKCOLOR WHITE
	
	@180, 30 LABEL Label_6 VALUE "Negative number format:" AUTOSIZE
	@180,190 LABEL Label_6a VALUE IF(HMG_GetLocaleInfo( LOCALE_INEGNUMBER ) ='0', '(1'+cDec+'1)' , ;
				  IF(HMG_GetLocaleInfo( LOCALE_INEGNUMBER ) ='1', cNeg+'1'+cDec+'1', ;
				  IF(HMG_GetLocaleInfo( LOCALE_INEGNUMBER ) ='2', cNeg+' 1'+cDec+'1', ;
				  IF(HMG_GetLocaleInfo( LOCALE_INEGNUMBER ) ='3', '1'+cDec+'1'+cNeg, ;
				  IF(HMG_GetLocaleInfo( LOCALE_INEGNUMBER ) ='4', '1'+cDec+'1 '+cNeg, 'Invalid' ))))) BACKCOLOR WHITE
	
	@210, 30 LABEL Label_7 VALUE "Display leading zeros:" AUTOSIZE
	@210,190 LABEL Label_7a VALUE IF( HMG_GetLocaleInfo( LOCALE_ILZERO ) = '0', '' , '0') + cDec + '7' BACKCOLOR WHITE
	
	@240, 30 LABEL Label_8 VALUE "List separator:" AUTOSIZE
	@240,190 LABEL Label_8a VALUE HMG_GetLocaleInfo( LOCALE_SLIST ) BACKCOLOR WHITE
	
	@270, 30 LABEL Label_9 VALUE "Measurement system:" AUTOSIZE
	@270,190 LABEL Label_9a VALUE IF(HMG_GetLocaleInfo( LOCALE_IMEASURE ) = '0', 'Metric', 'U.S.') BACKCOLOR WHITE
	
	@300, 30 LABEL Label_10 VALUE "Standard digits:" AUTOSIZE
	@300,190 LABEL Label_10a VALUE HMG_GetLocaleInfo( LOCALE_SNATIVEDIGITS ) BACKCOLOR WHITE
	
	@330, 30 LABEL Label_11 VALUE "Use native digits:" AUTOSIZE
	@330,190 LABEL Label_11a VALUE IF(HMG_GetLocaleInfo( LOCALE_IDIGITSUBSTITUTION ) = '0', 'Context-based', ;
				   IF(HMG_GetLocaleInfo( LOCALE_IDIGITSUBSTITUTION ) = '1', 'Never', ;
				   IF(HMG_GetLocaleInfo( LOCALE_IDIGITSUBSTITUTION ) = '2', 'Native', 'Invalid'))) BACKCOLOR WHITE
	
END WINDOW

CENTER WINDOW frm1
ACTIVATE WINDOW frm1


Return Nil


#pragma BEGINDUMP

#define COMPILE_HMG_UNICODE
#include "SET_COMPILE_HMG_UNICODE.ch"
#include "HMG_UNICODE.h"

#include <windows.h>
#include "hbapi.h"
#include "hbvm.h"
#include "hbstack.h"

HB_FUNC ( HMG_GETLOCALEINFO )
{
   INT LCType = hb_parni (1);
   LPTSTR cText;

   cText = ( LPTSTR ) hb_xgrab( 128 );

   GetLocaleInfo( LOCALE_USER_DEFAULT, LCType, cText, 128 );

   HMG_retc( cText );
   hb_xfree( cText );
}

#pragma ENDDUMP

hmgwinnls.ch.7z
(1.88 KiB) Downloaded 45 times
I do not know why I get invalid characters for LOCALE_SNATIVEDIGITS other than Arabic numbers?

KDJ
Posts: 206
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 243 times

Post by KDJ » Mon Apr 02, 2018 1:52 pm

Edward

This is great!

edk wrote:
Mon Apr 02, 2018 9:34 am
I do not know why I get invalid characters for LOCALE_SNATIVEDIGITS other than Arabic numbers?
If you change LOCALE_SNATIVEDIGITS, try to change LOCALE_IDIGITSUBSTITUTION too.

edk
Posts: 307
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 85 times
Been thanked: 234 times

Post by edk » Mon Apr 02, 2018 3:03 pm

KDJ wrote:
Mon Apr 02, 2018 1:52 pm
If you change LOCALE_SNATIVEDIGITS, try to change LOCALE_IDIGITSUBSTITUTION too.
So I did, but instead of these characters:
1.png
1.png (17.32 KiB) Viewed 657 times
I get this in response:
2.png
2.png (11.04 KiB) Viewed 657 times
I do not know if I compile correctly in UNICODE mode.

KDJ
Posts: 206
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 243 times

Post by KDJ » Mon Apr 02, 2018 4:02 pm

I have compiled it with HMG 3.4.4 32-bit, Win-7 64-bit, and all works properly:

Screen_Window.jpg
Screen_Window.jpg (29.19 KiB) Viewed 646 times

edk
Posts: 307
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 85 times
Been thanked: 234 times

Post by edk » Tue Apr 03, 2018 7:53 am

Well now I have a riddle :? .
I recompiled on a different machine (Win10-32bit) and the characters are displayed correctly :shock: .
On this computer, where characters are incorrectly displayed, the system Win10-64bit is brand new and the original unmodified hmg3.4.4 installed.

Post Reply