Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Topr right control box on form 2

Status
Not open for further replies.

button71

Programmer
Nov 8, 2006
69
AU
Is it possible to have a Title Bar with an Icon + Title and not have the control box?

When I use controlbox = .f. I loose the Icon?

Regards

William
 
If your are talking about the 3 buttons:
- = Minimize
[] = maxamize
These 2 are controled by Window state
X = close (Closeable)

You can disable each or all of them
By setting ControlBox = .f., you have removed them. You can do this and put your own Icon on the Form - (Not in the Title bar) and put whatever code you want in it. It is easier if you have a class of the form and put your "box" on the class.
 
William,

If you set Closable to .F., you lose the icon. That's inevitable. The icon is the control box.

You can add your own icon, but not in the title bar. You would have to place on the actual form surface.

If you set MinButton, MaxButton and Closeable all to .F., you still get the control box, but it doesn't do anything except Move and Size. Is that any use to you?

All this raises the question: Why do you want to do this? What have you got against the control box? It serves a useful purpose, and users expect it to be there.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

I have put the - and x buttons back at top right.

I used a [Close] button on my working form that is always visible over the top of a black 'Main' form to run this code

Code:
	DO  cleaner
	Clear EVENTS
	Quit

I have put the above code on the Unload Method on the Main Form.


Minimise works fine but I get 'Cannot Quit Visual FoxPro' error when I click on the X.


In Cleaner I run code to cleanout the temp folder I use when running the application.

Regards

William
 
William,

Don't put that code in the Unload. Instead, put a CLEAR EVENTS in the Destroy. In your main program (the one containing READ EVENTS), put the cleanup and the QUIT after the READ EVENTS.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

I still got the error - so I put a Set Step On before the CLEAR EVENTS in destroy.

When I click the X on the Main Form it justs goes directly to the error. So the Destroy method isn't being used possibly?

Regards

William

 
William,

In that case, you must be trying to do a QUIT at some earlier point in the process. Check through all you code, looking for a QUIT command. If you find it, you probably need to remove it.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Folks,

Further to the above

Sometimes my app closes Ok, on others it locks up at this DO WHILE loop and the form does not close.

Code:
PROCEDURE PropShutdown()

* --- Release/Close All Open Forms ---
*!*Any other clean up code you may want goes here


DO WHILE _SCREEN.FORMCOUNT > 0
	_SCREEN.FORMS(1).RELEASE
ENDDO

DO Mycleaner 

Release WINDOW ALL
CLOSE DATABASES ALL
Release ALL
Clear ALL
CLOSE ALL
Clear PROGRAM
Clear EVENTS
QUIT

END PROC

I'm stumped - as far as I can see I have followed all the advise above and on Mike's web site.

Anyone help?

Regards

William
 
William,

With regard to the form that fails to close in the DO WHILE loop. Check the code in the Destroy, Unload and QueryUnload events. In particular, look for NODEFAULT. That would likely prevent the closing of the form.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Code:
[DO WHILE _SCREEN.FORMCOUNT > 0
    _SCREEN.FORMS(1).RELEASE
ENDDO

1. forms(1): you are closing the First Object and only the first, could be a form, a toolbar etc.

try this:
Code:
nCount =  _Screen.FormCount
For nForm = 1 To nCount		
  If Alltrim(Upper(_Screen.Forms(nForm).BaseClass)) = "FORM"
	_screen.forms(nForm).release
  Endif
Endfor

Close all toolbars seperately. If it has been declared public, it will be released by the following line:

Release all extended

*** some thing like this (to give you an idea)
Pop Menu _Msysmenu To Master
Set Sysmenu To Default
Set Message To " "
Set Classlib To
Clear
Clear Events
Close Data All
Release All Extended
*Quit

 
Imaginecorp,

nCount = _Screen.FormCount
For nForm = 1 To nCount
If Alltrim(Upper(_Screen.Forms(nForm).BaseClass)) = "FORM"
_screen.forms(nForm).release
Endif
Endfor

I'm not sure that will work. The problem is that nCount will stay constant during the loop, but nForm will increment.

So, if nCount starts at 10, you'll go round the loop 10 times. After you've closed five forms, nForm will contain 6, but there is no longer a sixth form to close. You'll probably get a "subscript out of bounds" error.

The following might work better:

Code:
nForm =  1
DO WHILE nForm <= _Screens.FormCount
  If Alltrim(Upper(_Screen.Forms(nForm).BaseClass)) = "FORM"
    _screen.forms(nForm).release
  Endif
  nForm = nForm + 1
ENDDO

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,
I hate like hell to disagree with you, but the For..Endfor Loop will work.
It loops based upon the objects in _screen. It does not matter how many. The IF will close the forms.

_Screen.Forms() refers to Objects and not Forms, (misleading use of the name Form)

Try it...
 
Imaginecorp,

I hate like hell to disagree with you ...

Come now. Lots of other people do. You shouldn't feel left out <g>.

Seriously though ...

I just ran your code. I started with six forms and one toolbar open. Here's what happened:

At start:
FormCount = 7
nCount = 7

1st time round:
nCount points to toolbar; no action
nCount = 7

2nd time round:
closed 1st form
nCount = 6

3rd time round:
closed 2nd form
nCount = 5

4th time round:
closed 3rd form
nCount = 4

5th time round:
closed 4th form
nCount = 5

6th time round
tried to close 5th form, but only 3 forms now open, so it crashed.

The error was "FORMS is not an object", which I think it consistent with what happens when you try to address an empty collection.

Of course, it might be something quite different that caused the error. I'll try plugging in my own version of the code to see what difference that makes. In the meantime, I'd be interested in your observations.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Ha!. My version of the code didn't work either. I'll try to figure out why.

However, here's a version which I know does work:

Code:
nCount =  _Screen.FormCount
For [b]nForm = nCount TO 1 STEP -1[/b]
  If Alltrim(Upper(_Screen.Forms(nForm).BaseClass)) = "FORM"
    _screen.forms(nForm).release
  Endif
Endfor

In other words, you are counting downward from FormCount to 1. That will work, because nForm is always going to point to an existing form.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Strange:

Now: lets see this step by step
1 Form + 1 tool bar + 4 forms - All Objects in this order
nCount = _Screen.FormCount
****nCount returns 6 and will NEVER change. Its outside the loop.

For nForm = 1 To nCount
*** loop 6 times
If Alltrim(Upper(_Screen.Forms(nForm).BaseClass)) = "FORM"
_screen.forms(nForm).release
Endif
***nForm = 1
***is object 1 a form .. Yes, Close
*** nform = 2
*** is object 2 a Form ... No Next
*** nform = 3
*** is object 3 a form .... Yes Close
*** nform = 4
*** is object 4 a form .... Yes Close
*** nform = 5
*** is object 5 a form .... Yes Close
*** nform = 6
*** is object 6 a form .... Yes Close
***Fallout
Endfor

What am I missing?

 
What you're missing is that you're dealing with a collection, not an array, and as you remove items from the collection, the size of the collection shrinks.

In fact, Button71's original code was designed to deal with. Each time through the loop, it removes the first item from the collection. That means the next time through the loop, the firs item is a different item.

Personally, I prefer the looping backwards approach, as in Mike Lewis' code a few messages back. I find it easier to understand.

Tamar
 
WOW... You are both right. Feel pretty sheepish...

In my defense: we Do Not close open forms in our app, but just check to see if any are open, If so we warn the user to close them. This is to prevent the user from closing the app with forms open.

No wonder the following code works. Wrote this years ago and never had to re-visit. The minute it sees a form open, it warns then falls out of the loop.

Code:
lFormFound = .F.
nCount =  _Screen.FormCount
For cForm = 1 To nCount
  If Alltrim(Upper(_Screen.Forms(cForm).BaseClass)) = "FORM"
	lFormFound = .T.
	Exit
  Endif
Endfor
If lFormFound
  = Messagebox(mAppName+" has determined there are some screens that are still open."+Chr(13)+;
 "Shutting down now may cause problems in "+mAppName+Chr(13)+;
 "Close all open screens first,then shut down.",16,its_logo)
 Return
Endif
 
Wow,

I thought I was asking a 'simple' question.

Thanks to everyone - it seems that Mike's solution is working for me.

William
 
Imaginecorp,

I'm pleased it's all clear now. As usual, Tamar explained the problem better than ever I could.

William,

I thought I was asking a 'simple' question.

But this is Visual FoxPro. Nothing is ever as simple as you first think <g>.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top