FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Button behavior with MDI
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Button behavior with MDI
Posted: Thu Apr 23, 2026 11:20 PM

I am converting a very large, MODAL program ( legacy ) to MDI. I've been using Claude and have been very pleased with the results.

On the main screen there is a button bar. One button, Tools ( which controls a drop down menu for setup options, etc. ) we want to maintain as MODAL because any changes there could affect open Windows if that were permitted.

The idea is to make it active, but once a MDI window is opened, it is disabled. When all MDI windows are closed, then we want it to be enabled again. Claude has become exhausted trying to find a solution. Perhaps someone on the forum has dealt with this issue and knows the solution to our problem: When an MDI windows opens the button is disabled. When all windows are closed, the system fails to enable it.

Here is what claude has tried:
Good call. For the forum post, here's a concise summary of what's been tried:

Goal: Disable/gray the Tools button on the main TBar (oReBar) while any MDI child windows are open,
re-enable when all are closed.

Mechanism: DEFINE TIMER ... INTERVAL 400 ... ACTION oReBar:AEvalWhen() + WHEN (condition) clause on
the button.

What works: The button IS disabled when an MDI child opens — so AEvalWhen() fires, bWhen is evaluated,
and Disable() runs correctly.

What doesn't work: The button never re-enables after all MDI children are closed, regardless of what
the WHEN condition checks.

Conditions tried — all failed to restore:

  1. Len( oWnd:oWndClient:aWnd ) == 0 — FiveWin's own tracking array

  2. AScan( oWnd:oWndClient:aWnd, { |o| IsWindow( o:hWnd ) } ) == 0 — filtered for live handles

  3. SendMessage( oWnd:oWndClient:hWnd, 553, 0, 0 ) == 0 — WM_MDIGETACTIVE direct to MDICLIENT

    The suspicion is that either AEvalWhen() isn't re-evaluating bWhen after disable, or TBtnBmp:Enable()
    isn't fully restoring visual/functional state in the 2015 bar style. The forum may know the correct
    pattern for dynamically enabling/disabling a TBar button at runtime.

Here is the current control in the source code:

				DEFINE BUTTON oWBtn8 OF oReBar RESOURCE "FIBILD" PROMPT "Tools" ;
				               ACTION oWbtn8:ShowPopup() MENU oWPopM8 TOOLTIP "Special tools" BTNRIGHT GROUP LABEL "System" ;
				               WHEN ( oWnd:oWndClient == NIL .OR. SendMessage( oWnd:oWndClient:hWnd, 553, 0, 0 ) == 0 )

Does anyone have a solution ?

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Button behavior with MDI
Posted: Fri Apr 24, 2026 02:36 AM

Dear Tim,

Could you please provide a screenshot ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Button behavior with MDI
Posted: Fri Apr 24, 2026 12:09 PM

Dear Tim, could you make a small demo for testing?

Gracias, tks.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Button behavior with MDI
Posted: Fri Apr 24, 2026 06:48 PM

I would love to give you a small test code, but that would be quite large. It would involve creating a main window, with a button bar, and a test MDI window. However, perhaps a step by step will help if someone knows FWH source well enough to give an answer.

First, Antonio and I worked on this last night. Here is a solution we found. It will block the dropdown menu, or any code execution, but it does not put the button itself in a disable() mode. Thus the button shows fully, but if a MDI window is open, then clicks pop up the message to close windows, and it does activate the menu or functions called. That works, but is not the "modern" behavior. Here is that code:

				DEFINE BUTTON oWBtn8 OF oReBar RESOURCE "FIBILD" PROMPT "Tools" ;
				              ACTION If( Len( oWnd:oWndClient:aWnd ) > 0, MsgAlert( "All ASW windows must be closed to use Tools"), oWbtn8:ShowPopup() ) ;
				              MENU oWPopM8 TOOLTIP "Special tools" BTNRIGHT GROUP LABEL "System"

Here is where it gets interesting. If I use the following code, the button is disabled ( and the display dimmed ) as desired when I open an MDI. However, when the MDI is closed, the button is not enabled. Here is that code:

				DEFINE BUTTON oWBtn8 OF oReBar RESOURCE "FIBILD" PROMPT "Tools" ;
				              ACTION oWbtn8:ShowPopup()  ;
				              WHEN LEN( oWnd:oWndClient:aWnd) == 0 ;	
				              MENU oWPopM8 TOOLTIP "Special tools" BTNRIGHT GROUP LABEL "System"

I also added a button to run this little piece of code. If I click the button, after closing an MDI, it shows that aWnd has returned to 0. As soon as I exit the popup message, then the Tools button suddenly reappears in enabled mode. Here is that code:

DEFINE BUTTON oWBtn9 OF oReBar RESOURCE "HRHELP" PROMPT "Help" ;	
		   ACTION MsgInfo( Len( oWnd:oWndClient:aWnd) ) BTNRIGHT

So, the solution to my problem lies in what occurs with that last button. The close of MsgInfo apparently triggers some function that allows for the state of BUTTON oWBtn8 to be re-evaluated in the WHEN statement ... and I can find what that is, I'm done. If you have the answer, you can know you are smarter than Claude because it had no idea !

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Button behavior with MDI
Posted: Fri Apr 24, 2026 08:50 PM

AND WE HAVE A SOLUTION -

Working with Claude code, the initial solution was to create a timer to check the status of the open MDI windows, and then update the WHEN clause of the button in question. However, no matter how many combinations it tried, it never worked.

After a lot of experimenting, I finally took a closer look and realized that Claude never activated the timer ! I worked this with Claude Code a long time, and it never caught it. This morning I worked on it with my desktop Claude interface and no solution. I guess the leesson is that Claude can help, but ultimately our knowledge may be the only solution to some issues. I should add, to be fair, that I am converting a legacy app from MODAL to MDI, and as I trained Claude on the process, I could provide it access to a file and tell it to make it MDI, and it handled everything, including resources, very quickly.

For reference, here is the button code:

				DEFINE BUTTON oWBtn8 OF oReBar RESOURCE "FIBILD" PROMPT "Tools" ;
				              ACTION oWbtn8:ShowPopup()  ;
				              WHEN LEN( oWnd:oWndClient:aWnd) == 0 ;	
				              MENU oWPopM8 TOOLTIP "Special tools" BTNRIGHT GROUP LABEL "System"

And here is the TIMER code:

		// Disable Tools button while any MDI child windows are open
		DEFINE TIMER oTimerMdi INTERVAL 400 OF oWnd ;
			ACTION If( Len( oWnd:oWndClient:aWnd ) = 0, oWbtn8:enable(), oWbtn8:disable() ) 
 		oTimerMdi:activate()
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit

Continue the discussion