Text changing for dialogbox elements

Share your advanced PureBasic knowledge/code with the community.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Text changing for dialogbox elements

Post by Hroudtwolf »

Hi,

The source shows a way to change texts of dialogbox elements while runtime dynamicly.
It is predestinated for multilanguage support.

Best regards

Wolf

Code: Select all

; PureBasic-Lounge.com
; Hroudtwolf
; Date: 20-02-2009
; Windows



Structure tDLGHook
   hHook.i
   sExpr.s [ $FF ]
EndStructure

Procedure _DLGHook ()
   Static this.tDLGHook
   
   ProcedureReturn this
EndProcedure

Procedure _DlGHookCB ( idMsg.i , wParam.i , lParam.i )
   Protected *this   .tDLGHook = _DLGHook ()
   Protected sBuffer .s        = Space ( $FF )
   
   Select idMsg
      Case #HCBT_ACTIVATE
      For nI = 0 To $FE
         If *this\sExpr [ nI ] And GetDlgItemText_( wParam , nI , @ sBuffer , $FF )
            SetDlgItemText_( wParam , nI , *this\sExpr [ nI ] )
         EndIf
      Next nI
     
   EndSelect
   
   ProcedureReturn #False
EndProcedure

Procedure DLGHook_Start ()
   Protected *this.tDLGHook = _DLGHook ()

   *this\hHook = SetWindowsHookEx_ ( #WH_CBT , @ _DlGHookCB () , GetModuleHandle_ ( #Null ) , GetCurrentThreadId_ () )
   
   ProcedureReturn #Null
EndProcedure

Procedure DLGHook_Stop ()
   Protected *this.tDLGHook = _DLGHook ()
   
   UnhookWindowsHookEx_( *this\hHook )
   
   ProcedureReturn #Null
EndProcedure

Procedure DLGHook_SetExpression ( idDLGItem.i , sText.s )
   Protected *this.tDLGHook = _DLGHook ()
   
   *this\sExpr [ idDLGItem ] = sText
   
   ProcedureReturn #Null
EndProcedure

;---- Test

; Start hooking
DLGHook_Start ()

; Set new texts for miscellaneous dialog items.
DLGHook_SetExpression ( #IDYES    , "Yeah" )
DLGHook_SetExpression ( #IDNO     , "Oh no" )
DLGHook_SetExpression ( #IDCANCEL , "blup" )
DLGHook_SetExpression ( #IDOK     , "Oskar Krause" )

; A few of tests.
MessageRequester  ( "blup"  , "bla"  , #PB_MessageRequester_YesNoCancel )
MessageRequester  ( "blup"  , "bla"  , #PB_MessageRequester_YesNo )
MessageRequester  ( "blup"  , "bla"  , #PB_MessageRequester_Ok )
ColorRequester    ( 0 )
FontRequester     ( "Arial" , 12 , #PB_FontRequester_Effects )
OpenFileRequester ( "test" , "*.*" , "*.*" , 0 )

; Stop hooking.
DLGHook_Stop ()
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Text changing for dialogbox elements

Post by luis »

Interesting! I found it only today ... thank you!
"Have you tried turning it off and on again ?"
+18
Enthusiast
Enthusiast
Posts: 228
Joined: Fri Oct 24, 2008 2:07 pm

Re: Text changing for dialogbox elements

Post by +18 »

thanks, Nice and great
There is a like things for InputRequester and PrintRequester ?
Post Reply