Changing the program from rochinha ( Posted: Mon Jul 07, 2008 2:26 am Post subject: CODE: Help in controls, now, so easy. ) , tooltips can be managed very easy from the main aplication , by pressing F2 in a control which has focus , or right clicking the mouse (can also be disabled)
Tooltips are visible when the mouse moves over the control , without pressing a key. Of course we can also view the tip by pressing F2
- Code: Select all Expand view RUN
#include "FiveWin.ch"
#include "btnget.ch"
#command OPEN <(db)> ;
[VIA <rdd>] ;
[ALIAS <a>] ;
[<new: NEW>] ;
[<ex: EXCLUSIVE>] ;
[<sh: SHARED>] ;
[<ro: READONLY>] ;
[INDEX <(index1)> [, <(indexn)>]] ;
=> if Select( <(db)> )==0 ;
; dbUseArea( <.new.>, <rdd>, <(db)>, <(a)>, if(<.sh.> .or. <.ex.>, !<.ex.>, NIL), <.ro.> , 0 )[; dbSetIndex( <(db)> )];
; else ;
; dbSelectArea( <(db)> ) ;
; end
GLOBAL rMouseClick := .F. , lCanEdit := .T.
//----------------------------------------------------------------------------//
function Main()
***************
local oDlg , el
local cCtrl9000 := SPACE(45) ,;
nCtrl9001 := 1 ,;
lCtrl9007 := .F. ,;
cCtrl9008 := "CADASTRO" ,;
nCtrl9009 := 3 ,;
nCtrl9012 := 1 ,;
nCtrl9013 := 1 ,;
dCtrl9014 := DATE() ,;
dCtrl9015 := DATE()
aCtrl9008 := { "CADASTRO", "ANIVERSARIO", "ULTIMA COMPRA" }
// ************************************************
Request DBFCDX
RddRegister('DBFCDX',1)
RddSetDefault('DBFCDX')
Request OrdKeyNo
Request OrdKeyCount
// ************************************************
// ************************************************
SetKey( VK_F2, nil )
// ************************************************
SET _3DLOOK ON
DEFINE DIALOG oDlgPainel RESOURCE "dlgPainel"
REDEFINE GET oCtrl9000 VAR cCtrl9000 ID 9000 PICTURE "@!" OF oDlgPainel
REDEFINE RADIO oCtrl9001 VAR nCtrl9001 ID 9001,9002 ON CHANGE oCtrl9101:Enable() OF oDlgPainel
REDEFINE CHECKBOX oCtrl9007 VAR lCtrl9007 ID 9007 ON CHANGE oCtrl9008:Enable() OF oDlgPainel
REDEFINE COMBOBOX oCtrl9008 VAR cCtrl9008 ID 9008 ITEMS aCtrl9008 OF oDlgPainel WHEN lCtrl9007
REDEFINE RADIO oCtrl9009 VAR nCtrl9009 ID 9009,9010,9011 ON CHANGE oCtrl9012:Enable() OF oDlgPainel
REDEFINE GET oCtrl9012 VAR nCtrl9012 ID 9012 PICTURE "999" WHEN lCtrl9007 .AND. nCtrl9009 = 1 OF oDlgPainel ;
VALID nCtrl9012 >= 0 ;
SPINNER ;
ON UP (++nCtrl9012,oCtrl9012:Refresh(),nCtrl9009:=1,oCtrl9009:Refresh(),oCtrl9101:Enable()) ;
ON DOWN (--nCtrl9012,oCtrl9012:Refresh(),nCtrl9009:=1,oCtrl9009:Refresh(),oCtrl9101:Enable()) MIN 1
REDEFINE GET oCtrl9013 VAR nCtrl9013 ID 9013 PICTURE "999" WHEN lCtrl9007 .AND. nCtrl9009 = 2 OF oDlgPainel ;
VALID nCtrl9013 >= 0 ;
SPINNER ;
ON UP (++nCtrl9013,oCtrl9013:Refresh(),nCtrl9009:=2,oCtrl9009:Refresh(),oCtrl9101:Enable()) ;
ON DOWN (--nCtrl9013,oCtrl9013:Refresh(),nCtrl9009:=2,oCtrl9009:Refresh(),oCtrl9101:Enable()) MIN 1
REDEFINE BTNGET oCtrl9014 VAR dCtrl9014 ID 9014 WHEN lCtrl9007 .AND. nCtrl9009 = 3 ;
RESOURCE "calen" OF oDlgPainel SPINNER ;
ON UP (++dCtrl9014,oCtrl9014:Refresh(),nCtrl9009:=3,oCtrl9009:Refresh(),oCtrl9101:Enable()) ;
ON DOWN (--dCtrl9014,oCtrl9014:Refresh(),nCtrl9009:=3,oCtrl9009:Refresh(),oCtrl9101:Enable()) ;
ACTION (aRect := GetCoors(oCtrl9014:hWnd),;
dCtrl9014 := FwCalendar(dCtrl9014,aRect[1],aRect[4],oDlgPainel),;
oCtrl9014:Refresh())
REDEFINE BTNGET oCtrl9015 VAR dCtrl9015 ID 9015 WHEN lCtrl9007 .AND. nCtrl9009 = 3 ;
RESOURCE "calen" OF oDlgPainel SPINNER ;
ON UP (++dCtrl9015,oCtrl9015:Refresh(),nCtrl9009:=3,oCtrl9009:Refresh(),oCtrl9101:Enable()) ;
ON DOWN (--dCtrl9015,oCtrl9015:Refresh(),nCtrl9009:=3,oCtrl9009:Refresh(),oCtrl9101:Enable()) ;
ACTION (aRect := GetCoors(oCtrl9015:hWnd),;
dCtrl9015 := FwCalendar(dCtrl9015,aRect[1],aRect[4],oDlgPainel),;
oCtrl9015:Refresh())
REDEFINE BUTTON oCtrl9101 ID 9101 OF oDlgPainel ACTION .t.
oCtrl9008:Disable()
oCtrl9013:Disable()
oCtrl9014:Disable()
oCtrl9015:Disable()
InitHelp(oDlgPainel:aControls)
ACTIVATE DIALOG oDlgPainel CENTERED //;
// ************************************************
SetKey( VK_F2, fun() )
// ************************************************
return nil
*******************************************************
PROC InitHelp(aControls)
************************
LOCAL el
LOCAL aStru
if ! file( "HELP.DBF" )
aStru := { { "RESNAME" ,"C" , 20, 0 } , ;
{ "NID","C" , 4, 0 } , ;
{ "TEXT" ,"C" ,255, 0 } }
dbCreate( "HELP.DBF", aStru )
endif
if !file( "HELP.CDX" )
use help exclusive
index on RESNAME+NID to help
use
endif
open help shared new
set index to help
FOR EACH el IN aControls
//? el:nId , __ObjHasData(el,"bKeyDown") , __ObjHasData(el,"cToolTip") , el:ClassName , el:oWnd:cResName
IF __ObjHasData(el,"bKeyDown")
el:bKeyDown := {|nKey,bFlags| iif( nKey==VK_F2 , TheHelp( el ) , .t.)}
IF rMouseClick
el:bRClicked := {||TheHelp( el )}
END
END
IF __ObjHasData(el,"cToolTip")
IF HELP->(DBSEEK(PAD(el:oWnd:cResName,20)+StrZero( el:nId , 4 )))
el:cToolTip := HELP->Text
END
END
NEXT
RETURN
*******************************************************
function fun()
return .t.
************************************************************
PROC TheHelp( Ctrl )
**************************************
local IdCtrl := Ctrl:nId
local cResName := Padr(Ctrl:oWnd:cResName,20) // UPPER(...) ?????
local cDlgCtrl := StrZero( idCtrl, 4 )
local cText := Space( 200 )
local oldArea := Select("HELP")
local aStru
local lDelete := .F.
local lOk , lFound
lFound := dbSeek( cResName+cDlgCtrl )
cText := FIELD->TEXT
IF MsgHelpFancy( @cText , lCanEdit .AND. EMPTY(cText) , Ctrl )
lDelete := FOUND() .AND. EMPTY(cText)
lOk := .F.
IF ! lFound
DbAppend()
lOk := ! Neterr()
IF lOk
REPL FIELD->ResNAme WITH cResName , FIELD->nId WITH cDlgCtrl
END
ELSE
lOk := rLock()
ENDIF
IF lOk
IF lDelete
DbDelete()
ELSE
REPL FIELD->Text WITH cText
Ctrl:cToolTip := cText
END
DbUnlock()
END
END
Select( oldArea )
return
**********************************************************************************
STATIC Function HelpIndex()
Keyboard( VK_F1 )
return nil
/*
* SOURCE: NewHelp.prg
*/
function MsgHelpFancy( cMsg , lEdit , oWnd)
************************************
//PUBLIC lNoPaint := .f.
LOCAL oHBrush , oFont
LOCAL lOk := .F.
LOCAL oGet , oBut[2] , oCheck
LOCAL o
LOCAL cMem := cMsg
LOCAL coord := GetWndRect( oWnd:hWnd)
DEFINE BRUSH oHBrush STYLE NULL
DEFINE FONT oFont NAME "Arial" SIZE 0, -9
DEFINE DIALOG oWndHelp TITLE "Ajuda" SIZE 400,150 BRUSH oHBrush STYLE WS_POPUP OF oWnd
@ 5,85 CHECKBOX oCheck VAR lEdit PROMPT "Edit" SIZE 20,8 OF oWndHelp PIXEL FONT oFont WHEN lCanEdit;
ON CHANGE (o := IIF(lEdit , oGet , oBut[2] ) , xSetFocus(o) )
@ 20,50 GET oGet VAR cMsg SIZE 110,20 OF oWndHelp COLOR nRGB(000,000,000),nRGB(255,250,141) PIXEL FONT oFont MEMO WHEN lEdit
@ 43,60 BUTTON oBut[1] PROMPT "OK" SIZE 20,12 OF oWndHelp PIXEL FONT oFont WHEN lEdit ACTION (lOk := .T.,oWndHelp:end() )
@ 43,110 BUTTON oBut[2] PROMPT "CANCEL" SIZE 30,12 OF oWndHelp PIXEL FONT oFont ACTION oWndHelp:end()
ACTIVATE DIALOG oWndHelp ;
ON PAINT ShowHelpBmp( oWndHelp, "genie1", "genie2" );
ON INIT ( o := IIF(lEdit , oGet , oBut[2] ) , xSetFocus(o) , oWndHelp:Move( Coord[3],Coord[2]))
oHBrush:end()
oFont:end()
RETURN (lOk .AND. cMsg<>cMem)
*********************************************************************************************************************************
function ShowHelpBmp( oWndHelp, cBmp1, cBmp2 )
*********************************************
local hDC := oWndHelp:hDC
local oBmp1, oBmp2
DEFINE BITMAP oBmp1 RESOURCE cBmp1
DEFINE BITMAP oBmp2 RESOURCE cBmp2
DrawBitmap( hDC, oBmp2:hBitmap, 0, 0, 0, 0, 15597702 )
DrawBitmap( hDC, oBmp1:hBitmap, 0, 0, 0, 0, 8913094 )
oBmp1:End()
oBmp2:End()
return nil
*****************************************************************************************
function xSetFocus( oObx )
**************************
// function from local.fivewin.english 4/1/2003 Kleyber Derick
local oTempo:=""
local lGet := oObx:ClassName $ "TGET TMULTIGET"
define timer oTempo interval 10 of oObx:oWnd ;
action (oObx:SetFocus(), IIF(lGet , oObx:SetPos(0) , ), oTempo:Deactivate() )
activate timer oTempo
return nil
Building and using TOOLTIPS on dialog's from resources.
Each control from a dialog from resources can have a tooltip. This texts are saved in HELP.DBF :
aStru := { { "RESNAME" ,"C" , 20, 0 } , ;
{ "NID","C" , 4, 0 } , ;
{ "TEXT" ,"C" ,255, 0 } }
With :
Resname : oDlg:cResname , name from the dialog in the rc-file
(used with DEFINE DIALOG .... RESOURCE ...... )
nId : Idnumber from the control in the res-file
(in the source REDEFINE GET .... ID nId ....)
Text : Text from the tooltip
This help.dbf can build without the aplication , at the moment the rc-file is build ,
or it can build with the main aplication
In this case a input routine from the text-files is launched when a control has focus.
This can be done with :
Pressing F2
AND/OR
Right click the mouse , when the GLOBAL variable rMousClick is set
Two GLOBAL variables are used , to allow a global setting :
rMouseclick := .T. , in each control is bRClicked overwritten with the inputroutine
lCanEdit := .T. , Texts from the tooltips can be edited
To use the program , we have only to include one line before activating the dialog :
InitHelp(oDlg:aControls)
and , of course linking in the routines from this file
Frank Demont