Is there a message or notification in Win32 that detects when user changes locale?
Asked Answered
T

1

7

EDIT:

Question is reduced and optimized in response to community's comments. The deleted part of the question will be posted as separate question.

QUESTION:

Is there any WM_SOMETHING or NM_SOMETHING message in Win32 API that can inform me about user changing the locale?

You see, I could use that message/notification to change my program's locale to the current locale.

Something like this pseudo-code:

case WM_SOMETHING: // in my main window procedure
    _wsetlocale( LC_ALL, L"" );

Also, if there is such message, and I process it as in the pseudo-code above, will it adjust only main window's locale or will it also set locale for child dialog boxes and controls?.

MY EFFORTS TO SOLVE THIS:

After browsing through Internet, the only thing I found was WM_INPUTLANGCHANGE, WM_SETTINGCHANGE and WM_INPUTLANGCHANGEREQUEST messages, but I have never used them and do not know if they can solve my problem.

Thank you.

Best regards.

Trichloride answered 1/2, 2014 at 21:47 Comment(0)
T
8

Windows sends a WM_SETTINGCHANGE message, with the wParam set to 0, and the lParam set to a character string containing the value intl. This is described in the documentation for WM_SETTINGCHANGE under the Parameters section:

wParam ...

When the system sends this message as a result of a change in locale settings, this parameter is zero.

lParam ...

When the system sends this message as a result of a change in locale settings, this parameter points to the string "intl".

Your application will need to respond to the message and make any necessary changes yourself in child dialogs and controls.

Tithing answered 1/2, 2014 at 22:44 Comment(12)
I could make a static global variable and update it in response to this message. It could solve the problem with using proper locale in dialog boxes. Still, I have another problem-say my app collects data and forms SQL query in EN-US (INSERT INTO table VALUES(1.2);). Before user clicks on "Save" he changes locale to EN-CA and only then clicks "Save". Now I get the query with 1.2 instead of 1,2 as argument and get error. How could I solve that case? I can not stop user from changing locale until my query executes so I must adapt to this case. Any thoughts? Thank you.Trichloride
I use MS Access 2007 and ADO to insert data into database. Best regards.Trichloride
"How could I solve that case?" I don't know the answer to that, I'm afraid, but it would be a different question. The one you asked here is the one I answered. :-)Tithing
I see, thank you. I will upvote for now, give me some time to implement all this and I will officially accept. As for the other part of my question, well it is a tough one...but then again, what kind of a person would leave a program running just to change the control panel settings? Maybe I am just too paranoid and too careful I guess...Until I implement this I wish you best regards.Trichloride
I had that thought as well. It seems pretty unlikely someone would retrieve some data in your app, edit it, switch to Control Panel, change the locale settings, and then return to your app to save the changes. Thanks for the upvote. :-)Tithing
I'm afraid I don't know the answer to that - I'm not a C++ guy, myself. In Delphi, it would be a straight typecast: if PChar(lParam) = 'intl'.Tithing
Forget it-I have solved it! Thank you for your help! Best regards.Trichloride
How can we listen for this event in c++? when the locale is changed?Stampede
@Trichloride Could you please provide code sample?Stampede
@kittu: It's a Windows message. You listen for it the same as you would any other Windows message - in your message processing code in wndProc.Tithing
For me, its returning lParam as 648600 instead of "intl". See here: #62403875Stampede
@kittu: Yes, I see your question. Remy Lebeau has already written a comment there that explains what you're doing wrong and how to do it properly.Tithing

© 2022 - 2024 — McMap. All rights reserved.