Wiki Home

Screen Methods


Namespace: Wiki
WARNING This technique has been disabled starting with VFP8 SP1.

Screen Methods is a program by Fred Taylor that's been floating around Fox USENET newsgroups for a while. It demonstrates a technique that allows you to assign code to PEMs of _SCREEN, such as Resize. -- Willson De Veas

For the historical source and various examples of how to use this, see:
http://groups.google.com/groups?sourceid=navclient&q=screenmethods%2Eprg
*
* ScreenMethods.PRG
*
* Fred Taylor - ElZorro 4/10/2001 www.elzorro.org
*   with thanks to "Michel Roy" roym@jonar.com from the
*   News Group microsoft.public.fox.programmer.exchange
*   Subject: Re: Centering Picture in _SCREEN
*                ( or modifying _SCREEN Methods )
*
* Use the following to modify _SCREEN methods:
*
* For VFP6 & 7:
*
*     _SCREEN.NewObject("oSH","ScreenHook","screenmethods.prg")
*
* For VFP3 & 5:
*
*     SET PROCEDURE TO screenmethods ADDITIVE
*     _SCREEN.AddObject("oSH","ScreenHook")
*
* Most of the main VFP screen methods can be hooked into in this manner.
* A similar technique can also be used to hook methods of grid
* headers, etc., at run-time.
*
DEFINE CLASS Screenhook AS CUSTOM
oScr = _SCREEN
KeyPreview = .t.

FUNCTION oScr.Click        && Works
WAIT WINDOW NOWAIT "_SCREEN.Click"
ENDFUNC

FUNCTION oScr.DblClick     && Works
* Note that Click fires first!
WAIT WINDOW NOWAIT "_SCREEN.DblClick"
ENDFUNC

PROCEDURE oScr.KeyPress    && Works
LPARAMETERS nKeyCode, nShiftStat
? nKeyCode, nShiftStat
ENDPROC

PROCEDURE oScr.QueryUnload
  NODEFAULT                && Hmmm, doesn't work like a form's does.
  WAIT WINDOW NOWAIT "QueryUnload!"
ENDPROC

PROCEDURE oScr.Resize()    && Works
  *
  * Code to handle the main VFP screen being resized
  *
  WAIT WINDOW NOWAIT TRANSFORM(this.Width)+" "+TRANSFORM(this.Height)
ENDPROC

PROCEDURE oScr.RightClick  && Works
  *
  * Code to do a "shortcut" menu on main VFP screen rightclick
  *
  DO testmenu.mpr
ENDPROC

*-------------------------------
PROCEDURE oScr.MyMethod    && Works
wait window "my method fired!"
ENDPROC
ENDDEFINE



As per a request, how do you know when the _screen is minimized?
_Screen.Newobject("sh", "sh", "e:\vfptest\screenmin.prg")

Define Class sh As Custom
  oScr = _Screen
  Procedure Init
    If Vartype(_Screen.nLastWindowState) <> "N"
      _Screen.AddProperty("nLastWindowState")
    Endif
    _Screen.nLastWindowState = _Screen.WindowState
  Endproc

  Procedure oScr.Resize
    If This.nLastWindowState <> 1 And This.WindowState = 1
      _Screen.Caption = "Minimized"
    Else
    _Screen.Caption = "VFP"
    Endif
    This.nLastWindowState = This.WindowState
  Endproc
Enddefine


Here I am posting the code for VFP 8 and VFP 9 beta, It serves the same purpose as of the above code. As the above code does not work in the newer versions. Here is a little bit change in the code.
Kamran Chughtai (PUCIT)
PUBLIC oSH
oSH = NEWOBJECT("ScreenHook")
BINDEVENT(_SCREEN,"Resize",oSH,"myResize")
BINDEVENT(_SCREEN,"RightClick",oSH,"myRightClick")

_screen.addobject("oImage", "Image")

WITH _screen.oImage
   .picture = GETPICT()
*  .picture = 'pakflag5.gif'
   .stretch = 0
   .left = (_screen.width  / 2) - (.width  / 2)
   .top  = (_screen.height / 2) - (.height / 2)
   .visible = .T.
ENDWITH

DEFINE CLASS ScreenHook AS CUSTOM
	PROCEDURE myResize
		WITH _screen.oImage
		   .left = (_screen.width  / 2) - (.width  / 2)
		   .top  = (_screen.height / 2) - (.height / 2)
		ENDWITH
	ENDPROC

	PROCEDURE myRightClick
		DO screenmenu.mpr
	ENDPROC

	PROCEDURE MyMethod
		wait window "my method fired!"
	ENDPROC
ENDDEFINE

See also: Screen Resize
Category Code Samples
( Topic last updated: 2006.05.12 07:58:22 AM )