Adding buttons to a Title Bar
Posted: Thu Jul 23, 2015 6:21 pm
The next release of eXpress++ (build 262) will support a new feature that allows DC* objects to be added to a title bar.
In the below sample, a HELP push button is added to the titlebar of all windows by setting DC_GetOptDefault().
Xbase++ does not support writing to the title bar area of an XbpDialog(), therefore another XbpDialog() must be created which is a sibling yet the main dialog is the OWNER. By setting the :moveWithOwner iVar, the pushbutton appears to be a child of the titlebar. Resizing the windows also keeps the button position due to new methods of the DC_XbpDialog1() class.
Three (3) new files are needed to make this work:
Copy DCDIALOG.CH to \exp20\include
Copy _DCGETBX.PRG to \exp20\source\dclipx
Copy _DCCLASS.PRG to \exp20\source\dclipx
Rebuild DCLIPX.DLL by running BUILD19_SL1.BAT or BUILD20.BAT.
In the below sample, a HELP push button is added to the titlebar of all windows by setting DC_GetOptDefault().
Xbase++ does not support writing to the title bar area of an XbpDialog(), therefore another XbpDialog() must be created which is a sibling yet the main dialog is the OWNER. By setting the :moveWithOwner iVar, the pushbutton appears to be a child of the titlebar. Resizing the windows also keeps the button position due to new methods of the DC_XbpDialog1() class.
Three (3) new files are needed to make this work:
Copy DCDIALOG.CH to \exp20\include
Copy _DCGETBX.PRG to \exp20\source\dclipx
Copy _DCCLASS.PRG to \exp20\source\dclipx
Rebuild DCLIPX.DLL by running BUILD19_SL1.BAT or BUILD20.BAT.
Code: Select all
#INCLUDE "dcdialog.ch"
#INCLUDE "appevent.CH"
FUNCTION Main()
LOCAL GetList[0], GetOptions, oMenuBar, oSubMenu, oDlg
DCGETOPTIONS ;
EVAL {|o|CreateTitleBar(o)}
DC_GetOptDefault(GetOptions)
DCMENUBAR oMenuBar
DCSUBMENU oSubMenu PROMPT 'Window' PARENT oMenuBar
DCMENUITEM 'Open a Window' PARENT oSubMenu ;
ACTION {|o|o := Thread():new(), o:start({||OpenWindow(oDlg)})}
DCGETOPTIONS ;
WINDOWWIDTH 800 ;
WINDOWHEIGHT 600
DCREAD GUI TITLE 'Buttons on Title Bar' OPTIONS GetOptions ;
PARENT @oDlg SETAPPWINDOW
RETURN nil
* ----------
STATIC FUNCTION OpenWindow( oDlg )
LOCAL GetList[0], GetOptions, i
FOR i := 1 TO 10
@ i,0 DCSAY 'This is line ' + Alltrim(Str(i)) FONT '10.Lucida Console' SAYSIZE 50
NEXT
DCREAD GUI TITLE 'Test Window' OPTIONS GetOptions APPWINDOW oDlg:drawingArea
RETURN nil
* ----------
PROC appsys ; RETURN
* ----------
STATIC FUNCTION CreateTitleBar( oDlg )
LOCAL GetList[0], oButtonDlg, oDrawingArea, oAppDeskTop := AppDeskTop(), ;
oConfig, oButton, oParent
IF oDlg:parent == AppDeskTop()
oParent := oDlg:parent
ELSE
oParent := oDlg:parent:parent
ENDIF
oConfig := DC_XbpPushButtonXPConfig():new()
oConfig:bgColor := GRA_CLR_DARKGRAY
oConfig:fgColor := GRA_CLR_WHITE
oConfig:radius := 0
@ 100,100 DCDIALOG oButtonDlg DRAWINGAREA oDrawingArea ;
NOTITLEBAR NOMINBUTTON NOMAXBUTTON ;
BORDER XBPDLG_THINBORDER SIZE 35,20 PIXEL ;
PARENT oParent OWNER oDlg PREEVAL {|o|o:moveWithOwner := .t.} ;
EVAL {|o|o:drawingArea:setColorBG(XBPSYSCLR_TRANSPARENT), ;
oDlg:setButtons(o), ;
oDlg:setOffset(160)}
@ 0,0 DCPUSHBUTTONXP CAPTION 'Help' SIZE 33,18 PIXEL PARENT oDrawingArea CONFIG oConfig ;
ACTION {||MsgBox('There is no Help for you!')} ;
OBJECT oButton
DCREAD GUI EXIT PARENT oAppDeskTop
oButton:invalidateRect()
PostAppEvent(xbeP_Resize,,,oDlg)
DC_CompleteEvents()
IF oParent # AppDeskTop()
oDlg:killDisplayFocus := {||oButtonDlg:hide()}
oDlg:setDisplayFocus := {||oButtonDlg:show()}
ENDIF
RETURN nil