24 May
2005

Minimize and be Damned, continued

In the first part of this I generally described how I created the object for showing a minmised form, the standard icon and label.

To restore the form I could have used one of two different methods, either tightly bind the individual icon object with the form that it was attached to, or use the system UI messaging abilities of the Codemine Class Library that I use for all Visual Foxpro applications.

I decided, partly to make it a more general solution, to do the former. This really just meant adding an object reference to the Form to the obicon class and then attaching code to the DblClick event to restore the Form, make it visible and kill the icon object.

After testing the code, I took it out of the test form and amended a custom version of the underlying form class. In Codemine's case that's the frmFormCustom class in the custom folder.

Now all forms which inherit from this class (which is all the ones I use), now get the minimise to icon behaviour without any further work.

In the extended entry (or on LJ behind the cut) is the code.


the minimize method on the form:
* create an obicon object with our form icon, the caption and the name
* so that we can restore it afterwards.

nNewPosition = _screen.nLasticon
oIconname = "_Screen."+ALLTRIM(this.name)+"icon"
_screen.AddObject(ALLTRIM(this.name)+"icon","obIcon")
WITH &oIconname
.imgImagecustom1.picture = thisform.Icon
.top = nNewPosition
nNewPosition = nNewPosition + .height+3
IF nNewPosition > (_screen.Height - 75)
nNewPosition = 0
ENDIF
_screen.nLasticon = nNewPosition
.cname = this.Name
.cTitle = this.Caption
.lbltextcustom1.caption = this.Caption
.lbltextcustom1.alignment = 2
.form = this
.visible = .t.
ENDWITH
this.savesizeandposition()
thisform.Visible = .f.
_screen.Refresh

When the icon is created the init code includes the following to handle the drag and drop:

=DODEFAULT()
BINDEVENT(_SCREEN,"DragDrop",this,"HandleDragDrop")

The DragDrop code itself is really very generic:

Handledragdrop
LPARAMETERS oSource, nXCoord, nYCoord
width = oSource.width
newx = nXcoord - (width / 2)
height = oSource.height
newy = nYcoord - (height / 2)
oSource.Move(newx,newy)

And then finally the code for when the icon is double clicked:

* restore the minimised window
this.Visible = .f.
this.form.WindowState = 0
this.form.restoresizeandposition()
this.form.visible = .t.
this.form.show()
_Screen.RemoveObject(this.Name)

And that's all that's needed.

There are a couple of limitations at the moment which I'll get to if they cause a nuisance. The icons are only created in the first column of the available desktop right now (users would have to move them around themselves if they needed more), I could add code to store the current column position as well but in practice I don't think users will have that many forms minimised and its probably a bad idea if they do have that many open at one time for the health of the application.

Secondly, right now the drag drop is just on the container so you have to click outside the icon or label, this is non inutitive and it will be fixed before put in front of a user.

There is one situation when I should automatically restore the minimised forms and that's when the user closes the application. if they have unsaved data then they'll be asked correctly if they want it saved, and the dialog will have the necessary title to let them know which form but it should be restored so that they can see the details and the icon be cleanly removed.

Posted by theSliver at 12:54 | Comments (0)
<< Payback Time | Main | Adding the News >>
Comments
There are no comments.