Adding buttons to a Title Bar

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4734
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Adding buttons to a Title Bar

#1 Post by rdonnay »

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.

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
Attachments
titlebar.zip
(173.89 KiB) Downloaded 588 times
The eXpress train is coming - and it has more cars.

User avatar
hz_scotty
Posts: 107
Joined: Thu Jan 28, 2010 8:20 am
Location: Wr.Neustadt / Österreich

Re: Adding buttons to a Title Bar

#2 Post by hz_scotty »

Hello Roger!

I've discovered an anomaly in the windows.

start titlebar.exe, open test window, click help button in the testwindow, a message come, click ok -
do not close the testwindow, click help button on main window, a message comes, click ok

the help button in the testwindow is gone and the windows flashes

for info
best regards
Hans

User avatar
rdonnay
Site Admin
Posts: 4734
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Adding buttons to a Title Bar

#3 Post by rdonnay »

The anomaly that you refer to is caused by the following code:

IF oParent # AppDeskTop()
oDlg:killDisplayFocus := {||oButtonDlg:hide()}
oDlg:setDisplayFocus := {||oButtonDlg:show()}
ENDIF

I added this code to deal with a worse anomaly which only occurs on child windows of the main window.
Comment out that code and you will see what I mean.

The button shows again when the window receives focus.

This anomaly does not occur on modal windows or windows that are not child windows of the main window.

This solution is a workaround due to limitations of the Windows dialog system.
The eXpress train is coming - and it has more cars.

Post Reply