How to create a multi-thread window

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

How to create a multi-thread window

#1 Post by rdonnay »

Brian Wolfsohn suggested in this thread http://bb.donnay-software.com/donnay/vi ... 2&start=46 that it would be great to put some of his existing windows on multiple tab pages.

Each TabPage runs in its own thread.

Here is a sample program that shows how to do this.
Compile and run the below sample to see how it works.

Caution must be used when doing this as it is necessary to shut down the child threads when the parent window is closed.

Code: Select all

#INCLUDE "dcdialog.CH"
#INCLUDE "appevent.CH"

FUNCTION Main()

LOCAL GetList[0], oMenu, oSubMenu, oDlg, GetOptions

DCMENUBAR oMenu
  DCSUBMENU oSubMenu PROMPT 'File' PARENT oMenu
    DCMENUITEM 'Multi-Threaded Window' ;
      ACTION {|o|o := Thread():new(),Sleep(5),o:start({||MultiTab(oDlg:drawingArea)})} ;
      PARENT oSubMenu
    DCMENUITEM 'Single-Threaded Window' ;
      ACTION {|o|o := Thread():new(),Sleep(5),o:start({||DataBrowse(oDlg:drawingArea)})} ;
      PARENT oSubMenu

DCGETOPTIONS WINDOWWIDTH 1000 WINDOWHEIGHT 800
DCREAD GUI TITLE 'Multi-Threaded Window Test' PARENT @oDlg OPTIONS GetOptions

RETURN nil

* ----------

FUNCTION MultiTab(oParent)

LOCAL GetList[0], oTab1, oTab2, oTab3, aGetList[0], i, oDlg, oGetList

AAdd(aGetList,{})
AAdd(aGetList,{})
AAdd(aGetList,{})

DC_LoadRdds()

@ 0,0 DCTABPAGE oTab1 SIZE 100,25 CAPTION 'Tab 1'
@ 0,0 DCTABPAGE oTab2 CAPTION 'Tab 2' RELATIVE oTab1
@ 0,0 DCTABPAGE oTab3 CAPTION 'Tab 3' RELATIVE oTab2

DCREAD GUI FIT TITLE 'This is a Three-Thread Window' ;
   APPWINDOW oParent ;
   NODESTROY PARENT @oDlg ;
   EVAL {|o|Sleep(20), ;
            o := Thread():new(), Sleep(10), o:start({||DataBrowse(oTab1,aGetList[1])}),;
            Sleep(20), ;
            o := Thread():new(), Sleep(10), o:start({||DataBrowse(oTab2,aGetList[2])}),;
            Sleep(20), ;
            o := Thread():new(), Sleep(10), o:start({||DataBrowse(oTab3,aGetList[3])}),;
            nil}

// Make sure all child threads are closed before destroying this window
FOR i := 1 TO Len(aGetList)
  oGetList := DC_GetListObject(aGetList[i])
  oGetList:isDialogActive := .f.
  Sleep(10)
NEXT

oDlg:destroy()

RETURN nil

* ------------

PROC appsys ; RETURN

* ------------

FUNCTION DataBrowse(oParent,GetList)

LOCAL oBrowse

DEFAULT GetList := {}

USE \exp19\data\xtest VIA 'FOXCDX'

@ 2,2 DCBROWSE oBrowse ALIAS 'XTEST' SIZE 96,20  FONT '10.Lucida Console'

DCBROWSECOL FIELD XTEST->areacode WIDTH 10 PARENT oBrowse
DCBROWSECOL FIELD XTEST->exchange WIDTH 10 PARENT oBrowse
DCBROWSECOL FIELD XTEST->number WIDTH 10 PARENT oBrowse
DCBROWSECOL FIELD XTEST->date WIDTH 10 PARENT oBrowse
DCBROWSECOL FIELD XTEST->time WIDTH 10 PARENT oBrowse

@ 23,2 DCSAY 'This Browse is running in Thread ' + Alltrim(Str(ThreadID())) ;
       SAYSIZE 0 FONT '12.Lucida Console'

IF oParent:isDerivedFrom("DC_XbpTabPage")
  // All objects will be created on oParent.  No dialog window.
  DCREAD GUI PARENT oParent WAIT 5
ELSE
  // All objects will be created on a new dialog window.
  DCREAD GUI FIT APPWINDOW oParent TITLE 'This is a One-Thread Window'
ENDIF

dbCloseAll()

RETURN nil
The eXpress train is coming - and it has more cars.

bwolfsohn
Posts: 649
Joined: Thu Jan 28, 2010 7:07 am
Location: Alachua, Florida USA
Contact:

Re: How to create a multi-thread window

#2 Post by bwolfsohn »

quick test works nicely, even inside our regular application window...

I'm going to look to implement this along with re-doing our circa y2k vanilla dialogs..
Brian Wolfsohn
Retired and traveling around the country to music festivals in my RV.
OOPS.. Corona Virus, so NOT traveling right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises

skiman
Posts: 1199
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: How to create a multi-thread window

#3 Post by skiman »

Hi,

I just tested it. It looks as I probably misunderstood the question of Brian. I thought he would like to see the content of the tabpages in the drawingarea of the main window. I experimented a bit with this today, and the look is what I like. But as mentioned in the other thread, it looks to me that it is difficult to use it in a multi-threaded application.
Best regards,

Chris.
www.aboservice.be

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

Re: How to create a multi-thread window

#4 Post by rdonnay »

I thought he would like to see the content of the tabpages in the drawingarea of the main window.
Try this:

DCREAD GUI PARENT oMainWindow:drawingArea
The eXpress train is coming - and it has more cars.

bwolfsohn
Posts: 649
Joined: Thu Jan 28, 2010 7:07 am
Location: Alachua, Florida USA
Contact:

Re: How to create a multi-thread window

#5 Post by bwolfsohn »

rdonnay wrote:
I thought he would like to see the content of the tabpages in the drawingarea of the main window.
Try this:

DCREAD GUI PARENT oMainWindow:drawingArea
that's basically what i did to put it into our app..
Brian Wolfsohn
Retired and traveling around the country to music festivals in my RV.
OOPS.. Corona Virus, so NOT traveling right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises

skiman
Posts: 1199
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: How to create a multi-thread window

#6 Post by skiman »

Yes, that's what I did. But this way it is difficult to see how much 'screens' are already open. If a normal MDI window is used, it is clear for the user if he opens a screen two times.

That's my problem. A better look but with less functionality is the result.
Best regards,

Chris.
www.aboservice.be

bwolfsohn
Posts: 649
Joined: Thu Jan 28, 2010 7:07 am
Location: Alachua, Florida USA
Contact:

Re: How to create a multi-thread window

#7 Post by bwolfsohn »

what i'm planning is automatically opening up buyer lots & sellers into a 3 tabbed dialog.

we can prevent 2 buyer windows from opening now by checking the titles of the open windows.

Couldn't we use that same routine to keep someone from opening up the multi-threaded window twice ?

Other windows could still be opened.

perhaps w/ future development, the # of tabs could be dynamically changed.. (additional tabs added / removed)

just random thoughts at this point..
Brian Wolfsohn
Retired and traveling around the country to music festivals in my RV.
OOPS.. Corona Virus, so NOT traveling right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises

bwolfsohn
Posts: 649
Joined: Thu Jan 28, 2010 7:07 am
Location: Alachua, Florida USA
Contact:

Re: How to create a multi-thread window

#8 Post by bwolfsohn »

not sure what you mean by not sure how many screens are open... it seems like it's just a minor user thought adjustment... unless i'm missing the point...
Brian Wolfsohn
Retired and traveling around the country to music festivals in my RV.
OOPS.. Corona Virus, so NOT traveling right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises

skiman
Posts: 1199
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: How to create a multi-thread window

#9 Post by skiman »

Hi Brian,

When using Windows, a user sees the different windows. You can also use the 'CASCADE' option. A user can place the different screens on a different place.

Each window is running in a different thread.
mdiwindows.jpg
mdiwindows.jpg (113.58 KiB) Viewed 13526 times
When placing the window in the drawingarea of the main window, you don't have this possibility anymore. Below there is a window opened which is integrated in the drawingarea. Now you can't see if there are other windows open, and you can't move them.
drawingarea.jpg
drawingarea.jpg (87.6 KiB) Viewed 13526 times
This is my problem. I prefer the look when using the drawingarea, but I want the functionality of the old style. I don't know how to solve this.
Best regards,

Chris.
www.aboservice.be

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

Re: How to create a multi-thread window

#10 Post by rdonnay »

Chris -

I don't think you quite understand what Brian was asking for.

His Auction program has lots of windows, but there are 3 of them that are always opened at the same time. It occurred to him that it probably would have been better to merge the functionality of those 3 windows into a single window. However, due to the way his software was written, it would have been a large project. He wanted to know if he could take his existing code (in which each window is running in a different thread) and merge this code into a single window yet still have the original code running in it's own thread.

I thought that this was an interesting idea and that it was very possible to do. In fact, it is so easy to do that it could even become a configuration option which could be chosen by the user.

I am not yet understanding what it is that you are trying to do. From your screen shot, it looks like you want to paint screen objects in the drawing area of the main window, but also want to maintain the functionality of separate windows.
Am I right about this?
The eXpress train is coming - and it has more cars.

Post Reply