I am re-writing a MDI application that has mdichildren. I am replacing the mdichildren with dialog\nowait... Previously, when a user 'x''d out of the mdi frame .. the valid would fire on the mdichild and I could trap that event and close everything down nicely and exit the program.
Compile the code and cut and past the utilmenu.rc and link .. when you close Utilmenu .. the valid fires and I can trap that .. re-open Utilmenu and then 'x' out of the MDI frame .. and you will notice the Utilmenu valid does not fire .. but the MDI valid does fire.. my concern is that I may have ADO recordsets open and if I can not trap a MDI close .. I will not be able to close those recordsets properly
Here is a sample piece of code :
- Code: Select all Expand view
// main.prg
#INCLUDE "FIVEWIN.CH"
STATIC oWInd // main mdi window
STATIC oBmap // mdi window .bmp
STATIC lExitPgm := .F.
STATIC xMESSAGE
STATIC lOKx
//----------------------------------
FUNC MAIN()
LOCAL cDEFA,nLEN,cFILE,cRIGHTS,SAYING,mSTART,aDIR,cRDD
LOCAL cREAD,cWRITE,cSUPER,cOLDDEFA,cADMIN
LOCAL nPOS,cLOGIN,dEXE
LOCAL nYEAR,nSCR1,nSCR2,aVER
LOCAL oICO, oRs, cSQL, oErr, cPROG
LOCAL lOK, oDLG, cINIFILE, cERR
LOCAL TEXT_EOF, BYTES_READ,cTEXT,nHANDLE
LOCAL oSAY, cSAY
PUBLIC xVOL := "C:", xREAD,xWRITE,xLOGIN,xSUPER,xADMIN
PUBLIC xPROVIDER, xSOURCE, xCATALOG, xUSERID, xPASSWORD, xPROGID
PUBLIC xTABLE, xHOLD_TABLE, xQUE_TABLE
//--------------
PARAMETERS xTEXT
REQUEST DBFCDX
rddsetdefault ( "DBFCDX" )
xREAD := " "
xWRITE := " "
xLOGIN := " "
xSUPER := " "
xPROGID := " "
xADMIN := " "
xPROVIDER := "SQLOLEDB"
*xSOURCE := "MSSQL01"
xSOURCE := "LWMWEBDB01"
xCATALOG := "PCAS"
xUSERID := "pcasuser"
xPASSWORD := "pcas"
nSCR1 := GetSysMetrics(0)
nSCR2 := GetSysMetrics(1)
//-- get timestamp on .exe //
cFILE := GetModuleFileName( GetInstance() )
aDIR := DIRECTORY( cFILE )
dEXE := aDIR[1] [3]
// where .exe started from is default directory //
mSTART := RAT( "\", cFILE )
cDEFA := SUBSTR(cFILE,1,mSTART-1)
aDIR := NIL
SET DEFA to ( cDEFA )
cOLDDEFA := cDEFA
cRDD := xPROVIDER+" on "+xSOURCE+" 32 bit -b x86"
SET DELETED on
SET CENTURY on
SET 3DLOOK on
nYEAR := ( year( DATE() )-5 )
SET EPOCH to ( nYEAR )
// test for TEXT mode /NL for no logo
IF EMPTY( xTEXT )
xTEXT := " "
ENDIF
xTEXT := ALLTRIM( UPPER(xTEXT))
xLOGIN := WNetGetUser() // FiveWin function
xLOGIN := UPPER( xLOGIN )
xLOGIN := xLOGIN+SPACE(8)
xLOGIN := SUBSTR(xLOGIN,1,8)
xWRITE := 'Y'
xSUPER := 'Y'
xADMIN := 'Y'
cRIGHTS := _Rights()
//----- main menu -------//
xMESSAGE := "User "+xLOGIN+" Rights "+cRIGHTS+ ;
" Default= "+cDEFA+" Rdd= "+cRDD+ ;
" Revision "+DTOC(dEXE)+;
" -r"+str(nSCR1,4)+" x "+STR(nSCR2,4)
*DEFINE ICON oICO RESOURCE "COUPLE"
DEFINE WINDOW oWind ;
FROM 0,2 to 28,78 ;
TITLE "PCAS Time and Data entry Program" ;
MENU BuildMenu(); //cOLDDEFA,dEXE,cRDD,nSCR1,nSCR2,oWind) ;
MDI
DEFINE BITMAP oBMAP FILENAME (cOLDDEFA+"\PCAS.BMP") of oWind
SET MESSAGE OF oWind ;
to xMESSAGE CLOCK
ACTIVATE WINDOW oWind ;
MAXIMIZED ;
ON PAINT ( _BackGround( hDC, oBmap, nSCR1, nSCR2, oWind, xTEXT ) );
ON INIT ( _Bar( oWind ) ) ;
VALID ( IF( !lExitPgm, ExitPgm( .T. ) , .F. ) )
RETURN( NIL )
//--------------------------
Static Func _BackGround( hDC, oBmap, nSCR1, nSCR2, oWind, xTEXT )
IF xTEXT = "/NL"
ELSE
PalBmpDraw( hDC, 0,0, oBMAP:hBitmap, oBMAP:hPalette, nSCR1, nSCR2 )
ENDIF
RETURN(NIL)
//--------------------------
Static Func _Bar( oWnd )
LOCAL aGRAD, oDLG, oBTN1, oBTN2, oSAY, cSAY
LOCAL nWIDTH, nHEIGHT, nTOP
nWidth := GetSysMetrics(0)
nHeight := GetSysMetrics(1)
nTop := GetSysMetrics(30)
cSAY := "Utility"+chr(10)
cSAY += "Information"+chr(10)
DEFINE DIALOG oDLG ;
FROM 0,0 to 100,100 of oWnd ;
STYLE nOR( WS_OVERLAPPED | WS_VISIBLE ) PIXEL TRANSPARENT
@ 20, 0 BTNBMP oBTN1 RESOURCE "STATS" ;
SIZE 32,40 adjust ;
NOBORDER ;
PROMPT cSAY CENTER of oDLG ;
ACTION ( _Utilmenu(oWnd, oBtn1 ))
oBtn1:lTransparent = .T.
oBtn1:cTooltip := "Utility Menu"
cSAY := "Utility"+chr(10)
cSAY += "Information"+chr(10)
* @ 2.5, 0 SAY cSAY OF oDlg COLOR "N/N"
* oDlg:aControls[ 2 ]:lTransparent = .t.
*aGrad := { { 0.1, 10389063, 16777215 },{ 0.1, 16777215, 10389063 } } // blue
aGRAD := {{ 1.0, 16777215,7518392},{ 1.00, 7518392, 16777215 }} // yellow
* @ 5,0 BUTTON oBTN2 PROMPT "Test" of oDLG ;
* SIZE 32,40 ;
* ACTION MsgInfo( "test" )
ACTIVATE DIALOG oDlg CENTERED NOWAIT ;
ON INIT oDlg:Move( 20, nWidth - 65, 70, nHeight - 75, .f. ) ;
ON PAINT ( GRADBAR( hDC, oDlg ), GradientBrush( oDlg, aGrad, .F. ) )
RETURN( NIL )
// ------- Fills the Buttons with Gradient-Background ----------
// ------ otherwise the Buttons are displayed with a white Color --
Static FUNCTION GradientBrush( oDlg, aColors , lDir)
local hDC, hBmp, hBmpOld , nWidth , nHeight
DEFAULT lDir := .T.
if Empty( oDlg:oBrush:hBitmap )
nHeight := if(lDir,oDlg:nHeight,1)
nWidth := if(lDir,1,oDlg:nWidth)
hDC = CreateCompatibleDC( oDlg:GetDC() )
hBmp = CreateCompatibleBitMap( oDlg:hDC, nWidth, nHeight )
hBmpOld = SelectObject( hDC, hBmp )
GradientFill( hDC, 0, 0, nHeight, nWidth, aColors,lDir )
DeleteObject( oDlg:oBrush:hBrush )
oDlg:oBrush:hBitmap = hBmp
oDlg:oBrush:hBrush = CreatePatternBrush( hBmp )
SelectObject( hDC, hBmpOld )
oDlg:ReleaseDC()
endif
RETURN NIL
// ---------- Fills the Bar with Gradient ---------------------
STATIC FUNCTION GRADBAR( hDC, oDlg )
local aGrad
*aGrad := { { 0.1, 10389063, 16777215 },{ 0.1, 16777215, 10389063 } } // blue
aGRAD := {{ 1.0, 16777215,7518392},{ 1.00, 7518392, 16777215 }}
GradientFill( hDC, 0, 0, oDlg:nHeight + 10, oDlg:nWidth, aGrad, .F. ) // yellow
RETURN NIL
//---------------------------
Static Func _Rights()
LOCAL cREAD,cWRITE,cSUPER,cADMIN,cRIGHTS
STORE " " to cWRITE,cSUPER,cADMIN
cREAD := "R"
IF xWRITE = 'Y'
cWRITE := "W"
ENDIF
IF xSUPER = "Y"
cSUPER := "S"
ENDIF
IF xADMIN = "Y"
cADMIN := "A"
ENDIF
IF cWRITE = " " .and. cSUPER = " " .and. cADMIN = " "
cRIGHTS := "(READ)"
ELSE
cRIGHTS := "("+cREAD+cWRITE+cSUPER+cADMIN+")"
ENDIF
RETURN( cRIGHTS )
//--------------------------//
Static FUNC BuildMenu() // cOLDDEFA, dEXE, cRDD,nSCR1,nSCR2,oWnd )
LOCAL oMenu, cRIGHTS, cDEFA
cDEFA := SET(7)
MENU oMenu
MENUITEM " "
ENDMENU
RETURN( oMenu )
//-----------------------
Static FUNCTION ExitPgm( lCLEAN )
IF lCLEAN = .T.
lExitPgm := .T.
SET RESOURCES to
msginfo( "main menu close" )
SysReFresh()
ENDIF
RETURN( lExitPgm )
//----------------------------------
Static FUNC _utilmenu( oWnd, oBtnx )
LOCAL oWndChild, oDlg, oBtn1, oBTN2, oBTN3, oBTN4, oBTN5, oBTN6
LOCAL oBTN7, oBTN8, oICO, aGrad
oBtnx:Hide()
lOKx := .F.
aGrad := { { 1.0, 16777215, nRGB(4,53,107) },{ 1.0, nRGB(4,53,107), 16777215 } }
DEFINE DIALOG oDlg RESOURCE "UTILMENU" ; // OF oWndChild ;
FROM 0,0 to 20,50 ;
TITLE "Utility Menu" ;
REDEFINE BUTTON oBtn1 ID 101 OF oDlg ;
ACTION ( Msginfo( "Indexing not required for SQL" ))
REDEFINE BUTTON oBtn2 ID 102 OF oDlg ;
ACTION ( MsgInfo( "Menu 2" )) // , _UtilBrow( oWnd ) )
REDEFINE BUTTON oBtn3 ID 103 OF oDlg ;
ACTION ( MsgInfo( "Menu 3" )) //,_empbrow( oWnd ) )
REDEFINE BUTTON oBtn4 ID 104 OF oDlg ;
ACTION ( MsgInfo( "Menu 3" )) //, _grpbrow( oWnd ) )
REDEFINE BUTTON oBtn5 ID 105 OF oDlg ;
ACTION ( MsgInfo( "Menu 4" )) //,_FyppBrow( oWnd ) )
REDEFINE BUTTON oBtn6 ID 106 OF oDlg ;
ACTION( MsgInfo( "Menu 5" )) //,_Purge() )
REDEFINE BUTTON oBtn7 ID 107 OF oDlg ;
ACTION( MsgInfo( "Menu 6" )) //, _HoliBrow(oWnd) )
REDEFINE BUTTON oBtn8 ID 108 OF oDlg ;
ACTION( oDlg:End(), dbCloseAll(), oBtnx:Show() )
ACTIVATE DIALOG oDlg NOWAIT ;
ON INIT ( oDLG:Move( 60, 15 )) ;
ON PAINT GradientFill( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aGrad, .T. );
VALID ( IF( !lOKx, GrpCLose( .T. ), .F. ))
RETURN(NIL)
//------------------------
Static FUNCTION GRPCLOSE(lCLEAN )
IF lCLEAN = .T.
lOKx := .T.
Msginfo( "closeing utility")
ENDIF
RETURN(lOKx)
//-- END
- Code: Select all Expand view
UTILMENU DIALOG 26, 9, 155, 208
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
FONT 10, "MS Sans Serif"
{
PUSHBUTTON "&Quit", 108, 7, 159, 29, 18
PUSHBUTTON "1 >>", 101, 7, 11, 29, 18
LTEXT "Reindex Files", -1, 45, 14, 92, 11, WS_BORDER | WS_GROUP
PUSHBUTTON "2 >>", 102, 7, 32, 29, 18
LTEXT "Enter, Edit System Params", -1, 45, 35, 92, 11, WS_BORDER | WS_GROUP
PUSHBUTTON "3 >>", 103, 7, 53, 29, 18
LTEXT "Employee Information", -1, 45, 56, 92, 11, WS_BORDER | WS_GROUP
PUSHBUTTON "4 >>", 104, 7, 74, 29, 18
LTEXT "WorkGroup Information", -1, 45, 77, 92, 11, WS_BORDER | WS_GROUP
PUSHBUTTON "5 >>", 105, 7, 95, 29, 18
LTEXT "FYPP Hourly Table ", -1, 45, 98, 92, 11, WS_BORDER | WS_GROUP
PUSHBUTTON "6 >>", 106, 7, 116, 29, 18
LTEXT "PCAS Data Purge Routine", -1, 45, 119, 92, 11, WS_BORDER | WS_GROUP
LTEXT "Return to Main Menu", -1, 45, 162, 92, 11, WS_BORDER | WS_GROUP
PUSHBUTTON "7 >>", 107, 7, 137, 29, 18
LTEXT "Holiday Schedule", -1, 45, 140, 92, 11, WS_BORDER | WS_GROUP
}