Page 5 of 6

Re: RICHEDITBOX

Posted: Sun Jun 22, 2014 11:29 pm
by srvet_claudio
esgici wrote:
srvet_claudio wrote: ...
is this what you wanted ?
Frankly no :)

I did not think it would be so good :o

Perfect 8-) ( as always )

Thank you very much doc :D

Code: Select all

#include <hmg.ch>

PROCEDURE Main

   aLanguages := { { 'Arabic',     0x0401 },;  
                   { 'English',    0x0409 },;
                   { 'French',     0x040C },;  
                   { 'Polish',     0x0415 },;
                   { 'Portuguese', 0x0416 },;                     
                   { 'Turkish',    0x041F },; 
                   { 'Persian',    0x0429 },;
                   { 'Azeri',      0x042C },;  
                   { 'Spanish',    0x040A } }  

   aLangNames := {}
   aLangCodes := {}

   
   AEVAL( aLanguages, { | a1 | AADD( aLangNames, a1[ 1 ] ), AADD( aLangCodes, a1[ 2 ] ) } )
   
   cCurr_KLName := GetKeyboardLayoutName()
   nCurr_KLNo := CTON( cCurr_KLName, 16 )

   nInsKLNo := ASCAN( aLangCodes, nCurr_KLNo )  // Installed KBL no
   
   DEFINE WINDOW Form_Main ;
      AT 0,0 ;
      WIDTH 600 HEIGHT 480 ;
      MAIN ;
      TITLE "VIVA INTERNATIONAL HMG !" 
      
      ON KEY ESCAPE ACTION ThisWindow.Release
      
      @ 50, 20 EDITBOX editbox_1 WIDTH 550 HEIGHT 350 VALUE ""

      @ 20, 20 COMBOBOX cmbLangs WIDTH 550 HEIGHT 350 ITEMS aLangNames ON CHANGE ChangeUILang( This.Value ) VALUE nInsKLNo
      
   END WINDOW

   CENTER WINDOW Form_Main
   ACTIVATE WINDOW Form_Main

RETURN 

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROCEDURE ChangeUILang(;
                        nSelected )

                        
   nCurr_KLNo := aLangCodes[ nSelected ]
   
   ActivateKeyboardLayout( nCurr_KLNo )
   
RETURN // ChangeUILang()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



#pragma BEGINDUMP
#include "SET_COMPILE_HMG_UNICODE.ch"
#include "HMG_UNICODE.h"
#include <windows.h>
#include <tchar.h>
#include "hbapi.h"


HB_FUNC ( GETKEYBOARDLAYOUTNAME )
{
   TCHAR cKLID [ KL_NAMELENGTH + 1 ];
   GetKeyboardLayoutName (cKLID);
   HMG_retc (cKLID);
}


HB_FUNC ( ACTIVATEKEYBOARDLAYOUT )
{
   HKL hkl     = (HKL)  HMG_parnl (1);
   UINT Flags  = (UINT) hb_parni  (2);
   HKL old_hkl = ActivateKeyboardLayout (hkl, Flags);
   HMG_retnl ((LONG_PTR) old_hkl );
}


HB_FUNC ( GETKEYBOARDLAYOUTLIST )
{
   int nCount = GetKeyboardLayoutList (0, NULL);
   if ( nCount > 0 )
   {  int i;
      hb_reta (nCount);
      HKL List [nCount];
      GetKeyboardLayoutList (nCount, List);
      for (i=0; i < nCount; i++)
           HMG_storvnl ((LONG_PTR) List [i], -1, i+1);
   }
}


HB_FUNC ( LOADKEYBOARDLAYOUT )
{
   // https://msdn.microsoft.com/en-us/library/windows/desktop/dd318693(v=vs.85).aspx
   TCHAR *cKLID = (TCHAR*) HMG_parc (1);
   UINT Flags   = (UINT)   hb_parni (2);
   HKL hkl = LoadKeyboardLayout (cKLID, Flags);
   HMG_retnl ((LONG_PTR) hkl );
}


HB_FUNC ( UNLOADKEYBOARDLAYOUT )
{
   HKL hkl = (HKL)  HMG_parnl (1);
   hb_retl ((BOOL) UnloadKeyboardLayout (hkl));
}


#pragma ENDDUMP
UI_Lang.jpg
I glad you find useful, I will include these functions in the new release of HMG.
How to display the virtual keyboard ?

Re: RICHEDITBOX

Posted: Mon Jun 23, 2014 12:38 am
by esgici
srvet_claudio wrote: ...I will include these functions in the new release of HMG.
It will be very good :)
How to display the virtual keyboard ?
There is a short key In Start Menu\All Programs and .exe is : %windir%\system32\osk.exe

More, if you close Windows without closing Virtual Keyboard, it will open next startup automatically.

I guess it will be possible to activate it ( by run / shell commands ) within our programs :?

Thanks again for this convenience :)

Regards :D

Re: RICHEDITBOX

Posted: Mon Jun 23, 2014 4:11 am
by srvet_claudio
esgici wrote:
srvet_claudio wrote: ...I will include these functions in the new release of HMG.
It will be very good :)
How to display the virtual keyboard ?
There is a short key In Start Menu\All Programs and .exe is : %windir%\system32\osk.exe

More, if you close Windows without closing Virtual Keyboard, it will open next startup automatically.

I guess it will be possible to activate it ( by run / shell commands ) within our programs :?

Thanks again for this convenience :)

Regards :D
That is cool !

Code: Select all

EXECUTE FILE GetSystemDir()+"\osk.exe"

Re: RICHEDITBOX

Posted: Mon Jun 23, 2014 2:02 pm
by esgici
srvet_claudio wrote: That is cool !
Coolest is you !

Code: Select all

EXECUTE FILE GetSystemDir()+"\osk.exe"
Thanks to tip 8-)

Added keyboard activation button !

Added also some languges ( of friends )

and some low-level rutine was simplified ( please confirm )
UI_Lang_02.zip
UI Lang select - II
(1.95 KiB) Downloaded 290 times
UI Lang select II screen shoot
UI Lang select II screen shoot
UI_Lang_02.jpg (82.48 KiB) Viewed 4803 times
A little note for friends :

In order to use this feature, you need install UI languages ( keyboards ) via Control panel. Check installed keyboards in "Language" bar of task-bar.

Regards

Re: RICHEDITBOX

Posted: Mon Jun 23, 2014 4:34 pm
by Rathinagiri
Awesome!

Re: RICHEDITBOX

Posted: Mon Jun 23, 2014 10:10 pm
by srvet_claudio
Enjoy !

Code: Select all

#include "hmg.ch"

#define WM_CLOSE 16

#xtranslate VirtualKeyboard.FILENAME         => "OSK.EXE"
#xtranslate VirtualKeyboard.FULLFILENAME     => GetSystemDir()+"\"+VirtualKeyboard.FILENAME
#xtranslate VirtualKeyboard.HANDLE           => _HMG_VirtualKeyboardGetHandle()
#xtranslate VirtualKeyboard.OPEN [ SHOW ]    => EXECUTE FILE VirtualKeyboard.FULLFILENAME
#xtranslate VirtualKeyboard.OPEN   HIDE      => EXECUTE FILE VirtualKeyboard.FULLFILENAME HIDE
#xtranslate VirtualKeyboard.RELEASE          => SendMessage (VirtualKeyboard.HANDLE, WM_CLOSE, 0, 0)
#xtranslate VirtualKeyboard.TITLE            => GetWindowText (VirtualKeyboard.HANDLE)
#xtranslate VirtualKeyboard.TITLE := <arg>   => SetWindowText (VirtualKeyboard.HANDLE, <arg>)
#xtranslate VirtualKeyboard.SHOW             => ShowWindow (VirtualKeyboard.HANDLE)
#xtranslate VirtualKeyboard.HIDE             => HideWindow (VirtualKeyboard.HANDLE)
#xtranslate VirtualKeyboard.IsVisible        => IsWindowVisible (VirtualKeyboard.HANDLE)
#xtranslate VirtualKeyboard.IsOpen           => IsValidWindowHandle (VirtualKeyboard.HANDLE)
#xtranslate VirtualKeyboard.IsRelease        => .NOT. VirtualKeyboard.IsOpen
#xtranslate VirtualKeyboard.IsMinimize       => IsMinimized (VirtualKeyboard.HANDLE)
#xtranslate VirtualKeyboard.IsMaximize       => IsMaximized (VirtualKeyboard.HANDLE)

#xtranslate VirtualKeyboard.ROW    => GetWindowRow    ( VirtualKeyboard.HANDLE )
#xtranslate VirtualKeyboard.COL    => GetWindowCol    ( VirtualKeyboard.HANDLE )
#xtranslate VirtualKeyboard.WIDTH  => GetWindowWidth  ( VirtualKeyboard.HANDLE )
#xtranslate VirtualKeyboard.HEIGHT => GetWindowHeight ( VirtualKeyboard.HANDLE )

#xtranslate VirtualKeyboard.ROW    := <arg> => _SetWindowSizePos ( VirtualKeyboard.HANDLE, <arg>,      ,      ,       )
#xtranslate VirtualKeyboard.COL    := <arg> => _SetWindowSizePos ( VirtualKeyboard.HANDLE,      , <arg>,      ,       )
#xtranslate VirtualKeyboard.WIDTH  := <arg> => _SetWindowSizePos ( VirtualKeyboard.HANDLE,      ,      , <arg>,       )
#xtranslate VirtualKeyboard.HEIGHT := <arg> => _SetWindowSizePos ( VirtualKeyboard.HANDLE,      ,      ,      , <arg> )


FUNCTION _HMG_VirtualKeyboardGetHandle
STATIC hWnd := 0
LOCAL nProcessID, aWin
   IF IsValidWindowHandle (hWnd) == .F.
      hWnd := 0
      aWin := EnumWindows ()
      FOR i = 1 TO HMG_LEN (aWin)
         GetWindowThreadProcessId (aWin[i], NIL, @nProcessID)
         IF HMG_UPPER (VirtualKeyboard.FILENAME) $ HMG_UPPER (GetProcessImageFileName(nProcessID))
            hWnd := aWin[i]
            EXIT
         ENDIF
      NEXT
   ENDIF
RETURN hWnd



Function Main


   aLanguages := { { 'Arabic',     0x0401 },;  
                   { 'English',    0x0409 },;
                   { 'French',     0x040C },;  
                   { 'Polish',     0x0415 },;
                   { 'Portuguese', 0x0416 },;                     
                   { 'Turkish',    0x041F },; 
                   { 'Persian',    0x0429 },;
                   { 'Azeri',      0x042C },;  
                   { 'Spanish',    0x040A } }  

   aLangNames := {}
   aLangCodes := {}

   
   AEVAL( aLanguages, { | a1 | AADD( aLangNames, a1[ 1 ] ), AADD( aLangCodes, a1[ 2 ] ) } )
   
   cCurr_KLName := GetKeyboardLayoutName()
   nCurr_KLNo := CTON( cCurr_KLName, 16 )

   nInsKLNo := ASCAN( aLangCodes, nCurr_KLNo )  // Installed KBL no
   
   DEFINE WINDOW Form_1;
      AT 0,0 ;
      WIDTH 600 HEIGHT 600 ;
      MAIN ;
      TITLE "System Virtual Keyboard";
      ON RELEASE IF (VirtualKeyboard.IsOpen == .T., VirtualKeyboard.RELEASE, NIL)
      
      ON KEY ESCAPE ACTION ThisWindow.Release
      
      @ 50, 20 EDITBOX editbox_1 WIDTH 550 HEIGHT 350 VALUE ""

      @ 20, 20 COMBOBOX cmbLangs WIDTH 550 HEIGHT 350 ITEMS aLangNames ON CHANGE ChangeUILang( This.Value ) VALUE nInsKLNo
      
      @ 410, 280 BUTTON Button_1 CAPTION "On/Off"  ACTION OnOff_VirtualKeyboard()
      @ 450, 280 BUTTON Button_2 CAPTION "Release" ACTION IF (VirtualKeyboard.IsOpen == .T., VirtualKeyboard.RELEASE, NIL)

   END WINDOW

   CENTER WINDOW Form_1
   ACTIVATE WINDOW Form_1

RETURN 


PROCEDURE OnOff_VirtualKeyboard

   IF VirtualKeyboard.IsOpen == .F.
      IF .NOT. FILE (VirtualKeyboard.FULLFILENAME)
         RETURN
      ENDIF
      VirtualKeyboard.OPEN   HIDE
      Inkey (1)   // Wait until the application is loaded
      VirtualKeyboard.TITLE := "HMG Virtual Keyboard"
      VirtualKeyboard.ROW := Form_1.ROW + Form_1.editbox_1.ROW + 50
      VirtualKeyboard.COL := Form_1.COL + Form_1.editbox_1.COL + 20
      VirtualKeyboard.SHOW
      RETURN
   ENDIF

   IF VirtualKeyboard.IsVisible == .F.
      VirtualKeyboard.SHOW
   ELSE
      VirtualKeyboard.HIDE
   ENDIF
RETURN




*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROCEDURE ChangeUILang( nSelected )
                    
   nCurr_KLNo := aLangCodes[ nSelected ]
   
   ActivateKeyboardLayout( nCurr_KLNo )
   
RETURN // ChangeUILang()


*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.



#pragma BEGINDUMP
#include "SET_COMPILE_HMG_UNICODE.ch"
#include "HMG_UNICODE.h"
#include <windows.h>
#include <tchar.h>
#include "hbapi.h"
#include "hbapiitm.h"


HB_FUNC ( GETKEYBOARDLAYOUTNAME )
{
   TCHAR cKLID [ KL_NAMELENGTH + 1 ];
   GetKeyboardLayoutName (cKLID);
   HMG_retc (cKLID);
}


HB_FUNC ( ACTIVATEKEYBOARDLAYOUT )
{
   HKL hkl     = (HKL)  HMG_parnl (1);
   UINT Flags  = (UINT) hb_parni  (2);
   HKL old_hkl = ActivateKeyboardLayout (hkl, Flags);
   HMG_retnl ((LONG_PTR) old_hkl );
}


//        GetProcessImageFileName ( [ nProcessID ] ) --> return cProcessImageFileName
HB_FUNC ( GETPROCESSIMAGEFILENAME )
{
   typedef DWORD (WINAPI *Func_GetProcessImageFileName) (HANDLE,LPTSTR,DWORD);
   static Func_GetProcessImageFileName pGetProcessImageFileName = NULL;
   if (pGetProcessImageFileName == NULL) 
   {   HMODULE hLib = LoadLibrary (_TEXT("Psapi.dll"));
       #ifdef UNICODE
          pGetProcessImageFileName = (Func_GetProcessImageFileName) GetProcAddress(hLib, "GetProcessImageFileNameW");
       #else
          pGetProcessImageFileName = (Func_GetProcessImageFileName) GetProcAddress(hLib, "GetProcessImageFileNameA");
       #endif
   }
   if (pGetProcessImageFileName == NULL)
       return;   // return NIL

   DWORD ProcessID = HB_ISNUM (1) ? (DWORD) hb_parnl(1) : GetCurrentProcessId();
   TCHAR cProcessFullName [ MAX_PATH ] = _TEXT ("");

   HANDLE hProcess = OpenProcess ( PROCESS_QUERY_INFORMATION, FALSE, ProcessID );
   if ( hProcess != NULL )
   {   pGetProcessImageFileName (hProcess, cProcessFullName, sizeof(cProcessFullName)/sizeof(TCHAR));
       CloseHandle (hProcess);
       HMG_retc (cProcessFullName);
   }
   return;   // return NIL
}


extern PHB_ITEM pArray;

BOOL CALLBACK EnumWindowsProc (HWND hWnd, LPARAM lParam)
{
   UNREFERENCED_PARAMETER (lParam);
   hb_arrayAddForward (pArray, hb_itemPutNLL (NULL, (LONG_PTR) hWnd));
   return TRUE;
}


HB_FUNC ( ENUMWINDOWS )
{
   pArray = hb_itemArrayNew ( 0 );
   EnumWindows ((WNDENUMPROC) EnumWindowsProc, (LPARAM) 0);
   hb_itemReturnRelease ( pArray );
   pArray = NULL;
}


//        GetWindowThreadProcessId (hWnd, @nThread, @nProcessID)
HB_FUNC ( GETWINDOWTHREADPROCESSID )
{
   HWND hWnd = (HWND) HMG_parnl (1);
   DWORD nThread, nProcessID;

   nThread = GetWindowThreadProcessId (hWnd, &nProcessID);

   if ( HB_ISBYREF(2) )
        hb_storni (nThread, 2); 
   if ( HB_ISBYREF(3) )
        hb_storni (nProcessID, 3); 
}


#pragma ENDDUMP

Re: RICHEDITBOX

Posted: Mon Jun 23, 2014 10:43 pm
by esgici
srvet_claudio wrote:Enjoy !
...
Wonderful :!:

Now, the Virtual Keyboard is completly under control :arrow:

Thank a lot doc :)

RICHEDITBOX

Posted: Mon Jun 23, 2014 11:02 pm
by Pablo César
Very nice Claudio. Thanks for your sharing.

Re: RICHEDITBOX

Posted: Tue Jun 24, 2014 12:31 am
by danielmaximiliano
Buenisimo Claudio.

Esgici , thanks for sharing.....

Re: RICHEDITBOX

Posted: Tue Jun 24, 2014 4:28 am
by bpd2000
Is there any other software require / any changes require in system, because even after I change language selection but OSK shows only English language
My OS is Windows XP Sp3