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 ()