PowerBuilder 10 Get and Set System Language

1 minute read

Today I wanted to retrieve the selected system language from PowerBuilder 10. To accomplish that I had to do some search in the web. After a long period I found this post in Google Groups.

It seems that Powerbuilder datawindow fields do have their onwn charset defined in font.charset property. If you change the language in a field, when this field loses focus (for example with a tab press), the selected language is changed back to system default.

This becomes quite annoying, especially when you have to access large datawindow forms via keyboard. To retrieve the current system language and change it, you have to use Win32 GetKeyboardLayout and ActivateKeyboardLayout functions which are defined in user32.dll.

My machine uses two charsets, English (EN) and Greek (EL). So I followed these steps:

1.Define Win32 functions in Global External Functions

   Function long GetKeyboardLayout  (long IdThread) Library "user32.dll"
   Function long ActivateKeyboardLayout (long HKL, long flags) Library "user32.dll"
  1. Define Global Variables

    NOTE: I found the numeric language values by calling GetKeyboardLayout.

    Constant long KLF_REORDER = 8
    Constant long LANG_US_ENGLISH = 67699721
    Constant long LANG_EL_GREEK = 67634184
    long CurrentLanguage
    
  2. Use the functions to retrieve current selected System Language or change it**

    // get and display current System Language
    MessageBox('Keyboard language',GetKeyboardLayout(0))
       
    // set System Language to Greek
    ActivateKeyboardLayout(LANG_EL_GREEK , KLF_REORDER)
    

Comments